Exemplo n.º 1
0
        public ActionResult Create(HttpPostedFileBase LeftFixedBkgrFile, HttpPostedFileBase RightFixedBkgrFile, HolidayModel holiday)
        {
            if (LeftFixedBkgrFile != null && LeftFixedBkgrFile.ContentLength > 0)
            {
                string fileName = Convert.ToInt32((DateTime.Now - new DateTime(2010, 01, 01)).TotalSeconds) + "_" + LeftFixedBkgrFile.FileName;
                string currentDomain = System.Configuration.ConfigurationManager.AppSettings["CurrentDomain"];
                string folder = "UploadedImages/backgroundimage";
                string filePath = System.Configuration.ConfigurationManager.AppSettings[currentDomain] + @"\" + folder + @"\" + fileName;

                using (new Impersonator("uploaduser", "", "Upload@@123"))
                {
                    LeftFixedBkgrFile.SaveAs(filePath);
                }
                holiday.LeftFixedBkgr = currentDomain + "/" + folder + "/" + fileName;
            }
            else
            {
                holiday.LeftFixedBkgr = "/Images/default-avatar.png";
            }

            if (RightFixedBkgrFile != null && RightFixedBkgrFile.ContentLength > 0)
            {
                string fileName = Convert.ToInt32((DateTime.Now - new DateTime(2010, 01, 01)).TotalSeconds) + "_" + RightFixedBkgrFile.FileName;
                string currentDomain = System.Configuration.ConfigurationManager.AppSettings["CurrentDomain"];
                string folder = "UploadedImages/backgroundimage";
                string filePath = System.Configuration.ConfigurationManager.AppSettings[currentDomain] + @"\" + folder + @"\" + fileName;

                using (new Impersonator("uploaduser", "", "Upload@@123"))
                {
                    RightFixedBkgrFile.SaveAs(filePath);
                }
                holiday.RightFixedBkgr = currentDomain + "/" + folder + "/" + fileName;
            }
            else
            {
                holiday.RightFixedBkgr = "/Images/default-avatar.png";
            }

            ModelState.Clear();
            TryValidateModel(holiday);

            if (ModelState.IsValid)
            {
                var holidayEn = AutoMapper.Mapper.Map<HolidayModel, Holiday>(holiday);
                _holidayRepository.InsertOrUpdate(holidayEn);
                _holidayRepository.Save();
                return RedirectToAction("Management");
            }
            return View(holiday);
        }