Пример #1
0
        public AdminCostViewModel ReplaceAllCost(AdminCostViewModel cost)
        {
            cost.AdditionalScreenCosts = cost.AdditionalScreenCosts.Replace(",", ".");
            cost.DTGPrintPrice         = cost.DTGPrintPrice.Replace(",", ".");
            cost.FirstScreenCost       = cost.FirstScreenCost.Replace(",", ".");
            cost.InkCost    = cost.InkCost.Replace(",", ".");
            cost.LabourCost = cost.LabourCost.Replace(",", ".");
            cost.PercentageMarkUpRequired = cost.PercentageMarkUpRequired.Replace(",", ".");

            return(cost);
        }
Пример #2
0
        public ActionResult Edit()
        {
            TShirtCostRecord cost = _costService.GetCost(cultureSearch);

            if (cost == null)
            {
                return(View("Edit"));
            }
            else
            {
                AdminCostViewModel costViewModel = new AdminCostViewModel {
                    AdditionalScreenCosts = cost.AdditionalScreenCosts.ToString(), DTGPrintPrice = cost.DTGPrintPrice.ToString(), FirstScreenCost = cost.FirstScreenCost.ToString(), InkCost = cost.InkCost.ToString(), LabourCost = cost.LabourCost.ToString(), LabourTimePerColourPerPrint = cost.LabourTimePerColourPerPrint, LabourTimePerSidePrintedPerPrint = cost.LabourTimePerSidePrintedPerPrint, PercentageMarkUpRequired = cost.PercentageMarkUpRequired.ToString(), PrintsPerLitre = cost.PrintsPerLitre, SalesGoal = cost.SalesGoal, MaxColors = cost.MaxColors, MinimumTarget = cost.MinimumTarget
                };

                return(View("Edit", costViewModel));
            }
        }
Пример #3
0
        // GET: Wizard
        public ActionResult Index(int?id)
        {
            ViewBag.Currencies = _currencyRepository.Table.ToArray();

            var commonSettings = _commonSettingsRepository.Table
                                 .FirstOrDefault(s => s.CommonCulture == _cultureUsed);

            if (commonSettings == null)
            {
                _commonSettingsRepository.Create(new CommonSettingsRecord()
                {
                    DoNotAcceptAnyNewCampaigns = false,
                    CommonCulture = _cultureUsed
                });

                commonSettings = _commonSettingsRepository.Table
                                 .First(s => s.CommonCulture == _cultureUsed);
            }

            if (commonSettings.DoNotAcceptAnyNewCampaigns)
            {
                return(RedirectToAction("Oops"));
            }

            var product = _productService.GetAllProducts()
                          .Where(pr => pr.ProductHeadlineRecord.ProdHeadCulture == _cultureUsed);

            var group = _productService.GetAllProductGroups()
                        .Where(gr => gr.ProdGroupCulture == _cultureUsed);

            var color = _productService.GetAllColorsAvailable()
                        .Where(col => col.ProdColorCulture == _cultureUsed);

            //var art = _artRepository.Table.Where(a => a.ArtCulture == cultureUsed);
            var font = _fontService.GetAllfonts()
                       .Where(f => f.FontCulture == _cultureUsed);

            var swatch = _swatchService.GetAllSwatches()
                         .Where(s => s.SwatchCulture == _cultureUsed);

            var currencies = _currencyRepository.Table
                             .Where(c => c.CurrencyCulture == _cultureUsed);

            var sizes = _productService.GetAllProducts()
                        .Where(pr => pr.ProductImageRecord.ProdImgCulture == _cultureUsed);

            //var images = _productService.GetAllProducts().Where(pr => pr.);

            if (!product.Any() ||
                !group.Any() ||
                !color.Any() ||
                !font.Any() ||
                !swatch.Any() ||
                !currencies.Any() ||
                !sizes.Any())
            {
                return(RedirectToAction("Oops"));
            }

            var cost = _costService.GetCost(_cultureUsed);

            var currencyFrom = _currencyRepository.Table
                               .First(c => c.CurrencyCulture == _cultureUsed);

            var costViewModel = new AdminCostViewModel();

            if (cost != null)
            {
                costViewModel.AdditionalScreenCosts = cost.AdditionalScreenCosts.ToString();

                var dtgPrintPrice = cost.DTGPrintPrice; //_priceConversionService
                //.ConvertPrice(cost.DTGPrintPrice, currencyFrom, ExchangeRateFor.Seller);
                costViewModel.DTGPrintPrice = dtgPrintPrice.ToString();

                var firstScreenCost = cost.FirstScreenCost; //_priceConversionService
                //.ConvertPrice(cost.FirstScreenCost, currencyFrom, ExchangeRateFor.Seller);
                costViewModel.FirstScreenCost = firstScreenCost.ToString();

                var inkCost = cost.InkCost; // _priceConversionService
                //.ConvertPrice(cost.InkCost, currencyFrom, ExchangeRateFor.Seller);
                costViewModel.InkCost = inkCost.ToString();

                var laborCost = cost.LabourCost; // _priceConversionService
                //.ConvertPrice(cost.LabourCost, currencyFrom, ExchangeRateFor.Seller);
                costViewModel.LabourCost = laborCost.ToString();

                costViewModel.LabourTimePerColourPerPrint      = cost.LabourTimePerColourPerPrint;
                costViewModel.LabourTimePerSidePrintedPerPrint = cost.LabourTimePerSidePrintedPerPrint;
                costViewModel.PercentageMarkUpRequired         = cost.PercentageMarkUpRequired.ToString();
                costViewModel.PrintsPerLitre = cost.PrintsPerLitre;
                costViewModel.SalesGoal      = cost.SalesGoal;
                costViewModel.MinimumTarget  = cost.MinimumTarget;
                costViewModel.MaxColors      = cost.MaxColors;
                costViewModel = ReplaceAllCost(costViewModel);
            }

            if (id != null && id > 0)
            {
                var campaignId = (int)id;
                var campaign   = _campaignService.GetCampaignById(campaignId);
                var products   = _campaignService.GetProductsOfCampaign(campaignId).ToList();
                costViewModel.Campaign = campaign;
                costViewModel.Products = products;
            }

            if (_orchardServices.WorkContext.CurrentUser != null)
            {
                var currentUserRoles = _orchardServices.WorkContext.CurrentUser.ContentItem.As <UserRolesPart>().Roles;
                costViewModel.IsCurrentUserAdministrator = currentUserRoles.Any(r => r == "Administrator");
            }

            var facebookSettingsPart = _orchardServices.WorkContext.CurrentSite.As <FacebookSettingsPart>();

            costViewModel.FacebookClientId = facebookSettingsPart.ClientId;

            var googleSettingsPart = _orchardServices.WorkContext.CurrentSite.As <GoogleSettingsPart>();

            costViewModel.GoogleClientId = googleSettingsPart.ClientId;

            costViewModel.GoogleApiKey = "AIzaSyBijPOV5bUKPNRKTE8areEVNi81ji7sS1I";

            costViewModel.CampaignCurrencyId = _currencyRepository.Table.FirstOrDefault(aa => aa.Code == "USD") != null?_currencyRepository.Table.FirstOrDefault(aa => aa.Code == "USD").Id : _priceConversionService.CurrentUserCurrency.Id;

            costViewModel.CurrencyCulture = _currencyRepository.Table.FirstOrDefault(aa => aa.Code == "USD") != null ? "USD" : _priceConversionService.CurrentUserCurrency.Code;

            costViewModel.IsAdmin = _orchardServices.WorkContext.CurrentUser != null;


            return(View(costViewModel));
        }
Пример #4
0
        public ActionResult Save(AdminCostViewModel costViewModel)
        {
            costViewModel = ReplaceAllCost(costViewModel);

            bool  dontUpdate = false;
            float flo;

            try
            {
                flo = Convert.ToSingle(costViewModel.AdditionalScreenCosts, new CultureInfo("en-US"));
            }
            catch
            {
                Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("Incorrect entries in the box \"Additional Screen Costs\""));
                dontUpdate = true;
            }
            try
            {
                flo = Convert.ToSingle(costViewModel.DTGPrintPrice, new CultureInfo("en-US"));
            }
            catch
            {
                Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("Incorrect entries in the box \"DTG print price\""));
                dontUpdate = true;
            }
            try
            {
                flo = Convert.ToSingle(costViewModel.FirstScreenCost, new CultureInfo("en-US"));
            }
            catch
            {
                Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("Incorrect entries in the box \"1st Screen Cost\""));
                dontUpdate = true;
            }
            try
            {
                flo = Convert.ToSingle(costViewModel.InkCost, new CultureInfo("en-US"));
            }
            catch
            {
                Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("Incorrect entries in the box \"Ink Cost\""));
                dontUpdate = true;
            }
            try
            {
                flo = Convert.ToSingle(costViewModel.LabourCost, new CultureInfo("en-US"));
            }
            catch
            {
                Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("Incorrect entries in the box \"Labour Cost\""));
                dontUpdate = true;
            }
            if (costViewModel.LabourTimePerColourPerPrint == 0)
            {
                Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("Incorrect entries in the box \"Labour time per colour per print\""));
                dontUpdate = true;
            }
            if (costViewModel.LabourTimePerSidePrintedPerPrint == 0)
            {
                Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("Incorrect entries in the box \"Labour time per side printed per print\""));
                dontUpdate = true;
            }
            try
            {
                flo = Convert.ToSingle(costViewModel.PercentageMarkUpRequired, new CultureInfo("en-US"));
            }
            catch
            {
                Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("Incorrect entries in the box \"Percentage Mark-Up required\""));
                dontUpdate = true;
            }
            if (costViewModel.PrintsPerLitre == 0)
            {
                Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("Incorrect entries in the box \"Prints per litre\""));
                dontUpdate = true;
            }
            if (dontUpdate)
            {
                return(this.RedirectToAction("Edit"));
            }

            TShirtCostRecord cost = _costService.GetCost(cultureSearch);

            if (cost == null)
            {
                TShirtCostRecord newCost = new TShirtCostRecord
                {
                    AdditionalScreenCosts = Convert.ToSingle(costViewModel.AdditionalScreenCosts, new CultureInfo("en-US")),
                    DTGPrintPrice         = Convert.ToSingle(costViewModel.DTGPrintPrice, new CultureInfo("en-US")),
                    FirstScreenCost       = Convert.ToSingle(costViewModel.FirstScreenCost, new CultureInfo("en-US")),
                    InkCost    = Convert.ToSingle(costViewModel.InkCost, new CultureInfo("en-US")),
                    LabourCost = Convert.ToSingle(costViewModel.LabourCost, new CultureInfo("en-US")),
                    LabourTimePerColourPerPrint      = costViewModel.LabourTimePerColourPerPrint,
                    LabourTimePerSidePrintedPerPrint = costViewModel.LabourTimePerSidePrintedPerPrint,
                    PercentageMarkUpRequired         = Convert.ToSingle(costViewModel.PercentageMarkUpRequired, new CultureInfo("en-US")),
                    PrintsPerLitre = costViewModel.PrintsPerLitre,
                    SalesGoal      = costViewModel.SalesGoal,
                    MaxColors      = costViewModel.MaxColors,
                    CostCulture    = cultureSearch,
                    MinimumTarget  = costViewModel.MinimumTarget
                };

                if (_costService.InsertCost(newCost))
                {
                    Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Information, T("Data update was successfully"));
                }
                else
                {
                    Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("When you try to update the data error occurred. Please, try again later!"));
                }
            }
            else
            {
                var ncost = new TShirtCostRecord()
                {
                    AdditionalScreenCosts = Convert.ToSingle(costViewModel.AdditionalScreenCosts, new CultureInfo("en-US")),
                    DTGPrintPrice         = Convert.ToSingle(costViewModel.DTGPrintPrice, new CultureInfo("en-US")),
                    FirstScreenCost       = Convert.ToSingle(costViewModel.FirstScreenCost, new CultureInfo("en-US")),
                    InkCost     = Convert.ToSingle(costViewModel.InkCost, new CultureInfo("en-US")),
                    CostCulture = "en-MY",
                    LabourCost  = Convert.ToSingle(costViewModel.LabourCost, new CultureInfo("en-US")),
                    LabourTimePerColourPerPrint      = costViewModel.LabourTimePerColourPerPrint,
                    LabourTimePerSidePrintedPerPrint = costViewModel.LabourTimePerSidePrintedPerPrint,
                    PercentageMarkUpRequired         = Convert.ToSingle(costViewModel.PercentageMarkUpRequired, new CultureInfo("en-US")),
                    PrintsPerLitre = costViewModel.PrintsPerLitre,
                    SalesGoal      = costViewModel.SalesGoal,
                    MaxColors      = costViewModel.MaxColors,
                    CostRevision   = cost.CostRevision + 1,
                    MinimumTarget  = costViewModel.MinimumTarget
                };



                //cost.AdditionalScreenCosts = Convert.ToSingle(costViewModel.AdditionalScreenCosts, new CultureInfo("en-US"));
                //cost.DTGPrintPrice = Convert.ToSingle(costViewModel.DTGPrintPrice, new CultureInfo("en-US"));
                //cost.FirstScreenCost = Convert.ToSingle(costViewModel.FirstScreenCost, new CultureInfo("en-US"));
                //cost.InkCost = Convert.ToSingle(costViewModel.InkCost, new CultureInfo("en-US"));
                //cost.LabourCost = Convert.ToSingle(costViewModel.LabourCost, new CultureInfo("en-US"));
                //cost.LabourTimePerColourPerPrint = costViewModel.LabourTimePerColourPerPrint;
                //cost.LabourTimePerSidePrintedPerPrint = costViewModel.LabourTimePerSidePrintedPerPrint;
                //cost.PercentageMarkUpRequired = Convert.ToSingle(costViewModel.PercentageMarkUpRequired, new CultureInfo("en-US"));
                //cost.PrintsPerLitre = costViewModel.PrintsPerLitre;
                //cost.SalesGoal = costViewModel.SalesGoal;
                //cost.MaxColors = costViewModel.MaxColors;

                if (_costService.InsertCost(ncost))
                {
                    Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Information, T("Data update was successfully"));
                }
                else
                {
                    Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("When you try to update the data error occurred. Please, try again later!"));
                }
            }

            return(this.RedirectToAction("Index"));
        }