Exemplo n.º 1
0
 public Tuple <bool, string, long> Save()
 {
     try
     {
         long id = 0;
         using (Easycase.DataModel.EasyCaseDBEntities DB = new DataModel.EasyCaseDBEntities())
         {
             var task = new DataModel.Task
             {
                 Notes       = this.Notes,
                 CreatedBy   = this.CreatedBy,
                 CreatedOn   = DateTime.Now,
                 Deleted     = false,
                 DueDate     = this.DueDate,
                 Name        = this.Name,
                 Priority    = this.Priority,
                 RelatedCase = this.RelatedCase,
                 Status      = this.Status,
                 TimeDue     = this.TimeDue,
                 Archived    = false
             };
             DB.Tasks.Add(task);
             DB.SaveChanges();
             id = task.ID;
             //Save Mentions and Assigned
             if (this.Mentions.Length > 0)
             {
                 foreach (var item in this.Mentions)
                 {
                     var mention = new DataModel.Mention
                     {
                         TaskId   = id,
                         ClientId = item
                     };
                     DB.Mentions.Add(mention);
                 }
             }
             if (this.Assigned.Length > 0)
             {
                 foreach (var item in this.Assigned)
                 {
                     var assign = new DataModel.Assigned
                     {
                         TaskId   = id,
                         ClientId = item
                     };
                     DB.Assigneds.Add(assign);
                 }
             }
             //
             DB.SaveChanges();
         }
         return(new Tuple <bool, string, long>(true, Messages.SUCCESS, id));
     }
     catch (Exception ex)
     {
         Logs.SaveLog(ex.Message);
         return(new Tuple <bool, string, long>(false, ex.Message, 0));
     }
 }
Exemplo n.º 2
0
 public bool UpdateAssignee(long[] assignedIds, long taskId)
 {
     try
     {
         using (Easycase.DataModel.EasyCaseDBEntities DB = new DataModel.EasyCaseDBEntities())
         {
             var assignees = DB.Assigneds.Where(t => t.TaskId == taskId).ToList();
             // Remove assignee
             foreach (var item in assignees)
             {
                 DB.Entry(item).State = System.Data.Entity.EntityState.Deleted;
             }
             DB.SaveChanges();
             //Save Assigned
             foreach (var item in assignedIds)
             {
                 var assign = new DataModel.Assigned
                 {
                     TaskId   = taskId,
                     ClientId = item
                 };
                 DB.Assigneds.Add(assign);
             }
             //
             DB.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         Logs.SaveLog(ex.Message);
         return(false);
     }
 }