Esempio n. 1
0
 private List <Rotation> GetAllRotations()
 {
     using (var db = new RotationDbContext())
     {
         return(db.Rotations.ToList());
     }
 }
Esempio n. 2
0
 private List <Assignment> GetAllAssignments()
 {
     using (var db = new RotationDbContext())
     {
         return(db.Assignments.Include(a => a.Rotation).ToList());
     }
 }
Esempio n. 3
0
 private List <Resident> GetAllResidents()
 {
     using (var db = new RotationDbContext())
     {
         return(db.Residents.ToList());
     }
 }
Esempio n. 4
0
 private IEnumerable <Rotation> FindAllRotations()
 {
     using (var db = new RotationDbContext())
     {
         return(db.Rotations.ToList());
     }
 }
Esempio n. 5
0
        public ActionResult Update(int id, string name, string color)
        {
            using (var db = new RotationDbContext())
            {
                var rotation = db.Rotations.FirstOrDefault(r => r.Id == id);
                rotation.Name  = name;
                rotation.Color = color;

                db.SaveChanges();
            }

            return(RedirectToAction("index"));
        }
Esempio n. 6
0
        public ActionResult UpdateSchedule(List <UpdateScheduleInputModel> assignments, List <int> deletedIds)
        {
            try
            {
                deletedIds = deletedIds ?? new List <int>();
                var idsToGet  = new List <int>(deletedIds);
                var updateIds = new List <int>(assignments.Select(s => s.AssignmentId)).Distinct();
                idsToGet.AddRange(updateIds);

                using (var db = new RotationDbContext())
                {
                    var entities = db.Assignments.Where(a => idsToGet.Contains(a.Id)).ToList();

                    entities.Where(e => deletedIds.Contains(e.Id))
                    .ToList()
                    .ForEach(e => db.Assignments.Remove(e));

                    entities.Where(e => updateIds.Contains(e.Id))
                    .ToList()
                    .ForEach(e =>
                    {
                        var input    = assignments.FirstOrDefault(s => s.AssignmentId == e.Id);
                        e.ResidentId = input.ResidentId;
                        e.RotationId = input.RotationId;
                        e.FromMonth  = input.FromMonth;
                        e.ToMonth    = input.ToMonth;
                    });

                    assignments.Where(e => e.AssignmentId == 0)
                    .ToList()
                    .ForEach(e => db.Assignments.Add(new Assignment
                    {
                        ResidentId = e.ResidentId,
                        RotationId = e.RotationId,
                        FromMonth  = e.FromMonth,
                        ToMonth    = e.ToMonth
                    }));

                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, errors = new string[] { ex.ToString() } }));
            }


            return(Json(new { success = true }));
        }
Esempio n. 7
0
        public ActionResult Create(string name, string color)
        {
            using (var db = new RotationDbContext())
            {
                db.Rotations.Add(new Rotation
                {
                    Name  = name,
                    Color = color
                });

                db.SaveChanges();
            }

            return(RedirectToAction("index"));
        }