// // CUSTOM FUNCTIONS // public bool ChangeStatus(int id, int statusId, ref DTO.WarehouseExportMng.WarehouseExport dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; // only update the current data if the status is different than CONFIRMED if (dtoItem.ProcessingStatusID == 1) { // update current data if (!UpdateData(id, ref dtoItem, out notification)) { return(false); } } try { using (WarehouseExportMngEntities context = CreateContext()) { WarehouseExport dbItem = context.WarehouseExport.FirstOrDefault(o => o.WarehouseExportID == id); if (dbItem != null) { dbItem.ProcessingStatusID = statusId; dbItem.StatusUpdatedBy = dtoItem.UpdatedBy; dbItem.StatusUpdatedDate = DateTime.Now; context.SaveChanges(); dtoItem = GetData(id, out notification).Data; return(true); } else { throw new Exception("Export receipt not found!"); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public override bool DeleteData(int id, out Library.DTO.Notification notification) { bool result = false; notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (WarehouseExportMngEntities context = CreateContext()) { WarehouseExport dbItem = context.WarehouseExport.FirstOrDefault(o => o.WarehouseExportID == id); if (dbItem == null) { throw new Exception("Export receipt: " + dbItem.ReceiptNo + " not found!"); } else { if (dbItem.ProcessingStatusID == 1) { context.WarehouseExport.Remove(dbItem); context.SaveChanges(); result = true; } else { throw new Exception("Can not delete the approved/canceled export receipt"); } } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; } return(result); }
public override bool UpdateData(int id, ref DTO.WarehouseExportMng.WarehouseExport dtoItem, out Library.DTO.Notification notification) { bool result = false; notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (WarehouseExportMngEntities context = CreateContext()) { WarehouseExport dbItem = null; if (id == 0) { dbItem = new WarehouseExport(); context.WarehouseExport.Add(dbItem); } else { dbItem = context.WarehouseExport.FirstOrDefault(o => o.WarehouseExportID == id); } if (dbItem == null) { notification.Message = "Export receipt not found!"; } else { // check concurrency if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoItem.ConcurrencyFlag_String))) { throw new Exception(DALBase.Helper.TEXT_CONCURRENCY_CONFLICT); } // check if status = CONFIRMED if (dbItem.ProcessingStatusID > 1) { throw new Exception(DALBase.Helper.TEXT_CONFIRMED_CONFLICT); } DateTime dateValue; if (DateTime.TryParse(dtoItem.ExportedDate, new System.Globalization.CultureInfo("vi-VN"), System.Globalization.DateTimeStyles.None, out dateValue)) { dbItem.ExportedDate = dateValue; } converter.DTO2DB(dtoItem, ref dbItem); dbItem.UpdatedBy = dtoItem.UpdatedBy; dbItem.UpdatedDate = DateTime.Now; // remove orphans context.WarehouseExportProductDetail.Local.Where(o => o.WarehouseExport == null).ToList().ForEach(o => context.WarehouseExportProductDetail.Remove(o)); context.SaveChanges(); dtoItem = GetData(dbItem.WarehouseExportID, out notification).Data; result = true; } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; } return(result); }