Esempio n. 1
0
 public Intervention UpdateIntervention(int interventionId, User user, string oldStatus, string newStatus)
 {
     using (context = new CustomDBContext())
     {
         var intervention = context.Interventions
                            .Where(i => i.InterventionId == interventionId && i.Client.ClientDistrict.Equals(user.District) &&
                                   i.Status.Equals(oldStatus))         //Added &&
                            .Select(i => i)
                            .FirstOrDefault();
         if (newStatus.Equals(Status.APPROVED))
         {
             intervention.ApprovedByUserId = user.UserId;
         }
         intervention.LastUpdatedByUserId = user.UserId;
         intervention.Status     = newStatus;
         intervention.ModifyDate = DateTime.Now;
         try
         {
             context.SaveChanges();
         }
         catch
         {
             throw new FailedToUpdateRecordException();
         }
         return(intervention);
     }
 }
Esempio n. 2
0
 public void AddIntervention(Intervention intervention)
 {
     using (context = new CustomDBContext())
     {
         context.Interventions.Add(intervention);
         context.SaveChanges();
     }
 }
 public void AddClient(User user, Client client)
 {
     using (context = new CustomDBContext())
     {
         context.Clients.Add(client);
         context.SaveChanges();
     }
 }
 public void UpdateDistrictForUser(string userId, string district)
 {
     context = new CustomDBContext();
     {
         User user = context.Users.Single(u => u.UserId == userId);
         user.District = district;
         try
         {
             context.SaveChanges();
         }
         catch (Exception)
         {
             throw new FailedToUpdateRecordException();
         }
     }
 }
Esempio n. 5
0
 public Intervention UpdateIntervention(Intervention intervention)
 {
     using (context = new CustomDBContext())
     {
         var inter = context.Interventions
                     .Where(i => i.InterventionId == intervention.InterventionId)
                     .Select(i => i)
                     .FirstOrDefault();
         inter.ModifyDate          = DateTime.Now;
         inter.Status              = intervention.Status;
         inter.LastUpdatedByUserId = intervention.LastUpdatedByUserId;
         inter.Comments            = intervention.Comments;
         inter.Condition           = intervention.Condition;
         inter.InterventionCost    = intervention.InterventionCost;
         inter.InterventionHours   = intervention.InterventionHours;
         context.SaveChanges();
         return(inter);
     }
 }