public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (WarehouseCIMngEntities context = CreateContext()) { WarehouseCI dbItem = context.WarehouseCI.FirstOrDefault(o => o.WarehouseCIID == id); if (dbItem == null) { notification.Message = "Invoice not found!"; return(false); } else { List <WarehouseCIDetail> need_delete_details = new List <WarehouseCIDetail>(); foreach (WarehouseCIDetail dbDetail in dbItem.WarehouseCIDetail) { need_delete_details.Add(dbDetail); } List <WarehouseCIExtDetail> need_delete_extdetail = new List <WarehouseCIExtDetail>(); foreach (WarehouseCIExtDetail dbExtDetail in dbItem.WarehouseCIExtDetail) { need_delete_extdetail.Add(dbExtDetail); } foreach (var item in need_delete_details) { context.WarehouseCIDetail.Remove(item); } foreach (var item in need_delete_extdetail) { context.WarehouseCIExtDetail.Remove(item); } context.WarehouseCI.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Warning }; return(false); } }
public override bool UpdateData(int id, ref DTO.WarehouseCIMng.WarehouseCI dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (WarehouseCIMngEntities context = CreateContext()) { WarehouseCI dbItem = null; if (id == 0) { dbItem = new WarehouseCI(); context.WarehouseCI.Add(dbItem); } else { dbItem = context.WarehouseCI.FirstOrDefault(o => o.WarehouseCIID == id); } if (dbItem == null) { notification.Message = "Invoice not found!"; return(false); } else { // check concurrency if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoItem.ConcurrencyFlag_String))) { throw new Exception(DALBase.Helper.TEXT_CONCURRENCY_CONFLICT); } converter.DTO2DB_WarehouseCI(dtoItem, ref dbItem); if (id == 0) { dbItem.CreatedBy = dtoItem.UpdatedBy; dbItem.CreatedDate = DateTime.Now; } else { dbItem.UpdatedBy = dtoItem.UpdatedBy; dbItem.UpdatedDate = DateTime.Now; } context.SaveChanges(); dtoItem = GetData(dbItem.WarehouseCIID, out notification); return(true); } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.InnerException.InnerException.Message, Type = Library.DTO.NotificationType.Warning }; return(false); } }