public bool CancelReservation(int saleOrderID, int userID, out Library.DTO.Notification notification) { bool result = false; notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (WarehouseReservationMngEntities context = CreateContext()) { WarehouseReservation dbItem = context.WarehouseReservation.FirstOrDefault(o => o.SaleOrderID == saleOrderID); dbItem.UpdatedBy = userID; dbItem.UpdatedDate = DateTime.Now; dbItem.ProcessingStatusID = 3; dbItem.StatusUpdatedBy = userID; dbItem.StatusUpdatedDate = DateTime.Now; context.SaveChanges(); result = true; } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; } return(result); }
public bool CreateReservation(int saleOrderID, int userID, ref DTO.WarehouseReservationMng.WarehouseReservation dtoItem, out Library.DTO.Notification notification) { dtoItem.Details.ForEach(o => o.ProductStatusID = 1); bool result = false; notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { // cancel old reservation CancelReservation(saleOrderID, userID, out notification); if (notification.Type != Library.DTO.NotificationType.Success) { throw new Exception(notification.Message); } using (WarehouseReservationMngEntities context = CreateContext()) { WarehouseReservation dbItem = new WarehouseReservation(); context.WarehouseReservation.Add(dbItem); converter.DTO2DB(dtoItem, ref dbItem); dbItem.UpdatedBy = dtoItem.UpdatedBy; dbItem.UpdatedDate = DateTime.Now; dbItem.StatusUpdatedBy = dtoItem.UpdatedBy; dbItem.StatusUpdatedDate = DateTime.Now; dbItem.ProcessingStatusID = 2; dbItem.SaleOrderID = saleOrderID; context.SaveChanges(); dtoItem = converter.DB2DTO_WarehouseReservation(dbItem); result = true; } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; } return(result); }
public void DTO2DB(DTO.WarehouseReservationMng.WarehouseReservation dtoItem, ref WarehouseReservation dbItem) { // map main object AutoMapper.Mapper.Map <DTO.WarehouseReservationMng.WarehouseReservation, WarehouseReservation>(dtoItem, dbItem); // map child collection // delete case List <int> toBeDeletedDetailIDs = new List <int>(); foreach (WarehouseReservationProductDetail toBeDeletedDetail in dbItem.WarehouseReservationProductDetail) { if (!dtoItem.Details.Select(o => o.WarehouseReservationProductDetailID).Contains(toBeDeletedDetail.WarehouseReservationProductDetailID)) { toBeDeletedDetailIDs.Add(toBeDeletedDetail.WarehouseReservationProductDetailID); } } foreach (int toBeDeletedDetailID in toBeDeletedDetailIDs) { dbItem.WarehouseReservationProductDetail.Remove(dbItem.WarehouseReservationProductDetail.FirstOrDefault(o => o.WarehouseReservationProductDetailID == toBeDeletedDetailID)); } foreach (DTO.WarehouseReservationMng.WarehouseReservationProductDetail dtoDetail in dtoItem.Details) { // add new case WarehouseReservationProductDetail dbDetail = null; if (dtoDetail.WarehouseReservationProductDetailID <= 0) { dbDetail = new WarehouseReservationProductDetail(); dbDetail.WarehouseReservation = dbItem; dbItem.WarehouseReservationProductDetail.Add(dbDetail); } else { dbDetail = dbItem.WarehouseReservationProductDetail.FirstOrDefault(o => o.WarehouseReservationProductDetailID == dtoDetail.WarehouseReservationProductDetailID); } if (dbDetail != null) { AutoMapper.Mapper.Map <DTO.WarehouseReservationMng.WarehouseReservationProductDetail, WarehouseReservationProductDetail>(dtoDetail, dbDetail); } } }
public DTO.WarehouseReservationMng.WarehouseReservation DB2DTO_WarehouseReservation(WarehouseReservation dbItem) { return(AutoMapper.Mapper.Map <WarehouseReservation, DTO.WarehouseReservationMng.WarehouseReservation>(dbItem)); }