public bool DeleteOfferSeasonDetail(int offerSeasonDetailID, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.OfferSeasonDetailDTO dtoItem = new DTO.OfferSeasonDetailDTO(); try { using (OfferSeasonMngEntities context = CreateContext()) { if (offerSeasonDetailID > 0) { context.OfferSeasonMng_function_DeleteOfferSeasonDetail(offerSeasonDetailID); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; } return(false); }
public List <DTO.OfferSeasonDetailDTO> UpdateOfferSeasonDetail2(int userId, int offerSeasonID, object dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; List <DTO.OfferSeasonDetailDTO> dtoOfferSeasonDetails = ((Newtonsoft.Json.Linq.JArray)dtoItem).ToObject <List <DTO.OfferSeasonDetailDTO> >(); List <DTO.OfferSeasonDetailDTO> updatedReturnData = new List <DTO.OfferSeasonDetailDTO>(); try { using (OfferSeasonMngEntities context = CreateContext()) { foreach (var item in dtoOfferSeasonDetails) { DTO.OfferSeasonDetailDTO detailDTO = this.UpdateOfferSeasonDetail(userId, offerSeasonID, item.OfferSeasonDetailID, Newtonsoft.Json.Linq.JObject.FromObject(item), out notification); detailDTO.RowID = item.RowID; //asign rowID after get from db, so we can update back to frontend without reload page if (notification.Type != Library.DTO.NotificationType.Error) { updatedReturnData.Add(detailDTO); } } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = Library.Helper.HandleExceptionSingleLine(ex); } return(updatedReturnData); }
public DTO.OfferSeasonDetailDTO GetOfferSeasonDetail(int offerSeasonDetailID, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.OfferSeasonDetailDTO dtoItem = new DTO.OfferSeasonDetailDTO(); try { using (OfferSeasonMngEntities context = CreateContext()) { if (offerSeasonDetailID > 0) { var dbItem = context.OfferSeasonMng_OfferSeasonDetail_View.Where(o => o.OfferSeasonDetailID == offerSeasonDetailID).FirstOrDefault(); dtoItem = AutoMapper.Mapper.Map <OfferSeasonMng_OfferSeasonDetail_View, DTO.OfferSeasonDetailDTO>(dbItem); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; } return(dtoItem); }
public void DTO2DB_OfferSeasonDetail(int userId, int?offerSeasonTypeID, int offerSeasonDetailID, DTO.OfferSeasonDetailDTO dtoOfferSeasonDetail, bool isAllowEditProperties, ref OfferSeasonDetail dbItem) { // //some logic on dto item // if (offerSeasonDetailID <= 0) { if (offerSeasonTypeID == 1 || offerSeasonTypeID == 4 || offerSeasonTypeID == 5) //warehouse and sparepart { dtoOfferSeasonDetail.ItemStatus = 5; //auto approve item } } //auto change to status 2: Need Make Quotation if status is in 1: Pendding if (dtoOfferSeasonDetail.ItemStatus == 1) { dtoOfferSeasonDetail.ItemStatus = 2; } // //begin convert dto to db // //read from dto to db OfferSeasonDetailPriceOption OfferSeasonDetailPriceOption dbOfferSeasonDetailPriceOption; foreach (var item in dtoOfferSeasonDetail.OfferSeasonDetailPriceOptionDTOs) { if (item.OfferSeasonDetailPriceOptionID > 0) { dbOfferSeasonDetailPriceOption = dbItem.OfferSeasonDetailPriceOption.Where(o => o.OfferSeasonDetailPriceOptionID == item.OfferSeasonDetailPriceOptionID).FirstOrDefault(); } else { dbOfferSeasonDetailPriceOption = new OfferSeasonDetailPriceOption(); dbItem.OfferSeasonDetailPriceOption.Add(dbOfferSeasonDetailPriceOption); } if (dbOfferSeasonDetailPriceOption != null) { AutoMapper.Mapper.Map <DTO.OfferSeasonDetailPriceOptionDTO, OfferSeasonDetailPriceOption>(item, dbOfferSeasonDetailPriceOption); } } //read from dto to db OfferSeasonDetailRemark OfferSeasonDetailRemark dbOfferSeasonDetailRemark; foreach (var item in dtoOfferSeasonDetail.OfferSeasonDetailRemarkDTOs.Where(o => o.OfferSeasonDetailRemarkID <= 0)) { dbOfferSeasonDetailRemark = new OfferSeasonDetailRemark(); dbItem.OfferSeasonDetailRemark.Add(dbOfferSeasonDetailRemark); AutoMapper.Mapper.Map <DTO.OfferSeasonDetailRemarkDTO, OfferSeasonDetailRemark>(item, dbOfferSeasonDetailRemark); dbOfferSeasonDetailRemark.RemarkBy = userId; dbOfferSeasonDetailRemark.RemarkDate = DateTime.Now; } //map OfferSeasonDetail AutoMapper.Mapper.Map <DTO.OfferSeasonDetailDTO, OfferSeasonDetail>(dtoOfferSeasonDetail, dbItem); if (isAllowEditProperties) { dbItem.ModelID = dtoOfferSeasonDetail.ModelID; dbItem.FrameMaterialID = dtoOfferSeasonDetail.FrameMaterialID; dbItem.FrameMaterialColorID = dtoOfferSeasonDetail.FrameMaterialColorID; dbItem.MaterialID = dtoOfferSeasonDetail.MaterialID; dbItem.MaterialTypeID = dtoOfferSeasonDetail.MaterialTypeID; dbItem.MaterialColorID = dtoOfferSeasonDetail.MaterialColorID; dbItem.SubMaterialID = dtoOfferSeasonDetail.SubMaterialID; dbItem.SubMaterialColorID = dtoOfferSeasonDetail.SubMaterialColorID; dbItem.SeatCushionID = dtoOfferSeasonDetail.SeatCushionID; dbItem.BackCushionID = dtoOfferSeasonDetail.BackCushionID; dbItem.CushionColorID = dtoOfferSeasonDetail.CushionColorID; dbItem.FSCTypeID = dtoOfferSeasonDetail.FSCTypeID; dbItem.FSCPercentID = dtoOfferSeasonDetail.FSCPercentID; dbItem.ArticleCode = dtoOfferSeasonDetail.ArticleCode; dbItem.Description = dtoOfferSeasonDetail.Description; } //set tracking info if (dbItem.OfferSeasonDetailID > 0) { dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; } else { dbItem.CreatedBy = userId; dbItem.CreatedDate = DateTime.Now; } if (dbItem.ItemStatus == 5) // item is apprved { if (dtoOfferSeasonDetail.MarkAsApproved.HasValue && dtoOfferSeasonDetail.MarkAsApproved.Value) { dbItem.SetItemStatusBy = userId; dbItem.SetItemStatusDate = DateTime.Now; } } if (dtoOfferSeasonDetail.PlaningPurchasingPriceSelectedDate == "just now") { dbItem.PlaningPurchasingPriceSelectedBy = userId; dbItem.PlaningPurchasingPriceSelectedDate = DateTime.Now; } if (dtoOfferSeasonDetail.IsManuallyKeyIn.HasValue && dtoOfferSeasonDetail.IsManuallyKeyIn.Value) { dbItem.EstimatedPurchasingPriceUpdatedByID = userId; dbItem.EstimatedPurchasingPriceUpdatedDate = DateTime.Now; } if (dtoOfferSeasonDetail.MarkAsUnApproved.HasValue && dtoOfferSeasonDetail.MarkAsUnApproved.Value) { dbItem.UnApprovedBy = userId; dbItem.UnApprovedDate = DateTime.Now; } if (dtoOfferSeasonDetail.MarkAsNeedFactoryQuotation.HasValue) { dbItem.NeedFactoryQuotationBy = userId; dbItem.NeedFactoryQuotationDate = DateTime.Now; } if (dtoOfferSeasonDetail.PlaningPurchasingPriceFileHasChange.HasValue && dtoOfferSeasonDetail.PlaningPurchasingPriceFileHasChange.Value) { string tempFolder = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\"; dbItem.PlaningPurchasingPriceFile = (new Module.Framework.DAL.DataFactory()).CreateFilePointer(tempFolder, dtoOfferSeasonDetail.PlaningPurchasingPriceFileNewFile, dtoOfferSeasonDetail.PlaningPurchasingPriceFile, dtoOfferSeasonDetail.PlaningPurchasingPriceFileFriendlyName); } if (dtoOfferSeasonDetail.MarkAsClientSelected.HasValue) { dbItem.ClientSelectedBy = userId; dbItem.ClientSelectedDate = DateTime.Now; } }
public DTO.OfferSeasonDetailDTO UpdateOfferSeasonDetail(int userId, int offerSeasonID, int offerSeasonDetailID, object dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.OfferSeasonDetailDTO dtoOfferSeasonDetail = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.OfferSeasonDetailDTO>(); try { using (OfferSeasonMngEntities context = CreateContext()) { //find offer season to attach offerSeasonDetail OfferSeason dbOfferSeason = context.OfferSeason.Where(o => o.OfferSeasonID == offerSeasonID).FirstOrDefault(); if (dbOfferSeason == null) { throw new Exception("Could not find offer season"); } //offer seasons detail OfferSeasonDetail dbItem = null; bool isAllowEditProperties = true; if (offerSeasonDetailID > 0) { //get item to update dbItem = context.OfferSeasonDetail.Where(o => o.OfferSeasonDetailID == offerSeasonDetailID).FirstOrDefault(); //check item is in factory order so we can allow edit property of item bool isInFactoryOrder = context.OfferSeasonMng_function_CheckOfferItemIsInFactoryOrder(offerSeasonDetailID).FirstOrDefault().Value > 0; isAllowEditProperties = !isInFactoryOrder; //get admin permission Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); if (fwFactory.HasSpecialPermission(userId, Module.Framework.ConstantIdentifier.SPECIAL_PERMISSION_CHANGE_OFFER_ITEM_OPTION)) { isAllowEditProperties = true; } } else { //create new OfferSeasonDetail dbItem = new OfferSeasonDetail(); dbOfferSeason.OfferSeasonDetail.Add(dbItem); } if (dbItem == null) { throw new Exception("data not found offer season item!"); } else { //convert dto 2 db converter.DTO2DB_OfferSeasonDetail(userId, dbOfferSeason.OfferSeasonTypeID, offerSeasonDetailID, dtoOfferSeasonDetail, isAllowEditProperties, ref dbItem); if (dbItem.IsPlaningPurchasingPriceSelected.HasValue && dbItem.IsPlaningPurchasingPriceSelected.Value && dbItem.PlaningPurchasingPriceSelectedBy == null) { dbItem.PlaningPurchasingPriceSelectedBy = userId; dbItem.PlaningPurchasingPriceSelectedDate = DateTime.Now; } //save data context.SaveChanges(); //auto make quotation request to quotation //context.OfferSeasonQuotatonRequestMng_function_AddOfferSeasonItemToQuotation(dbItem.OfferSeasonDetailID, userId); // disabled, using trigger instead //auto reset quotation status if change property of item if (dtoOfferSeasonDetail.IsChangedProperties.HasValue && dtoOfferSeasonDetail.IsChangedProperties.Value && isAllowEditProperties) { context.OfferSeasonMng_function_ResetStatusOfQuotation(dbItem.OfferSeasonDetailID); } //get return data dtoOfferSeasonDetail = GetOfferSeasonDetail(dbItem.OfferSeasonDetailID, out notification); return(dtoOfferSeasonDetail); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = Library.Helper.HandleExceptionSingleLine(ex); return(null); } }