public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (ClientGroupMngEntities context = CreateContext()) { ClientGroup dbItem = context.ClientGroup.FirstOrDefault(o => o.ClientGroupID == id); if (dbItem == null) { notification.Message = "Client Group not found!"; return(false); } else { context.ClientGroup.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message }; return(false); } }
public override bool UpdateData(int id, ref DTO.ClientGroupMng.ClientGroup dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (ClientGroupMngEntities context = CreateContext()) { ClientGroup dbItem = null; if (id == 0) { dbItem = new ClientGroup(); context.ClientGroup.Add(dbItem); } else { dbItem = context.ClientGroup.FirstOrDefault(o => o.ClientGroupID == id); } if (dbItem == null) { notification.Message = "Client Group not found!"; return(false); } else { converter.DTO2BD_ClientGroup(dtoItem, ref dbItem); context.SaveChanges(); dtoItem = GetData(dbItem.ClientGroupID, out notification); return(true); } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message }; return(false); } }