public ViewResult AddorEditUniversity(int id = 0) { var model = new EditUniversity(); if (id > 0) { var university = _coreRepository.Get <Institution>(id); if (university != null) { model = new EditUniversity(university); } } return(View("AddorEditUniversity", model)); }
public ActionResult AddorEditUniversity(EditUniversity model) { if (ModelState.IsValid) { var university = _coreRepository.Get <Institution>(model.Id) ?? new Institution(); university.Name = model.Name; university.ShortName = model.ShortName; if (!string.IsNullOrWhiteSpace(model.Description)) { university.Description = _generalHelper.ConvertHtmlToPlainText(model.Description); } if (model.logoFile != null) { var fileName = model.logoFile.FileName; model.LogoPathName = fileName; //university.logoFile.SaveAs(ConfigurationManager.AppSettings["BaseResourcesFolder"] + fileName); string newFileName = null; string oldFileName = university.LogoPathName; if (!string.IsNullOrWhiteSpace(oldFileName)) { bool isFileDeleted = _generalHelper.DeleteFile(oldFileName, ConfigurationManager.AppSettings["BaseResourcesFolder"]); } if (_generalHelper.SaveFile(model.logoFile, ConfigurationManager.AppSettings["BaseResourcesFolder"], out newFileName, model.LogoPathName)) { model.LogoPathName = newFileName; } university.logoFile = model.logoFile; university.LogoPathName = model.LogoPathName; } if (model.Id == 0) { university.CreatedOn = DateTime.Now; } bool isSaved = _coreRepository.SaveOrUpdate(university); if (isSaved) { TempData[ApplicationConstants.SuccessNotification] = ApplicationConstants.SuccessSaveMessage; return(RedirectToAction("University")); } } //var errors = ModelState.Values.SelectMany(v => v.Errors); TempData[ApplicationConstants.ErrorNotification] = ApplicationConstants.ErrorSaveMessage; return(View(model)); }