Beispiel #1
0
        public ConfigModel()
        {
            /// all the objects in the class have been initialized with an empty object to avoid
            /// throwing Object reference error even in all circumstances.
            /// these objects SHOULD be initialized with some default values - possibly from web.config for worst case scenarios.

            ConfigSettings         = new List <ConfigSettingModel>();
            BasketSettings         = new BasketSettings();
            B2BSettings            = new B2BSettings();
            CatalogSettings        = new CatalogSettings();
            DomainSettings         = new DomainSettings();
            OrderSettings          = new OrderSettings();
            SearchSettings         = new SearchSettings();
            SeoSettings            = new SeoSettings();
            ShippingSettings       = new ShippingSettings();
            SocialSettings         = new SocialSettings();
            RecommendationSettings = new RecommendationSettings();
            Currencies             = new List <CurrencyModel>();
            ShippingCountries      = new List <CountryModel>();
            BillingCountries       = new List <CountryModel>();
            Languages        = new List <LanguageModel>();
            RegionalSettings = new RegionalSettings();
            ReviewSettings   = new List <ProductReviewSection>();
            GeoLocators      = new List <GeoLocatorModel>();
            Snippets         = new List <SnippetModel>();
            FeatureToggles   = new FeatureToggleSettings();
        }
        public async Task sendInvoiceEmail(string invoiceHtml, string userEmail, string path, string pdfPathToSave)
        {
            try
            {
                //var order = GetOrderById(orderId);

                //order.PaymentMethodName = Utility.GetPaymentMethodName(order.PaymentMethod);

                //string invoiceHtml = MvcControllerCustom.RenderViewToString("Home", "~/Views/Home/GenerateInvoiceReport.cshtml", order, contextBase);

                //string path = @"~/Content/bootstrap.min.css";
                //path = HttpContext.Current.Server.MapPath(path);
                if (File.Exists(path))
                {
                    string readText = File.ReadAllText(path);
                    if (!string.IsNullOrWhiteSpace(readText))
                    {
                        invoiceHtml = invoiceHtml.Replace(".testClass {}", readText);
                    }
                }
                NReco.PdfGenerator.HtmlToPdfConverter pdfGenerator = new NReco.PdfGenerator.HtmlToPdfConverter();
                byte[] pdfDocument = pdfGenerator.GeneratePdf(invoiceHtml);

                var url = SaveFile.SaveFileFromBytes(pdfDocument, "PDFReports", pdfPathToSave);

                string       subject = "New Order Has been placed - " + EmailUtil.FromName;
                const string body    = "Please find attached Invoice file";

                var smtp = new SmtpClient
                {
                    Host                  = "smtp.gmail.com",
                    Port                  = 587,
                    EnableSsl             = true,
                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential(EmailUtil.FromMailAddress.Address, EmailUtil.FromPassword)
                };

                var message = new MailMessage(EmailUtil.FromMailAddress, new MailAddress(userEmail))
                {
                    Subject = subject,
                    Body    = body + " Invoice Attached"
                };
                var AdminEmail = BasketSettings.GetAdminEmailForOrders();
                if (AdminEmail != null)
                {
                    message.To.Add(new MailAddress(AdminEmail));
                }
                Attachment attachment = new Attachment(url);
                message.Attachments.Add(attachment);
                smtp.Send(message);
            }
            catch (Exception ex)
            {
                Utility.LogError(ex);
            }
        }
Beispiel #3
0
        RedisBasketRepository BuildBasketRepository()
        {
            var loggerFactory  = new LoggerFactory();
            var basketSettings = new BasketSettings()
            {
                ConnectionString = "127.0.0.1"
            };

            _optionsMock.Setup(x => x.Value).Returns(basketSettings);

            return(new RedisBasketRepository(_optionsMock.Object, loggerFactory));
        }
Beispiel #4
0
 public RedisBasketRepository(IOptionsSnapshot <BasketSettings> options, ILoggerFactory loggerFactory)
 {
     _settings = options.Value;
     _logger   = loggerFactory.CreateLogger <RedisBasketRepository>();
 }
Beispiel #5
0
 public Basket UpdateBasket(Guid basketId, BasketSettings newBasket)
 {
     return(new Basket("Basket " + basketId));
 }
Beispiel #6
0
 public Basket CreateBasket(BasketSettings newBasket)
 {
     return(new Basket("Basket 1"));
 }
        public async Task <IHttpActionResult> SetSettings()
        {
            try
            {
                Settings model        = new Settings();
                var      httpRequest  = HttpContext.Current.Request;
                string   newFullPath  = string.Empty;
                string   fileNameOnly = string.Empty;



                if (httpRequest.Params["Id"] != null)
                {
                    model.Id = Convert.ToInt32(httpRequest.Params["Id"]);
                }

                //if (httpRequest.Params["Tax"] != null)
                //    model.Tax = Convert.ToInt32(httpRequest.Params["Tax"]);

                if (httpRequest.Params["Currency"] != null)
                {
                    model.Currency = httpRequest.Params["Currency"];
                }

                if (httpRequest.Params["DeliveryFee"] != null)
                {
                    model.DeliveryFee = Convert.ToDouble(httpRequest.Params["DeliveryFee"]);
                }

                //if (httpRequest.Params["ContactNo"] != null)
                //    model.ContactNo = httpRequest.Params["ContactNo"];

                //if (httpRequest.Params["ContactNo"] != null)
                //    model.InstagramImage = httpRequest.Params["InstagramImage"];

                if (httpRequest.Params["FreeDeliveryThreshold"] != null)
                {
                    model.FreeDeliveryThreshold = Convert.ToDouble(httpRequest.Params["FreeDeliveryThreshold"]);
                }
                if (httpRequest.Params["BannerImages"] != null)
                {
                    //model.BannerImages = JsonConvert.DeserializeObject<List<Banner_Images>>(httpRequest.Params["BannerImages"]);

                    Validate(model);
                }

                #region Validations

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                if (httpRequest.Files.Count > 0)
                {
                    if (!Request.Content.IsMimeMultipartContent())
                    {
                        return(Content(HttpStatusCode.OK, new CustomResponse <Error>
                        {
                            Message = "UnsupportedMediaType",
                            StatusCode = (int)HttpStatusCode.UnsupportedMediaType,
                            Result = new Error {
                                ErrorMessage = "Multipart data is not included in request"
                            }
                        }));
                    }
                }
                #endregion


                //bool BannerImageChanged = false;

                using (RiscoContext ctx = new RiscoContext())
                {
                    Settings returnModel = new Settings();
                    returnModel = ctx.Settings.FirstOrDefault();

                    string         fileExtension = string.Empty;
                    HttpPostedFile postedFile;
                    //List<Banner_Images> bannerImages = model.BannerImages;


                    #region ImageSaving
                    //foreach (var file in httpRequest.Files)
                    //{
                    //    postedFile = httpRequest.Files[file.ToString()];
                    //    if (postedFile != null && postedFile.ContentLength > 0)
                    //    {
                    //        IList<string> AllowedFileExtensions = new List<string> { ".jpg", ".gif", ".png" };
                    //        var ext = Path.GetExtension(postedFile.FileName);
                    //        fileExtension = ext.ToLower();
                    //        if (!AllowedFileExtensions.Contains(fileExtension))
                    //        {
                    //            return Content(HttpStatusCode.OK, new CustomResponse<Error>
                    //            {
                    //                Message = "UnsupportedMediaType",
                    //                StatusCode = (int)HttpStatusCode.UnsupportedMediaType,
                    //                Result = new Error { ErrorMessage = "Please Upload image of type .jpg,.gif,.png" }
                    //            });
                    //        }
                    //        else if (postedFile.ContentLength > Global.MaximumImageSize)
                    //        {
                    //            return Content(HttpStatusCode.OK, new CustomResponse<Error>
                    //            {
                    //                Message = "UnsupportedMediaType",
                    //                StatusCode = (int)HttpStatusCode.UnsupportedMediaType,
                    //                Result = new Error { ErrorMessage = "Please Upload a file upto " + Global.ImageSize }
                    //            });
                    //        }
                    //        else
                    //        {

                    //        }
                    //    }
                    //    var guid = Guid.NewGuid();
                    //    newFullPath = HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings["BannerImageFolerPath"] + model.Id + "_" + guid + fileExtension);
                    //    postedFile.SaveAs(newFullPath);

                    //    if (Path.GetFileNameWithoutExtension(postedFile.FileName) == "Instagram")
                    //    {
                    //        model.InstagramImage = ConfigurationManager.AppSettings["BannerImageFolerPath"] + model.Id + "_" + guid + fileExtension;
                    //    }
                    //    //else if (Path.GetFileNameWithoutExtension(postedFile.FileName).Contains("Banner"))
                    //    //{
                    //    //    newFullPath = HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings["BannerImageFolerPath"] + "SettingsBanner_" + guid + fileExtension);
                    //    //    Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings["BannerImageFolerPath"]));
                    //    //    postedFile.SaveAs(newFullPath);
                    //    //    bannerImages.Add(new Banner_Images { Url = ConfigurationManager.AppSettings["BannerImageFolerPath"] + "SettingsBanner_" + guid + fileExtension });
                    //    //    BannerImageChanged = true;
                    //    //}
                    //}
                    #endregion

                    if (returnModel != null)
                    {
                        ctx.Database.ExecuteSqlCommand("TRUNCATE TABLE [Banner_Images] ");
                        //if (model.BannerImages != null && model.BannerImages.Count > 0)
                        //{
                        //    foreach (var item in bannerImages)
                        //    {
                        //        if (item.Product_Id == 0 )
                        //        {
                        //            item.Product_Id = null;
                        //        }

                        //    }
                        //    ctx.BannerImages.AddRange(bannerImages);
                        //}
                        //if (model.InstagramImage != null)
                        //{
                        //    returnModel.InstagramImage = model.InstagramImage;
                        //}
                        returnModel.Currency = model.Currency;
                        //returnModel.ContactNo = model.ContactNo;
                        returnModel.DeliveryFee           = model.DeliveryFee;
                        returnModel.FreeDeliveryThreshold = model.FreeDeliveryThreshold;
                        //returnModel.Tax = model.Tax;
                        ctx.SaveChanges();
                    }
                    else
                    {
                        ctx.Settings.Add(model);
                        ctx.SaveChanges();
                    }

                    BasketSettings.LoadSettings();
                    //returnModel.BannerImages = BasketSettings.Settings.BannerImages;

                    return(Ok(new CustomResponse <Settings>
                    {
                        Message = Global.ResponseMessages.Success,
                        StatusCode = (int)HttpStatusCode.OK,
                        Result = returnModel
                    }));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(Utility.LogError(ex)));
            }
        }
Beispiel #8
0
        public async Task <IHttpActionResult> SetSettings()
        {
            try
            {
                Settings model        = new Settings();
                var      httpRequest  = HttpContext.Current.Request;
                string   newFullPath  = string.Empty;
                string   fileNameOnly = string.Empty;



                if (httpRequest.Params["Id"] != null)
                {
                    model.Id = Convert.ToInt32(httpRequest.Params["Id"]);
                }

                //if (httpRequest.Params["ImageDeletedOnEdit"] != null)
                //    model.BannerImage = Convert.ToBoolean(httpRequest.Params["ImageDeletedOnEdit"]);
                if (httpRequest.Params["Currency"] != null)
                {
                    model.Currency = httpRequest.Params["Currency"];
                }
                if (httpRequest.Params["DeliveryFee"] != null)
                {
                    model.DeliveryFee = Convert.ToDouble(httpRequest.Params["DeliveryFee"]);
                }
                if (httpRequest.Params["FreeDeliveryThreshold"] != null)
                {
                    model.FreeDeliveryThreshold = Convert.ToDouble(httpRequest.Params["FreeDeliveryThreshold"]);
                }



                Validate(model);

                #region Validations

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                if (httpRequest.Files.Count > 0)
                {
                    if (!Request.Content.IsMimeMultipartContent())
                    {
                        return(Content(HttpStatusCode.OK, new CustomResponse <Error>
                        {
                            Message = "UnsupportedMediaType",
                            StatusCode = (int)HttpStatusCode.UnsupportedMediaType,
                            Result = new Error {
                                ErrorMessage = "Multipart data is not included in request"
                            }
                        }));
                    }
                    else if (httpRequest.Files.Count > 2)
                    {
                        return(Content(HttpStatusCode.OK, new CustomResponse <Error>
                        {
                            Message = "UnsupportedMediaType",
                            StatusCode = (int)HttpStatusCode.UnsupportedMediaType,
                            Result = new Error {
                                ErrorMessage = "Multiple images are not supported, please upload upto two image"
                            }
                        }));
                    }
                }
                #endregion



                //model.Phone = httpRequest.Params["Phone"];
                //model.Role = Convert.ToInt16(httpRequest.Params["Role"]);
                //model.Password = httpRequest.Params["Password"];
                //model.Status = (int)Global.StatusCode.NotVerified;



                using (SkriblContext ctx = new SkriblContext())
                {
                    Settings returnModel = new Settings();
                    returnModel = ctx.Settings.FirstOrDefault();
                    // in case on showing subscription table
                    if (string.IsNullOrEmpty(model.BannerImage) && string.IsNullOrEmpty(model.Currency) && model.DeliveryFee == 0)
                    {
                        return(Ok(new CustomResponse <Settings>
                        {
                            Message = Global.ResponseMessages.Success,
                            StatusCode = (int)HttpStatusCode.OK,
                            Result = returnModel
                        }));
                    }

                    string         fileExtension = string.Empty;
                    HttpPostedFile postedFile;
                    #region ImageSaving
                    foreach (var file in httpRequest.Files)
                    {
                        postedFile = httpRequest.Files[file.ToString()];
                        if (postedFile != null && postedFile.ContentLength > 0)
                        {
                            IList <string> AllowedFileExtensions = new List <string> {
                                ".jpg", ".gif", ".png"
                            };
                            var ext = Path.GetExtension(postedFile.FileName);
                            fileExtension = ext.ToLower();
                            if (!AllowedFileExtensions.Contains(fileExtension))
                            {
                                return(Content(HttpStatusCode.OK, new CustomResponse <Error>
                                {
                                    Message = "UnsupportedMediaType",
                                    StatusCode = (int)HttpStatusCode.UnsupportedMediaType,
                                    Result = new Error {
                                        ErrorMessage = "Please Upload image of type .jpg,.gif,.png"
                                    }
                                }));
                            }
                            else if (postedFile.ContentLength > Global.MaximumImageSize)
                            {
                                return(Content(HttpStatusCode.OK, new CustomResponse <Error>
                                {
                                    Message = "UnsupportedMediaType",
                                    StatusCode = (int)HttpStatusCode.UnsupportedMediaType,
                                    Result = new Error {
                                        ErrorMessage = "Please Upload a file upto " + Global.ImageSize
                                    }
                                }));
                            }
                            else
                            {
                            }
                        }
                        var guid = Guid.NewGuid();
                        newFullPath = HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings["BannerImageFolerPath"] + model.Id + "_" + guid + fileExtension);
                        postedFile.SaveAs(newFullPath);
                        if (Path.GetFileNameWithoutExtension(postedFile.FileName) == "Banner")
                        {
                            model.BannerImage = ConfigurationManager.AppSettings["BannerImageFolerPath"] + model.Id + "_" + guid + fileExtension;
                        }
                        else if (Path.GetFileNameWithoutExtension(postedFile.FileName) == "Instagram")
                        {
                            model.InstagramImage = ConfigurationManager.AppSettings["BannerImageFolerPath"] + model.Id + "_" + guid + fileExtension;
                        }
                    }
                    #endregion

                    if (returnModel != null)
                    {
                        if (model.BannerImage != "")
                        {
                            returnModel.BannerImage = model.BannerImage;
                        }
                        if (model.InstagramImage != null)
                        {
                            returnModel.InstagramImage = model.InstagramImage;
                        }
                        returnModel.Currency              = model.Currency;
                        returnModel.DeliveryFee           = model.DeliveryFee;
                        returnModel.FreeDeliveryThreshold = model.FreeDeliveryThreshold;
                        ctx.SaveChanges();
                    }
                    else
                    {
                        ctx.Settings.Add(model);
                        ctx.SaveChanges();
                    }

                    BasketSettings.LoadSettings();

                    return(Ok(new CustomResponse <Settings>
                    {
                        Message = Global.ResponseMessages.Success,
                        StatusCode = (int)HttpStatusCode.OK,
                        Result = returnModel
                    }));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(Utility.LogError(ex)));
            }
        }