public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (SupplierMngEntities context = CreateContext()) { Supplier dbItem = context.Supplier.FirstOrDefault(o => o.SupplierID == id); if (dbItem == null) { notification.Message = "Supplier not found!"; return(false); } else { context.Supplier.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public bool UpdateData(int id, ref object dtoItem, int iRequesterID, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.Supplier dtoSupplier = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.Supplier>(); try { using (SupplierMngEntities context = CreateContext()) { Supplier dbItem = null; if (id == 0) { dbItem = new Supplier(); context.Supplier.Add(dbItem); } else { dbItem = context.Supplier.FirstOrDefault(o => o.SupplierID == id); dtoSupplier.UpdatedBy = iRequesterID; } if (dbItem == null) { notification.Message = "Supplier not found!"; return(false); } else { // check concurrency if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoSupplier.ConcurrencyFlag_String))) { throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT); } converter.DTO2BD(dtoSupplier, ref dbItem); context.SupplierBank.Local.Where(o => o.Supplier == null).ToList().ForEach(o => context.SupplierBank.Remove(o)); context.SaveChanges(); dtoItem = GetData(dbItem.SupplierID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }