public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (UserGroupMngEntities context = CreateContext()) { UserGroup dbItem = context.UserGroup.FirstOrDefault(o => o.UserGroupID == id); if (dbItem == null) { notification.Message = "User group not found!"; return(false); } else { context.UserGroup.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public override bool UpdateData(int id, ref DTO.UserGroupMng.UserGroup dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (UserGroupMngEntities context = CreateContext()) { UserGroup dbItem = null; if (id == 0) { dbItem = new UserGroup(); context.UserGroup.Add(dbItem); } else { dbItem = context.UserGroup.FirstOrDefault(o => o.UserGroupID == id); } if (dbItem == null) { notification.Message = "User group not found!"; return(false); } else { converter.DTO2DB(dtoItem, ref dbItem); context.SaveChanges(); dtoItem = GetData(dbItem.UserGroupID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }