public DTO.OfferMng.Offer DB2DTO_Offer(OfferMng_Offer_View dbItem) { DTO.OfferMng.Offer dtoItem = AutoMapper.Mapper.Map <OfferMng_Offer_View, DTO.OfferMng.Offer>(dbItem); /* * FORMAT FIELDS DATETIME */ if (dbItem.ConcurrencyFlag != null) { dtoItem.ConcurrencyFlag_String = Convert.ToBase64String(dbItem.ConcurrencyFlag); } if (dbItem.OfferDate.HasValue) { dtoItem.OfferDateFormated = dbItem.OfferDate.Value.ToString("dd/MM/yyyy"); } if (dbItem.ValidUntil.HasValue) { dtoItem.ValidUntilFormated = dbItem.ValidUntil.Value.ToString("dd/MM/yyyy"); } if (dbItem.LDS.HasValue) { dtoItem.LDSFormated = dbItem.LDS.Value.ToString("dd/MM/yyyy"); } if (dbItem.EstimatedDeliveryDate.HasValue) { dtoItem.EstimatedDeliveryDateFormated = dbItem.EstimatedDeliveryDate.Value.ToString("dd/MM/yyyy"); } if (dbItem.UpdatedDate.HasValue) { dtoItem.UpdatedDateFormated = dbItem.UpdatedDate.Value.ToString("dd/MM/yyyy"); } if (dbItem.CreatedDate.HasValue) { dtoItem.CreatedDateFormated = dbItem.UpdatedDate.Value.ToString("dd/MM/yyyy"); } return(dtoItem); }
public IHttpActionResult Revise(int id, int actionType, DTO.OfferMng.Offer dtoItem) { // authentication Module.Framework.BLL fwBll = new Module.Framework.BLL(); if (!fwBll.CanPerformAction(ControllerContext.GetAuthUserId(), moduleCode, Library.DTO.ModuleAction.CanApprove)) { return(InternalServerError(new Exception(Properties.Resources.NOT_AUTHORIZED))); } BLL.OfferMng bll = new BLL.OfferMng(); Library.DTO.Notification notification; bll.Revise(id, actionType, ref dtoItem, ControllerContext.GetAuthUserId(), out notification); return(Ok(new Library.DTO.ReturnData <DTO.OfferMng.Offer>() { Data = dtoItem, Message = notification })); }
public IHttpActionResult Update(int id, int actionType, DTO.OfferMng.Offer dtoItem) { Library.DTO.Notification notification; // authentication Module.Framework.BLL fwBll = new Module.Framework.BLL(); if (id > 0 && !fwBll.CanPerformAction(ControllerContext.GetAuthUserId(), moduleCode, Library.DTO.ModuleAction.CanUpdate)) { // edit case return(InternalServerError(new Exception(Properties.Resources.NOT_AUTHORIZED))); } else if (id == 0 && !fwBll.CanPerformAction(ControllerContext.GetAuthUserId(), moduleCode, Library.DTO.ModuleAction.CanCreate)) { // create new case return(InternalServerError(new Exception(Properties.Resources.NOT_AUTHORIZED))); } // validation if (!Helper.CommonHelper.ValidateDTO <DTO.OfferMng.Offer>(dtoItem, out notification)) { return(Ok(new Library.DTO.ReturnData <DTO.OfferMng.Offer>() { Data = dtoItem, Message = notification })); } // continue processing BLL.OfferMng bll = new BLL.OfferMng(); bll.UpdateData(id, actionType, ref dtoItem, ControllerContext.GetAuthUserId(), out notification); return(Ok(new Library.DTO.ReturnData <DTO.OfferMng.Offer>() { Data = dtoItem, Message = notification })); }
public void DTO2DB_Offer(DTO.OfferMng.Offer dtoItem, ref Offer dbItem, int actionType, int userId) { OfferStatus dbOfferStatus = dbItem.OfferStatus.Where(o => o.IsCurrentStatus.HasValue && o.IsCurrentStatus.Value).FirstOrDefault(); /* * MAP & CHECK OFFERLINE */ List <OfferLine> ItemNeedDelete_Extends = new List <OfferLine>(); if (dtoItem.OfferLines != null) { //CHECK foreach (OfferLine dbDetail in dbItem.OfferLine.Where(o => !dtoItem.OfferLines.Select(s => s.OfferLineID).Contains(o.OfferLineID))) { ItemNeedDelete_Extends.Add(dbDetail); } foreach (OfferLine dbDetail in ItemNeedDelete_Extends) { dbItem.OfferLine.Remove(dbDetail); } //MAP foreach (DTO.OfferMng.OfferLine dtoDetail in dtoItem.OfferLines) { OfferLine dbDetail; OfferLinePriceOption dbPriceOption; bool isAllowEditItem = true; if (dtoDetail.OfferLineID < 0 || actionType != 1) // actionType { 0:New, 1:Edit,2: Copy, 3:New Version} { dbDetail = new OfferLine(); if (dtoDetail.OfferLinePriceOptions != null) { foreach (DTO.OfferMng.OfferLinePriceOption dtoPriceOption in dtoDetail.OfferLinePriceOptions) { dbPriceOption = new OfferLinePriceOption(); dbDetail.OfferLinePriceOption.Add(dbPriceOption); AutoMapper.Mapper.Map <DTO.OfferMng.OfferLinePriceOption, OfferLinePriceOption>(dtoPriceOption, dbPriceOption); } } dbItem.OfferLine.Add(dbDetail); } else { dbDetail = dbItem.OfferLine.FirstOrDefault(o => o.OfferLineID == dtoDetail.OfferLineID); if (dbDetail != null && dtoDetail.OfferLinePriceOptions != null) { foreach (DTO.OfferMng.OfferLinePriceOption dtoPriceOption in dtoDetail.OfferLinePriceOptions) { if (dtoPriceOption.OfferLinePriceOptionID < 0) { dbPriceOption = new OfferLinePriceOption(); dbDetail.OfferLinePriceOption.Add(dbPriceOption); } else { dbPriceOption = dbDetail.OfferLinePriceOption.FirstOrDefault(o => o.OfferLinePriceOptionID == dtoPriceOption.OfferLinePriceOptionID); } if (dbPriceOption != null) { Mapper.Map(dtoPriceOption, dbPriceOption); } } } //check item exist in factory order var x = dbDetail.SaleOrderDetail.Where(o => o.FactoryOrderDetail != null && o.FactoryOrderDetail.Count() > 0); isAllowEditItem = !(x != null && x.Count() > 0); // detect changes for approved items if (dtoDetail.OfferItemTypeID == 1 && dtoDetail.IsApproved.HasValue && !dtoDetail.IsApproved.Value) { dbDetail.IsApproved = false; dbDetail.ApprovedBy = null; dbDetail.ApprovedDate = null; } // // Author : The My // Description : force update configuration changed even if item exists in factory order // Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); if (fwFactory.HasSpecialPermission(userId, Module.Framework.ConstantIdentifier.SPECIAL_PERMISSION_CHANGE_OFFER_ITEM_OPTION)) { isAllowEditItem = true; } } if (dbDetail != null) { dtoDetail.FinalPrice = ( (dtoItem.CommissionPercent == null ? 0 : dtoItem.CommissionPercent) + (dtoItem.SurChargePercent == null ? 0 : dtoItem.SurChargePercent) + (dtoDetail.IncreasePercent == null ? 0 : dtoDetail.IncreasePercent) ) / 100 * (dtoDetail.UnitPrice == null ? 0 : dtoDetail.UnitPrice) + (dtoDetail.UnitPrice == null ? 0 : dtoDetail.UnitPrice); // set update by for est purchasing price if (dtoDetail.EstimatedPurchasingPrice != dbDetail.EstimatedPurchasingPrice) { dbDetail.EstimatedPurchasingPriceUpdatedByID = userId; } // set selected by for planing purchasing price if (dtoDetail.PlaningPurchasingPriceSelectedDate == "just now") { dbDetail.PlaningPurchasingPriceSelectedBy = userId; dbDetail.PlaningPurchasingPriceSelectedDate = DateTime.Now; } Mapper.Map(dtoDetail, dbDetail); // only allow edit item in case item does not put in factory order detail if (isAllowEditItem) { dbDetail.ModelID = dtoDetail.ModelID; dbDetail.FrameMaterialID = dtoDetail.FrameMaterialID; dbDetail.FrameMaterialColorID = dtoDetail.FrameMaterialColorID; dbDetail.MaterialID = dtoDetail.MaterialID; dbDetail.MaterialTypeID = dtoDetail.MaterialTypeID; dbDetail.MaterialColorID = dtoDetail.MaterialColorID; dbDetail.SubMaterialID = dtoDetail.SubMaterialID; dbDetail.SubMaterialColorID = dtoDetail.SubMaterialColorID; dbDetail.SeatCushionID = dtoDetail.SeatCushionID; dbDetail.BackCushionID = dtoDetail.BackCushionID; dbDetail.CushionColorID = dtoDetail.CushionColorID; dbDetail.FSCTypeID = dtoDetail.FSCTypeID; dbDetail.FSCPercentID = dtoDetail.FSCPercentID; } } } } /* * MAP & CHECK OFFERLINE SPAREPART */ List <OfferLineSparepart> needItemDelete = new List <OfferLineSparepart>(); if (dtoItem.OfferLineSpareparts != null) { //CHECK foreach (OfferLineSparepart dbDetail in dbItem.OfferLineSparepart.Where(o => !dtoItem.OfferLineSpareparts.Select(s => s.OfferLineSparePartID).Contains(o.OfferLineSparePartID))) { needItemDelete.Add(dbDetail); } foreach (OfferLineSparepart dbDetail in needItemDelete) { dbItem.OfferLineSparepart.Remove(dbDetail); } //MAP foreach (DTO.OfferMng.OfferLineSparepart dtoDetail in dtoItem.OfferLineSpareparts) { OfferLineSparepart dbDetail; bool isAllowEditItem = true; if (dtoDetail.OfferLineSparePartID < 0 || actionType != 1) // actionType { 0:New, 1:Edit,2: Copy, 3:New Version} { dbDetail = new OfferLineSparepart(); dbItem.OfferLineSparepart.Add(dbDetail); } else { dbDetail = dbItem.OfferLineSparepart.FirstOrDefault(o => o.OfferLineSparePartID == dtoDetail.OfferLineSparePartID); var x = dbDetail.SaleOrderDetailSparepart.Where(o => o.FactoryOrderSparepartDetail != null && o.FactoryOrderSparepartDetail.Count() > 0); isAllowEditItem = !(x != null && x.Count() > 0); } if (dbDetail != null) { AutoMapper.Mapper.Map <DTO.OfferMng.OfferLineSparepart, OfferLineSparepart>(dtoDetail, dbDetail); // only allow edit item in case item does not put in factory order detail if (isAllowEditItem) { dbDetail.ModelID = dtoDetail.ModelID; dbDetail.PartID = dtoDetail.PartID; } } } } /* * MAP & CHECK OFFERLINE SAMPLE PRODUCT */ List <OfferLineSampleProduct> toBeDeletedItems = new List <OfferLineSampleProduct>(); if (dtoItem.OfferLineSampleProductDTOs != null) { //CHECK foreach (OfferLineSampleProduct dbSample in dbItem.OfferLineSampleProduct.Where(o => !dtoItem.OfferLineSampleProductDTOs.Select(s => s.OfferLineSampleProductID).Contains(o.OfferLineSampleProductID)).ToArray()) { dbItem.OfferLineSampleProduct.Remove(dbSample); } //MAP foreach (DTO.OfferMng.OfferLineSampleProductDTO dtoSample in dtoItem.OfferLineSampleProductDTOs) { OfferLineSampleProduct dbSample = null; if (dtoSample.OfferLineSampleProductID <= 0) { dbSample = new OfferLineSampleProduct(); dbItem.OfferLineSampleProduct.Add(dbSample); } else { dbSample = dbItem.OfferLineSampleProduct.FirstOrDefault(o => o.OfferLineSampleProductID == dtoSample.OfferLineSampleProductID); if (dbSample == null) { throw new Exception("Sample item not found!"); } } AutoMapper.Mapper.Map <DTO.OfferMng.OfferLineSampleProductDTO, OfferLineSampleProduct>(dtoSample, dbSample); } } /* * SETUP FORMATED FIELD */ //dbItem.OfferDate = Library.Helper.ConvertStringToDateTime(dtoItem.OfferDate, new System.Globalization.CultureInfo("vi-VN")); //dbItem.ValidUntil = Library.Helper.ConvertStringToDateTime(dtoItem.ValidUntil, new System.Globalization.CultureInfo("vi-VN")); //dbItem.LDS = Library.Helper.ConvertStringToDateTime(dtoItem.LDS, new System.Globalization.CultureInfo("vi-VN")); //dbItem.EstimatedDeliveryDate = Library.Helper.ConvertStringToDateTime(dtoItem.EstimatedDeliveryDate, new System.Globalization.CultureInfo("vi-VN")); Mapper.Map(dtoItem, dbItem); dbItem.OfferDate = dtoItem.OfferDateFormated.ConvertStringToDateTime(); dbItem.ValidUntil = dtoItem.ValidUntilFormated.ConvertStringToDateTime(); dbItem.LDS = dtoItem.LDSFormated.ConvertStringToDateTime(); dbItem.EstimatedDeliveryDate = dtoItem.EstimatedDeliveryDateFormated.ConvertStringToDateTime(); //var dtoEstimatedPurchasingPriceUpdatedBy = new DTO.OfferMng.OfferLine().EstimatedPurchasingPriceUpdatedByID = userId; //dtoItem.OfferLines.Select(x => x.EstimatedPurchasingPriceUpdatedByID = dtoEstimatedPurchasingPriceUpdatedBy).ToList(); //var dbdtoEstimatedPurchasingPriceUpdatedBy = new OfferLine().EstimatedPurchasingPriceUpdatedByID = userId; //dbItem.OfferLine.Select(x => x.EstimatedPurchasingPriceUpdatedByID = dbdtoEstimatedPurchasingPriceUpdatedBy).ToList(); //dtoEstimatedPurchasingPriceUpdatedBy = dbdtoEstimatedPurchasingPriceUpdatedBy; }