public ActionResult DeleteInstitution(UpsertViewModel model) { if (!model.Id.HasValue) { return(new HttpNotFoundResult()); } var institution = institutionRepository.Find(model.Id.Value); if (institution == null) { return(new HttpNotFoundResult()); } if (institution.UserProfiles.Any()) { ModelState["File"].Errors.Clear(); ModelState.AddModelError("noetempty", $"There are {institution.UserProfiles.Count} users registered under this domain. Institution {institution.Name} cannot be deleted."); return(View("DeleteInstitution", model)); } institutionRepository.Delete(institution); institutionRepository.Save(); return(RedirectToAction("InstitutionDeleted")); }
public async Task <ActionResult> Edit(int themeId) { var theme = await _themeService.GetAsync(themeId); if (theme == null) { throw new ArgumentException($"Unable to Identify Theme: {themeId}"); } var model = new UpsertViewModel { ThemeId = themeId, ThemeName = theme.ThemeName, TextFontId = theme.TextFontId.Value, TitleFontId = theme.TitleFontId.Value, FontList = await _fontService.GetAsync(), LargeTitleFontSize = theme.TitleLargeFontSize, MediumTitleFontSize = theme.TitleMediumFontSize, SmallTitleFontSize = theme.TitleSmallFontSize, TinyTitleFontSize = theme.TitleTinyFontSize, TextStandardFontSize = theme.TextStandardFontSize, PageBackgroundColour = theme.PageBackgroundColour, MenuBackgroundColour = theme.MenuBackgroundColour, MenuTextColour = theme.MenuTextColour, IsDefault = theme.IsDefault }; return(PartialView("_Edit", model)); }
public ActionResult AddInstitution(UpsertViewModel model) { ModelState["File"].Errors.Clear(); if (institutionRepository.Exists(model.Name)) { ModelState.AddModelError("Name", $"There is already an institution with the name \"{model.Name}\"."); } if (institutionRepository.DomainExists(model.ShortName)) { ModelState.AddModelError("ShortName", $"There is already an institution with the domain \"{model.ShortName}\"."); } if (!ModelState.IsValid) { return(View(model)); } institutionRepository.InsertOrUpdate(model.ToInstitution()); institutionRepository.Save(); return(View("AddedInstitution", new InstitutionsAddedViewModel { AmountImported = 1 })); }
public ActionResult Create() { var model = new UpsertViewModel { FontList = _fontService.Get() }; return(PartialView("_Create", model)); }
public ActionResult BulkAddInstitution(UpsertViewModel model) { if (model.File == null) { return(View("AddInstitution", model)); } try { var data = _institutionImporter.Execute(model.File.InputStream); List <Institution> invalidRecords = new List <Institution>(), existingNames = new List <Institution>(), existingDomains = new List <Institution>(); var imported = 0; foreach (var institution in data) { if (string.IsNullOrWhiteSpace(institution.Name) || string.IsNullOrWhiteSpace(institution.ShortName)) { invalidRecords.Add(institution); continue; } if (institutionRepository.Exists(institution.Name)) { existingNames.Add(institution); continue; } if (institutionRepository.DomainExists(institution.ShortName)) { existingDomains.Add(institution); continue; } institutionRepository.InsertOrUpdate(institution); institutionRepository.Save(); imported++; } return(View("AddedInstitution", new InstitutionsAddedViewModel { AmountImported = imported, Invalid = invalidRecords, ExistingNames = existingNames, ExistingDomains = existingDomains })); } catch (ArgumentException invalidFileException) { ModelState.AddModelError("generalError", invalidFileException.Message); return(View("AddInstitution", model)); } }
public ActionResult EditInstitution(UpsertViewModel model) { if (string.IsNullOrWhiteSpace(model.Name) || string.IsNullOrWhiteSpace(model.ShortName)) { return(View(model)); } institutionRepository.InsertOrUpdate(model.ToInstitution()); institutionRepository.Save(); return(RedirectToAction("Index", "Institutions")); }
public async Task <ActionResult> Create() { var model = new UpsertViewModel { FontList = await _fontService.GetAsync(), PageBackgroundColour = "#000000", MenuBackgroundColour = "#000000", MenuTextColour = "#9d9d9d" }; return(PartialView("_Create", model)); }
public async Task <ActionResult> Create(UpsertViewModel model) { if (!ModelState.IsValid) { model.FontList = await _fontService.GetAsync(); return(PartialView("_Create", model)); } await _themeService.UpsertAsync(0, model.ThemeName, model.TitleFontId, model.TextFontId, model.LargeTitleFontSize, model.MediumTitleFontSize, model.SmallTitleFontSize, model.TinyTitleFontSize, model.TextStandardFontSize, model.PageBackgroundColour, model.MenuBackgroundColour, model.MenuTextColour); return(Content("Refresh")); }
public ActionResult Edit(UpsertViewModel model) { if (!ModelState.IsValid) { model.FontList = _fontService.Get(); return(PartialView("_Edit", model)); } _themeService.Upsert(model.ThemeId, model.ThemeName, model.TitleFontId, model.TextFontId, model.LargeTitleFontSize, model.MediumTitleFontSize, model.SmallTitleFontSize, model.TinyTitleFontSize, model.TextStandardFontSize, model.PageBackgroundColour, model.MenuBackgroundColour, model.MenuTextColour); return(Content("Refresh")); }
public ActionResult Edit(UpsertViewModel model) { if (!ModelState.IsValid) { model.FontList = _fontService.Get(); return(PartialView("_Edit", model)); } _themeService.Upsert(model.ThemeId, model.ThemeName, model.TitleFontId, model.TextFontId); return(Content("Refresh")); }
ActionResult FetchUpsertViewModel(int id) { var institution = institutionRepository.Find(id); if (institution == null) { return(new HttpNotFoundResult()); } var model = new UpsertViewModel { Id = id, Name = institution.Name, ShortName = institution.ShortName }; return(View(model)); }
public ActionResult Upsert(UpsertViewModel upsertViewModel) { Trace.WriteLine("POST /Accounts/Upsert"); string[] stringSeparators = new string[] { "----", "---", "--", "-" }; if (!IsCsvFile(upsertViewModel.UploadedCSVFile)) { //Error message return(View()); } // Verify that the user selected a file if (upsertViewModel.UploadedCSVFile != null && upsertViewModel.UploadedCSVFile.ContentLength > 0) { StreamReader csvReader = new StreamReader(upsertViewModel.UploadedCSVFile.InputStream); { string inputLine = ""; while ((inputLine = csvReader.ReadLine()) != null) { string[] values = inputLine.Split(stringSeparators, StringSplitOptions.None); string accountId = values[0]; var returnedAccount = db.Accounts.Find(accountId); // New account to be added if (returnedAccount == null) { Account newAccount = new Account(); newAccount.AccountId = values[0]; newAccount.Password = values[1]; newAccount.AccountType = upsertViewModel.NewAccountType; db.Accounts.Add(newAccount); } else { } db.SaveChanges(); } csvReader.Close(); } } return(View()); }
public ActionResult Edit(int themeId) { var theme = _themeService.Get(themeId); if (theme == null) { throw new ArgumentException(string.Format("Unable to Identify Theme: {0}", themeId)); } var model = new UpsertViewModel { ThemeId = themeId, ThemeName = theme.ThemeName, TextFontId = theme.TextFontId.Value, TitleFontId = theme.TitleFontId.Value, FontList = _fontService.Get(), IsDefault = theme.IsDefault }; return(PartialView("_Edit", model)); }