Exemple #1
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"));
        }
Exemple #2
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 }));
        }
Exemple #3
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"));
        }