Exemplo n.º 1
0
        public ActionResult EditListImage(ListImageModel model)
        {
            try
            {
                var config = Ultilities.ConfigWeb;
                #region Save
                //Save image 1
                if (model.Image1.Image != null && model.Image1.Image.FileName != null)
                {
                    model.Image1.Image.SaveAs(HttpContext.Server.MapPath("~/images/" + model.Image1.Image.FileName));
                    config.Image1.ImageName = model.Image1.Image.FileName;
                    config.Image1.Alt = model.Image1.Alt;
                    config.Image1.Title = model.Image1.Title;
                }
                else
                {
                    config.Image1.Alt = model.Image1.Alt;
                    config.Image1.Title = model.Image1.Title;
                }
                //Save image 2
                if (model.Image2.Image != null && model.Image2.Image.FileName != null)
                {
                    model.Image2.Image.SaveAs(HttpContext.Server.MapPath("~/images/" + model.Image2.Image.FileName));
                    config.Image2.ImageName = model.Image2.Image.FileName;
                    config.Image2.Alt = model.Image2.Alt;
                    config.Image2.Title = model.Image2.Title;

                }
                else
                {
                    config.Image2.Alt = model.Image2.Alt;
                    config.Image2.Title = model.Image2.Title;

                }
                //Save image 3
                if (model.Image3.Image != null && model.Image3.Image.FileName != null)
                {
                    model.Image3.Image.SaveAs(HttpContext.Server.MapPath("~/images/" + model.Image3.Image.FileName));
                    config.Image3.ImageName = model.Image3.Image.FileName;
                    config.Image3.Alt = model.Image3.Alt;
                    config.Image3.Title = model.Image3.Title;

                }
                else
                {
                    config.Image3.Alt = model.Image3.Alt;
                    config.Image3.Title = model.Image3.Title;

                }
                //Save image 4
                if (model.Image4.Image != null && model.Image4.Image.FileName != null)
                {
                    model.Image4.Image.SaveAs(HttpContext.Server.MapPath("~/images/" + model.Image4.Image.FileName));
                    config.Image4.ImageName = model.Image4.Image.FileName;
                    config.Image4.Alt = model.Image4.Alt;
                    config.Image4.Title = model.Image4.Title;

                }
                else
                {
                    config.Image4.Alt = model.Image4.Alt;
                    config.Image4.Title = model.Image4.Title;

                }
                //Save image 5
                if (model.Image5.Image != null && model.Image5.Image.FileName != null)
                {
                    model.Image5.Image.SaveAs(HttpContext.Server.MapPath("~/images/" + model.Image5.Image.FileName));
                    config.Image5.ImageName = model.Image5.Image.FileName;
                    config.Image5.Alt = model.Image5.Alt;
                    config.Image5.Title = model.Image5.Title;

                }
                else
                {
                    config.Image5.Alt = model.Image5.Alt;
                    config.Image5.Title = model.Image5.Title;
                }
                //Save image 6
                if (model.Image6.Image != null && model.Image6.Image.FileName != null)
                {
                    model.Image6.Image.SaveAs(HttpContext.Server.MapPath("~/images/" + model.Image6.Image.FileName));
                    config.Image6.ImageName = model.Image6.Image.FileName;
                    config.Image6.Alt = model.Image6.Alt;
                    config.Image6.Title = model.Image6.Title;
                }
                else
                {
                    config.Image6.Alt = model.Image6.Alt;
                    config.Image6.Title = model.Image6.Title;
                }
                #endregion

                var xmlSerializer = new XmlSerializer(typeof (Config));
                using (var str = new StreamWriter(HttpContext.Server.MapPath("~/Config.xml")))
                {
                    xmlSerializer.Serialize(str, config);
                    str.Close();
                }
                ObjectCache cache = MemoryCache.Default;
                cache.Remove("Config");
                TempData["success"] = "Lưu thông tin thành công";
                return View(model);
            }
            catch (Exception exception)
            {
                ModelState.AddModelError("", exception.ToString());
                return View(model);
            }
        }
Exemplo n.º 2
0
        public ActionResult EditListImage()
        {
            var model = new ListImageModel()
                {
                    Image1 = new ImageModel()
                        {
                            Name = Ultilities.ConfigWeb.Image1.ImageName,
                            Alt = Ultilities.ConfigWeb.Image1.Alt,
                            Title = Ultilities.ConfigWeb.Image1.Title
                        },
                    Image2 = new ImageModel()
                        {
                            Name = Ultilities.ConfigWeb.Image2.ImageName,
                            Alt = Ultilities.ConfigWeb.Image2.Alt,
                            Title = Ultilities.ConfigWeb.Image2.Title
                        },

                    Image3 = new ImageModel()
                        {
                            Name = Ultilities.ConfigWeb.Image3.ImageName,
                            Alt = Ultilities.ConfigWeb.Image3.Alt,
                            Title = Ultilities.ConfigWeb.Image3.Title
                        },
                    Image4 = new ImageModel()
                        {
                            Name = Ultilities.ConfigWeb.Image4.ImageName,
                            Alt = Ultilities.ConfigWeb.Image4.Alt,
                            Title = Ultilities.ConfigWeb.Image4.Title
                        },
                    Image5 = new ImageModel()
                        {
                            Name = Ultilities.ConfigWeb.Image5.ImageName,
                            Alt = Ultilities.ConfigWeb.Image5.Alt,
                            Title = Ultilities.ConfigWeb.Image5.Title
                        },
                    Image6 = new ImageModel()
                        {
                            Name = Ultilities.ConfigWeb.Image6.ImageName,
                            Alt = Ultilities.ConfigWeb.Image6.Alt,
                            Title = Ultilities.ConfigWeb.Image6.Title
                        }
                };
            return View(model);
        }