Skip to content
Snippets Groups Projects

Sprint/2021 05

Merged Marcel Nellesen requested to merge Sprint/2021-05 into master
8 files
+ 352
19
Compare changes
  • Side-by-side
  • Inline
Files
8
using Coscine.Database.DataModel;
using Coscine.Database.ReturnObjects;
using Coscine.Database.Util;
using LinqKit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text.RegularExpressions;
using LinqKit;
namespace Coscine.Database.Models
{
public class ProjectModel : DatabaseModel<Project>
@@ -119,7 +117,7 @@ namespace Coscine.Database.Models
{
return DatabaseConnection.ConnectToDatabase((db) =>
{
return db.Delete(databaseObject);
return (int) db.Remove(databaseObject).State;
});
}
@@ -127,15 +125,15 @@ namespace Coscine.Database.Models
{
return DatabaseConnection.ConnectToDatabase((db) =>
{
return db.Delete(from tableEntry in GetITableFromDatabase(db).AsExpandable()
return (int)db.Remove(from tableEntry in GetITableFromDatabase(db).AsExpandable()
where whereClause.Invoke(tableEntry)
select tableEntry);
select tableEntry).State;
});
}
public Project StoreFromObject(ProjectObject projectObject, User user, bool isRWTHMember = false)
{
if (projectObject.Disciplines.Count() == 0 || projectObject.Organizations.Count() == 0)
if (!projectObject.Disciplines.Any() || !projectObject.Organizations.Any())
{
throw new ArgumentException("Discipline and Institute are necessary!");
}
@@ -162,10 +160,10 @@ namespace Coscine.Database.Models
SetOrganizations(project, projectObject.Organizations);
SetQuotas(project, isRWTHMember);
}
catch (Exception e)
catch (Exception)
{
HardDelete(project);
throw e;
throw;
}
SetOwner(project, user);
return project;
@@ -185,7 +183,7 @@ namespace Coscine.Database.Models
});
}
private String GenerateSlug(ProjectObject projectObject)
private string GenerateSlug(ProjectObject projectObject)
{
// create slug for project
var slug = projectObject.DisplayName;
@@ -360,7 +358,7 @@ namespace Coscine.Database.Models
public int UpdateByObject(Project project, ProjectObject projectObject)
{
if (projectObject.Disciplines.Count() == 0 || projectObject.Organizations.Count() == 0)
if (!projectObject.Disciplines.Any() || !projectObject.Organizations.Any())
{
throw new ArgumentException("Discipline and Institute are necessary!");
}
@@ -433,7 +431,7 @@ namespace Coscine.Database.Models
&& subProject.Project.Deleted == false
select subProject).Any());
if (list.Count() > 0)
if (list.Any())
{
currentProject = list.First();
bool authorized = true;
@@ -476,5 +474,54 @@ namespace Coscine.Database.Models
databaseObject.Id = id;
}
public string GetMetadataCompleteness(ProjectObject projectObject)
{
var maxCount = 0;
var counted = 0;
var projectProperties = typeof(ProjectObject).GetProperties();
foreach (var property in projectProperties)
{
if (property == null
|| property.PropertyType == typeof(Guid)
|| property.Name == "Slug")
{
continue;
}
maxCount++;
if (property.PropertyType == typeof(string)
&& property.GetValue(projectObject) != null
&& !string.IsNullOrEmpty(property.GetValue(projectObject).ToString()))
{
counted++;
}
else if (property.PropertyType == typeof(DateTime)
&& property.GetValue(projectObject) != null)
{
counted++;
}
else if (property.PropertyType == typeof(IEnumerable<DisciplineObject>)
&& property.GetValue(projectObject) != null
&& ((IEnumerable<DisciplineObject>)property.GetValue(projectObject)).Any())
{
counted++;
}
else if (property.PropertyType == typeof(IEnumerable<OrganizationObject>)
&& property.GetValue(projectObject) != null
&& ((IEnumerable<OrganizationObject>)property.GetValue(projectObject)).Any())
{
counted++;
}
else if (property.PropertyType == typeof(VisibilityObject)
&& property.GetValue(projectObject) != null)
{
counted++;
}
}
return $"{counted}/{maxCount}";
}
}
}
Loading