Example #1
0
        public ActionResult Create(SiteImage model)
        {
            try
            {
                model.Id = 0;
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var siteImage = new SiteImage{ImageType = (int)ImageType.Banner};
                    var file = Request.Files[i];
                    if (file == null) continue;
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    string filePath = Server.MapPath("~/Content/Images");

                    filePath = Path.Combine(filePath, fileName);
                    GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500);
                    siteImage.ImageSource = fileName;
                    _repository.AddSiteImage(siteImage);
                }
            }
            catch (Exception ex)
            {
                TempData["errorMessage"] = ex.Message + (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message) ? ex.InnerException.Message : "");
                return View(model);
            }

            return RedirectToAction("Index");
        }
Example #2
0
        public ActionResult Create(SiteImage model)
        {
            try
            {
                model.Id = 0;
                var siteImage = new SiteImage
                {
                    ImageType = model.ImageType,
                    Text = model.Text ?? "",
                    TextEng = model.TextEng ?? "",
                    Text2 = model.Text2 ?? "",
                    Text2Eng = model.Text2Eng ?? ""
                };

                var file = Request.Files[0];
                if (file != null && !string.IsNullOrEmpty(file.FileName))
                {
                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    string filePath = Server.MapPath("~/Content/Images");

                    filePath = Path.Combine(filePath, fileName);
                    GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500);
                    siteImage.ImageSource = fileName;
                }
                else
                {
                    siteImage.ImageSource = siteImage.ImageSource ?? "";
                }

                _repository.AddSiteImage(siteImage);
            }
            catch (Exception ex)
            {
                TempData["errorMessage"] = ex.Message + (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message) ? ex.InnerException.Message : "");
                return View(model);
            }

            return RedirectToAction("Index");
        }
Example #3
0
        public ActionResult Edit(SiteImage model)
        {
            try
            {
                var article = _repository.GetSiteImage(model.Id);
                //article.Text = model.Text == null ? "" : HttpUtility.HtmlDecode(model.Text);
                article.Text = model.Text ?? "";
                article.TextEng = model.TextEng ?? "";
                article.Text2 = model.Text2 ?? "";
                article.Text2Eng = model.Text2Eng ?? "";

                var file = Request.Files[0];
                if (file != null && !string.IsNullOrEmpty(file.FileName))
                {
                    if (!string.IsNullOrEmpty(article.ImageSource))
                    {
                        ImageHelper.DeleteImage(article.ImageSource);
                    }

                    string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                    string filePath = Server.MapPath("~/Content/Images");

                    filePath = Path.Combine(filePath, fileName);
                    GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500);
                    article.ImageSource = fileName;
                }
                else
                {
                    article.ImageSource = article.ImageSource ?? "";
                }

                _repository.SaveSiteImage(article);
            }
            catch (Exception ex)
            {
                TempData["errorMessage"] = ex.Message;
                return View(model);
            }
            return RedirectToAction("Index");
        }
Example #4
0
 public void SaveSiteImage(SiteImage siteImage)
 {
     //var cache = _store.SiteImages.Single(c => c.Id == siteImage.Id);
     _store.SaveChanges();
 }
Example #5
0
 public int AddSiteImage(SiteImage siteImage)
 {
     _store.SiteImages.Add(siteImage);
     _store.SaveChanges();
     return siteImage.Id;
 }