public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (WarehouseTransportMngEntities context = CreateContext()) { WarehouseTransport dbItem = context.WarehouseTransport.FirstOrDefault(o => o.WarehouseTransportID == id); if (dbItem == null) { notification.Message = "receipt not found!"; return(false); } else { context.WarehouseTransport.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message)) { notification.DetailMessage.Add(ex.InnerException.Message); } return(false); } }
public override bool UpdateData(int id, ref DTO.WarehouseTransportMng.WarehouseTransport dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (WarehouseTransportMngEntities context = CreateContext()) { WarehouseTransport dbItem = null; if (id == 0) { dbItem = new WarehouseTransport(); context.WarehouseTransport.Add(dbItem); } else { dbItem = context.WarehouseTransport.FirstOrDefault(o => o.WarehouseTransportID == id); } if (dbItem == null) { notification.Message = "receipt 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); } //validate transfer qnt ValidateTransferQuantity(dtoItem); //convert dto to db converter.DTO2DB_WarehouseTransport(dtoItem, ref dbItem); context.WarehouseTransportProductDetail.Local.Where(o => o.WarehouseTransport == null).ToList().ForEach(o => context.WarehouseTransportProductDetail.Remove(o)); context.WarehouseTransportSparepartDetail.Local.Where(o => o.WarehouseTransport == null).ToList().ForEach(o => context.WarehouseTransportSparepartDetail.Remove(o)); context.SaveChanges(); if (id == 0) { context.WarehouseTransportMng_function_GenerateReceiptNo(dbItem.WarehouseTransportID, dbItem.Season); } //update ReceiptNo //Get return data dtoItem = GetData(dbItem.WarehouseTransportID, out notification); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message)) { notification.DetailMessage.Add(ex.InnerException.Message); } return(false); } }