public void Edit(Core.Entities.Group group) { using (StudentsModel context = new StudentsModel()) { var editingGroup = context .Groups .FirstOrDefault(x => x.Id == group.Id); if (editingGroup == null) throw new ArgumentException("group is not found"); editingGroup.Name = group.Name; context.SaveChanges(); } }
public void Delete(int id) { using (StudentsModel context = new StudentsModel()) { var deletingGroup = context .Groups .FirstOrDefault(x => x.Id == id); if (deletingGroup == null) throw new ArgumentException("group is not found"); context.Groups.Remove(deletingGroup); context.SaveChanges(); } }
public int Add(Core.Entities.Group group) { var newGroup = new Group() { Name = group.Name }; using (StudentsModel context = new StudentsModel()) { context.Groups.Add(newGroup); context.SaveChanges(); } return newGroup.Id; }