Exemplo n.º 1
0
        public virtual ActionResult AddorUpdate(Settings settings, HttpPostedFileBase fileLogo)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    ModelState.AddModelError("", "ورودی نامعتبر");
                    return(View(MVC.Admin.Settings.Views.Index, settings));
                }
                using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    var path = Server.MapPath("~\\Content\\Images\\Logo\\");
                    // ذخیره لوگو
                    if (fileLogo != null)
                    {
                        if (Useful.CreateFolderIfNeeded(Server.MapPath("~/Content/Images/Logo")))
                        {
                            // اگر قبلا فایل وجود دارد حذف شود
                            if (System.IO.File.Exists(path + settings.University.Logo))
                            {
                                System.IO.File.Delete(path + settings.University.Logo);
                            }

                            if (settings.University.Logo == null)
                            {
                                path += Guid.NewGuid() + Path.GetExtension(fileLogo.FileName);
                            }
                            else
                            {
                                path += settings.University.Logo;
                            }

                            fileLogo.SaveAs(path);
                            settings.University.Logo = Path.GetFileName(path);
                        }
                    }

                    UpgradeWebconfig(settings.SmtpFrom, settings.SmtpHost, settings.SmtpUserName, settings.SmtpPass, Convert.ToInt32(settings.SmtpPort));
                    var data = _settingService.AddOrUpdateSettings(settings);
                    scope.Complete();

                    var ordinal    = EnumerationService.GetEnumValues <Ordinal>();
                    var genderList = new SelectList(ordinal, "Value", "Text");
                    TempData["Ordinal"] = genderList;

                    return(RedirectToAction(MVC.Admin.Settings.Index()));
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", " خطا در ثبت تنظیمات عمومی");
                return(View(MVC.Admin.Settings.Views.Index, settings));
            }
        }