private void DeleteOldUserAccessTokens(decimal userId, DateTime now, DragonflyEntities context)
        {
            var userAccesses =
                (from userAccess in context.User_Access
                 where userAccess.ID_User == userId &&
                 DbFunctions.TruncateTime(userAccess.Date_Expiration) < now.Date
                 select userAccess);

            DeleteAccessTokens(userAccesses, context);
        }
Beispiel #2
0
 private Project RetrieveProjectById(decimal projectId, DragonflyEntities context)
 {
     try
     {
         return((from p in context.Project
                 where p.ID_Project == projectId
                 select p).FirstOrDefault());
     }
     catch (Exception ex)
     {
         throw new InvalidOperationException("Unable to retrieve a project.", ex);
     }
 }
 private void DeleteAccessTokens(IQueryable <User_Access> userAccesses, DragonflyEntities context)
 {
     if (userAccesses.Count() > 0)
     {
         context.User_Access.RemoveRange(userAccesses);
     }
     try
     {
         context.SaveChanges();
     }
     catch (Exception ex)
     {//TODO log
     }
 }
Beispiel #4
0
 private void SaveExistingProjectInDB(Project project, DragonflyEntities context)
 {
     try
     {
         context.SaveChanges();
     }
     catch (DbEntityValidationException ex)
     {
         context.Project.Remove(project);
         List <ValidationError> validationErrors = ex.RetrieveValidationsErrors();
         throw new InsertDbDataException(validationErrors);
     }
     catch (DbUpdateException ex)
     {
         context.Project.Remove(project);
         throw new InvalidOperationException("Unable to save project", ex);
     }
 }
Beispiel #5
0
 private void KeepUserProject(decimal projectId, User_Project usProj, DragonflyEntities context)
 {
     try
     {
         context.User_Project.Add(usProj);
         context.SaveChanges();
     }
     catch (DbEntityValidationException ex)
     {
         context.User_Project.Remove(usProj);
         List <ValidationError> validationErrors = ex.RetrieveValidationsErrors();
         DeleteProject(projectId);
         throw new InsertDbDataException(validationErrors);
     }
     catch (DbUpdateException ex)
     {
         context.User_Project.Remove(usProj);
         DeleteProject(projectId);
         throw new InvalidOperationException("Unable to save user-project relation", ex);
     }
 }