public JsonResult Delete(long id) { try { using (var dbc = new KuLibDbContext()) { var entity = dbc.Publications.Find(id); dbc.Publications.Remove(entity); dbc.SaveChanges(); return(Json(new { success = true })); } } catch (Exception ex) { return(Json(new { success = false, message = ex.Message })); } }
public void Update(PublicationInstanceEditDto model) { using (var dbc = new KuLibDbContext()) { var entity = dbc.PublicationInstances.Find(model.Id); if (model.UserId.HasValue && model.UserId.Value != 0) { entity.RentingUser = dbc.Users.Find(model.UserId.Value); if (model.ReturnDate.HasValue) { entity.ReturnDate = model.ReturnDate; } else { throw new Exception("При выдаче экземпляра читателю на руки необходимо заполнить дату возврата."); } } else { dbc.Entry(entity).Reference(x => x.RentingUser).Load(); entity.RentingUser = null; entity.ReturnDate = null; } dbc.SaveChanges(); } }
public void Delete(long id) { using (var dbc = new KuLibDbContext()) { var entity = dbc.PublicationInstances.Find(id); dbc.PublicationInstances.Remove(entity); dbc.SaveChanges(); } }
/// <summary> /// Метод редактирования публикации /// </summary> /// <param name="model"></param> public void Update(TEditDto model) { using (var dbc = new KuLibDbContext()) { var entity = GetSet(dbc).Find(model.Id); FillFromModel(entity, model); dbc.SaveChanges(); } }
/// <summary> /// Метод удаления читателя /// </summary> /// <param name="id"></param> public void Delete(long id) { using (var dbc = new KuLibDbContext()) { var user = dbc.Users.Find(id); dbc.Users.Remove(user); dbc.SaveChanges(); } }
/// <summary> /// Метод редактирования читателя /// </summary> /// <param name="model"></param> public void Update(UserEditDto model) { using (var dbc = new KuLibDbContext()) { var user = dbc.Users.Find(model.Id); FillFromModel(user, model); dbc.SaveChanges(); } }
/// <summary> /// Метод удаления публикации /// </summary> /// <param name="id"></param> public void Delete(long id) { using (var dbc = new KuLibDbContext()) { var set = GetSet(dbc); var entity = set.Find(id); set.Remove(entity); dbc.SaveChanges(); } }
public PublicationInstance Create(PublicationInstanceEditDto model) { using (var dbc = new KuLibDbContext()) { var newEntity = new PublicationInstance(); newEntity.Publication = dbc.Publications.Find(model.PublicationId); dbc.PublicationInstances.Add(newEntity); dbc.SaveChanges(); return(newEntity); } }
/// <summary> /// Метод создания новой публикации /// </summary> /// <param name="model"></param> /// <returns></returns> public TEntity Create(TEditDto model) { using (var dbc = new KuLibDbContext()) { var newEntity = new TEntity(); FillFromModel(newEntity, model); GetSet(dbc).Add(newEntity); dbc.SaveChanges(); return(newEntity); } }
/// <summary> /// Метод создания нового читателя /// </summary> /// <param name="model"></param> /// <returns></returns> public User Create(UserEditDto model) { using (var dbc = new KuLibDbContext()) { var newUser = new User(); FillFromModel(newUser, model); dbc.Users.Add(newUser); dbc.SaveChanges(); return(newUser); } }