예제 #1
0
        //
        // CUSTOM FUNCTION HERE
        //

        public DTO.SupportFormData GetInitData(int userId, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.SupportFormData data = new DTO.SupportFormData();
            data.SaleDTOs = new List <DTO.SaleDTO>();
            try
            {
                using (AccManagerPerformanceRptEntities context = CreateContext())
                {
                    if (fwFactory.HasSpecialPermission(userId, Module.Framework.ConstantIdentifier.SPECIAL_PERMISSION_VIEW_ALL_SALES_DATA))
                    {
                        data.SaleDTOs.Add(new DTO.SaleDTO {
                            UserID = -1, EmployeeNM = "All Account Manager"
                        });
                        data.SaleDTOs.AddRange(converter.DB2DTO_Sale(context.SupportMng_ActiveSales_View.ToList()));
                    }
                    else
                    {
                        data.SaleDTOs = converter.DB2DTO_Sale(context.SupportMng_ActiveSales_View.Where(o => o.UserID == userId).ToList());
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.HandleExceptionSingleLine(ex);
            }
            return(data);
        }
예제 #2
0
        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;
        }
예제 #3
0
        public void DTO2BD(DTO.Employee dtoItem, ref Employee dbItem, string TmpFile, int userId)
        {
            //AutoMapper.Mapper.Map<DTO.Employee, Employee>(dtoItem, dbItem);
            if (dtoItem.AnnualLeaveSettings != null)
            {
                //check for child rows deleted
                foreach (AnnualLeaveSetting dbSetting in dbItem.AnnualLeaveSetting.ToArray())
                {
                    if (!dtoItem.AnnualLeaveSettings.Select(o => o.AnnualLeaveSettingID).Contains(dbSetting.AnnualLeaveSettingID))
                    {
                        dbItem.AnnualLeaveSetting.Remove(dbSetting);
                    }
                }
                //map child row
                foreach (DTO.AnnualLeaveSetting dtoSetting in dtoItem.AnnualLeaveSettings)
                {
                    AnnualLeaveSetting dbSetting;
                    if (dtoSetting.AnnualLeaveSettingID <= 0)
                    {
                        dbSetting = new AnnualLeaveSetting();
                        dbItem.AnnualLeaveSetting.Add(dbSetting);
                    }
                    else
                    {
                        dbSetting = dbItem.AnnualLeaveSetting.FirstOrDefault(o => o.AnnualLeaveSettingID == dtoSetting.AnnualLeaveSettingID);
                    }
                    if (dbSetting != null)
                    {
                        AutoMapper.Mapper.Map <DTO.AnnualLeaveSetting, AnnualLeaveSetting>(dtoSetting, dbSetting);
                    }
                }
            }

            if (dtoItem.EmployeeFactorys != null)
            {
                foreach (var item in dbItem.EmployeeFactory.ToArray())
                {
                    if (!dtoItem.EmployeeFactorys.Select(o => o.EmployeeFactoryID).Contains(item.EmployeeFactoryID))
                    {
                        dbItem.EmployeeFactory.Remove(item);
                    }
                }
                //map child row
                foreach (var item in dtoItem.EmployeeFactorys)
                {
                    EmployeeFactory dbEmpFactory;
                    if (item.EmployeeFactoryID <= 0)
                    {
                        dbEmpFactory = new EmployeeFactory();
                        dbItem.EmployeeFactory.Add(dbEmpFactory);
                    }
                    else
                    {
                        dbEmpFactory = dbItem.EmployeeFactory.FirstOrDefault(o => o.EmployeeFactoryID == item.EmployeeFactoryID);
                    }
                    if (dbEmpFactory != null)
                    {
                        AutoMapper.Mapper.Map <DTO.EmployeeFactory, EmployeeFactory>(item, dbEmpFactory);
                    }
                }
            }

            if (dtoItem.EmployeeResponsibleForDTOs != null)
            {
                foreach (var item in dbItem.EmployeeResponsibleFor.ToArray())
                {
                    if (!dtoItem.EmployeeResponsibleForDTOs.Select(o => o.ResposibleForID).Contains(item.ResposibleForID))
                    {
                        dbItem.EmployeeResponsibleFor.Remove(item);
                    }
                }
                //map child row
                foreach (var item in dtoItem.EmployeeResponsibleForDTOs)
                {
                    EmployeeResponsibleFor dbEmployeeResponsibleFor;
                    if (item.ResposibleForID <= 0 || item.ResposibleForID == null)
                    {
                        dbEmployeeResponsibleFor = new EmployeeResponsibleFor();
                        dbItem.EmployeeResponsibleFor.Add(dbEmployeeResponsibleFor);
                    }
                    else
                    {
                        dbEmployeeResponsibleFor = dbItem.EmployeeResponsibleFor.FirstOrDefault(o => o.ResposibleForID == item.ResposibleForID);
                    }
                    if (dbEmployeeResponsibleFor != null)
                    {
                        Mapper.Map(item, dbEmployeeResponsibleFor);
                    }
                }
            }
            Mapper.Map(dtoItem, dbItem);
            dbItem.DateStart         = dtoItem.DateStart.ConvertStringToDateTime();
            dbItem.DateEnd           = dtoItem.DateEnd.ConvertStringToDateTime();
            dbItem.DateOfBirth       = dtoItem.DateOfBirth.ConvertStringToDateTime();
            dbItem.ContractPeriod    = dtoItem.ContractPeriod.ConvertStringToDateTime();
            dbItem.ContractStartDate = dtoItem.ContractStartDate.ConvertStringToDateTime();

            //
            // map the field only for user with special permission
            //
            if (dtoItem.NeedToUpdateManagerData && fwFactory.HasSpecialPermission(userId, Module.Framework.ConstantIdentifier.SPECIAL_PERMISSION_EMPLOYEE_MANAGER_NOTE))
            {
                dbItem.ManagerNote = dtoItem.ManagerNote;

                // manager attached files
                if (dtoItem.EmployeeFileDTOs != null)
                {
                    foreach (var item in dbItem.EmployeeFile.ToArray())
                    {
                        if (!dtoItem.EmployeeFileDTOs.Select(o => o.EmployeeFileID).Contains(item.EmployeeFileID))
                        {
                            if (!string.IsNullOrEmpty(item.FileUD))
                            {
                                fwFactory.RemoveImageFile(item.FileUD);
                            }

                            dbItem.EmployeeFile.Remove(item);
                        }
                    }
                    //map child row
                    foreach (var item in dtoItem.EmployeeFileDTOs)
                    {
                        EmployeeFile dbFile;
                        if (item.EmployeeFileID <= 0)
                        {
                            dbFile = new EmployeeFile();
                            dbItem.EmployeeFile.Add(dbFile);
                        }
                        else
                        {
                            dbFile = dbItem.EmployeeFile.FirstOrDefault(o => o.EmployeeFileID == item.EmployeeFileID);
                        }

                        if (dbFile != null)
                        {
                            AutoMapper.Mapper.Map <DTO.EmployeeFileDTO, EmployeeFile>(item, dbFile);
                            if (item.HasChanged)
                            {
                                dbFile.FileUD = fwFactory.CreateNoneImageFilePointer(TmpFile, item.NewFile, dbFile.FileUD, item.FriendlyName);
                            }
                        }
                    }
                }

                // contract files
                if (dtoItem.EmployeeContractDTOs != null)
                {
                    foreach (var item in dbItem.EmployeeContract.ToArray())
                    {
                        if (!dtoItem.EmployeeContractDTOs.Select(o => o.EmployeeContractID).Contains(item.EmployeeContractID))
                        {
                            if (!string.IsNullOrEmpty(item.FileUD))
                            {
                                fwFactory.RemoveImageFile(item.FileUD);
                            }

                            dbItem.EmployeeContract.Remove(item);
                        }
                    }
                    //map child row
                    foreach (var item in dtoItem.EmployeeContractDTOs)
                    {
                        EmployeeContract dbContract;
                        if (item.EmployeeContractID <= 0)
                        {
                            dbContract = new EmployeeContract();
                            dbItem.EmployeeContract.Add(dbContract);
                        }
                        else
                        {
                            dbContract = dbItem.EmployeeContract.FirstOrDefault(o => o.EmployeeContractID == item.EmployeeContractID);
                        }

                        if (dbContract != null)
                        {
                            AutoMapper.Mapper.Map <DTO.EmployeeContractDTO, EmployeeContract>(item, dbContract);
                            dbContract.ValidFrom = item.ValidFrom.ConvertStringToDateTime();
                            if (item.HasChanged)
                            {
                                dbContract.FileUD = fwFactory.CreateNoneImageFilePointer(TmpFile, item.NewFile, dbContract.FileUD, item.FriendlyName);
                            }
                        }
                    }
                }
            }
            if (dtoItem.factoryAccesses != null)
            {
                foreach (var item in dbItem.QAQCFactoryAccess.ToArray())
                {
                    if (!dtoItem.factoryAccesses.Select(o => o.QAQCFactoryAccessID).Contains(item.QAQCFactoryAccessID))
                    {
                        dbItem.QAQCFactoryAccess.Remove(item);
                    }
                }
                //map child row
                foreach (var item in dtoItem.factoryAccesses)
                {
                    QAQCFactoryAccess dbfac;
                    if (item.QAQCFactoryAccessID <= 0)
                    {
                        dbfac = new QAQCFactoryAccess();
                        dbItem.QAQCFactoryAccess.Add(dbfac);
                    }
                    else
                    {
                        dbfac = dbItem.QAQCFactoryAccess.FirstOrDefault(o => o.QAQCFactoryAccessID == item.QAQCFactoryAccessID);
                    }
                    if (dbfac != null)
                    {
                        Mapper.Map(item, dbfac);
                    }
                }
            }
        }
예제 #4
0
        public override DTO.SearchFormData GetDataWithFilter(System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.SearchFormData data = new DTO.SearchFormData();
            data.Data = new List <DTO.DeltaByClientDTO>();
            totalRows = 0;

            string Season   = null;
            int?   SaleID   = null;
            int    UserID   = 0;
            int?   ClientID = null;

            if (filters.ContainsKey("Season") && filters["Season"] != null && !string.IsNullOrEmpty(filters["Season"].ToString()))
            {
                Season = filters["Season"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("UserID") && filters["UserID"] != null && !string.IsNullOrEmpty(filters["UserID"].ToString()))
            {
                UserID = Convert.ToInt32(filters["UserID"].ToString());
            }
            if (!fwFactory.HasSpecialPermission(UserID, "ViewAllSalesData"))
            {
                SaleID = UserID;
            }
            else
            {
                if (filters.ContainsKey("SaleID") && filters["SaleID"] != null && !string.IsNullOrEmpty(filters["SaleID"].ToString()))
                {
                    SaleID = Convert.ToInt32(filters["SaleID"].ToString());
                }
                if (SaleID == -1)
                {
                    SaleID = null;
                }
            }

            if (filters.ContainsKey("ClientID") && filters["ClientID"] != null && !string.IsNullOrEmpty(filters["ClientID"].ToString()))
            {
                ClientID = Convert.ToInt32(filters["ClientID"].ToString());
            }

            //try to get data
            try
            {
                using (MIDeltaByClientRptEntities context = CreateContext())
                {
                    //totalRows = context.Sample2Mng_function_SearchSampleOrder(SampleOrderUD, Season, ClientUD, ClientNM, PurposeID, TransportTypeID, SampleOrderStatusID, orderBy, orderDirection).Count();
                    var result = context.MIDeltaByClientRpt_function_SearchData(Season, SaleID, ClientID, orderBy, orderDirection).ToList();
                    data.Data = converter.DB2DTO_DeltaByClient(result);
                    totalRows = result.Count();
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }
        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);
            }
        }
예제 #6
0
        public override DTO.SearchFormData GetDataWithFilter(System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.SearchFormData data = new DTO.SearchFormData();
            data.Data = new List <DTO.DeltaByClientDTO>();
            data.AccountManagerSummaryDTOs = new List <DTO.AccountManagerSummaryDTO>();
            totalRows = 0;

            string Season = null;
            int?   SaleID = null;
            int    UserID = 0;

            if (filters.ContainsKey("Season") && filters["Season"] != null && !string.IsNullOrEmpty(filters["Season"].ToString()))
            {
                Season = filters["Season"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("UserID") && filters["UserID"] != null && !string.IsNullOrEmpty(filters["UserID"].ToString()))
            {
                UserID = Convert.ToInt32(filters["UserID"].ToString());
            }
            if (!fwFactory.HasSpecialPermission(UserID, "ViewAllSalesData"))
            {
                SaleID = UserID;
            }
            else
            {
                if (filters.ContainsKey("SaleID") && filters["SaleID"] != null && !string.IsNullOrEmpty(filters["SaleID"].ToString()))
                {
                    SaleID = Convert.ToInt32(filters["SaleID"].ToString());
                }
                if (SaleID == -1)
                {
                    SaleID = null;
                }
            }

            //try to get data
            try
            {
                using (MIDeltaByClientOSRptEntities context = CreateContext())
                {
                    var        result          = context.MIDeltaByClientOSRpt_function_SearchData(Season, SaleID, orderBy, orderDirection).ToList();
                    List <int> existingSaleIDs = result.Select(r => r.SaleID.Value).ToList();
                    string     prevSeason      = Library.Helper.GetPreviousSeason(Season);
                    var        accData         = context.MIDeltaByClientOSRpt_AccountManagerSummary_View.Where(o => existingSaleIDs.Contains(o.SaleID.Value) && o.Season == prevSeason);
                    data.Data = converter.DB2DTO_DeltaByClient(result);
                    data.AccountManagerSummaryDTOs = converter.DB2DTO_AccountManagerSummaryDTO(accData.ToList());
                    totalRows = result.Count();
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }
예제 #7
0
        public DTO.SearchFormData GetDataWithFilter(int userId, System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.SearchFormData data = new DTO.SearchFormData();
            data.Data = new List <DTO.ProductSearchResultDTO>();
            totalRows = 0;

            //try to get data
            try
            {
                using (WEXStockOverviewRptEntities context = CreateContext())
                {
                    string ArticleCode   = null;
                    string SubEANCode    = null;
                    string Description   = null;
                    string ProductTypeNM = null;
                    bool?  NoImage       = false;
                    int?   ItemSourceID  = null;

                    if (filters.ContainsKey("ArticleCode") && !string.IsNullOrEmpty(filters["ArticleCode"].ToString()))
                    {
                        ArticleCode = filters["ArticleCode"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("SubEANCode") && !string.IsNullOrEmpty(filters["SubEANCode"].ToString()))
                    {
                        SubEANCode = filters["SubEANCode"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("Description") && !string.IsNullOrEmpty(filters["Description"].ToString()))
                    {
                        Description = filters["Description"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("ProductTypeNM") && !string.IsNullOrEmpty(filters["ProductTypeNM"].ToString()))
                    {
                        ProductTypeNM = filters["ProductTypeNM"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("NoImage") && filters["NoImage"] != null && !string.IsNullOrEmpty(filters["NoImage"].ToString()))
                    {
                        NoImage = (filters["NoImage"].ToString() == "true") ? true : false;
                    }
                    if (filters.ContainsKey("ItemSourceID") && filters["ItemSourceID"] != null && !string.IsNullOrEmpty(filters["ItemSourceID"].ToString()))
                    {
                        ItemSourceID = Convert.ToInt32(filters["ItemSourceID"]);
                    }
                    totalRows = context.WEXStockOverviewRpt_function_SearchProduct(ArticleCode, SubEANCode, Description, ProductTypeNM, NoImage, ItemSourceID, orderBy, orderDirection).Count();
                    var result = context.WEXStockOverviewRpt_function_SearchProduct(ArticleCode, SubEANCode, Description, ProductTypeNM, NoImage, ItemSourceID, orderBy, orderDirection);
                    //data.Data = converter.DB2DTO_ProductSearchResultList(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                    data.Data = converter.DB2DTO_ProductSearchResultList(result.ToList());
                    if (!fwFactory.HasSpecialPermission(userId, Module.Framework.ConstantIdentifier.SPECIAL_PERMISSION_WEX_VVP))
                    {
                        data.Data.ForEach(o => o.VVPPrice = null);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }