public async Task <IActionResult> Delete(Guid id) { try { var result = await _service.Delete(id); result.Status = new StatusMessage { Type = StatusMessage.Success, Body = _localizer.Language["The language was successfully deleted"] }; return(Ok(result)); } catch (Exception e) { var result = new LanguageEditModel(); result.Status = new StatusMessage { Type = StatusMessage.Error, Body = e.Message }; return(BadRequest(result)); } }
/// <summary> /// Saves the given edit model and returns the updated data. /// </summary> /// <param name="model">The edit model</param> /// <returns>The updated data</returns> public async Task <LanguageEditModel> Save(LanguageEditModel model) { var current = await _api.Languages.GetAllAsync(); var removed = current .Where(c => !model.Items.Select(i => i.Id).Contains(c.Id)) .Select(c => c.Id); var defaultLanguage = model.Items.Single(i => i.IsDefault); // First let's save the default language if (defaultLanguage.Id == Guid.Empty) { defaultLanguage.Id = Guid.NewGuid(); } await _api.Languages.SaveAsync(defaultLanguage); // Now let's delete the removed languages foreach (var r in removed) { await _api.Languages.DeleteAsync(r); } // Let's save the rest of the languages foreach (var item in model.Items.Where(i => i.Id != defaultLanguage.Id)) { await _api.Languages.SaveAsync(item); } return(await Get()); }
public EditLanguage(LanguageEditModel model) { BindingContext = Model = model; Model.Navigation = Navigation; InitializeComponent(); Model.TrackChanges = true; }
public async Task Edit_POST_InvalidModel() { // arrange var model = new LanguageEditModel(); // act var result = await SystemUnderTest.Edit(model); // assert AssertInputErrorMessagesOfView(result, model); }
public static LanguageEditModel GetLanguageOneEditModel() { var model = new LanguageEditModel(); model.Name = "Language One"; model.OriginalName = "Language One Original Name"; model.IsoCode2 = IsoCode2One; model.IsoCode3 = IsoCode3One; return(model); }
public static LanguageEditModel MapLanguageEditModel(LanguageDto dto) { var model = new LanguageEditModel(); model.LanguageUid = dto.Uid; model.Name = dto.Name; model.OriginalName = dto.OriginalName; model.IsoCode2 = dto.IsoCode2; model.IsoCode3 = dto.IsoCode3; model.Description = dto.Description; model.SetInputModelValues(); return(model); }
public async Task <IActionResult> Add(LanguageEditModel model) { var entity = await Store.CreateAsync(new Language { CompileScript = model.CompileScript, FileExtension = model.FileExtension, AllowJudge = false, AllowSubmit = false, Id = model.ExternalId, Name = model.Name, TimeFactor = model.TimeFactor, }); await HttpContext.AuditAsync("added", entity.Id); return(RedirectToAction(nameof(Detail), new { langid = entity.Id })); }
public async Task <IActionResult> Add(LanguageEditModel model) { var entity = DbContext.Languages.Add(new Language { CompileScript = model.CompileScript, FileExtension = model.FileExtension, AllowJudge = false, AllowSubmit = false, ExternalId = model.ExternalId, Name = model.Name, TimeFactor = model.TimeFactor, }); await DbContext.SaveChangesAsync(); return(RedirectToAction(nameof(Detail), new { langid = entity.Entity.ExternalId })); }
public async Task <IActionResult> Edit(LanguageEditModel model) { if (model.IsNotValid()) { model.SetInputModelValues(); return(View(model)); } var path = Path.Combine("images", "flags", model.IsoCode2 + ".png"); var icon = model.Icon; if (icon != null) { if (icon.ContentType != "image/png") { model.ErrorMessages.Add("please_upload_png_file"); } if ((System.IO.File.Exists(path))) { System.IO.File.Delete(path); } var fileStream = new FileStream(Path.Combine(_environment.WebRootPath, path), FileMode.Create); icon.CopyTo(fileStream); fileStream.Close(); } var request = new LanguageEditRequest(CurrentUser.Id, model.LanguageUid, model.Name, model.OriginalName, model.IsoCode2, model.IsoCode3, path, model.Description); var response = await _languageService.EditLanguage(request); if (response.Status.IsNotSuccess) { model.MapMessages(response); model.SetInputModelValues(); return(View(model)); } CurrentUser.IsActionSucceed = true; return(Redirect("/Language/List/")); }
public async Task <IActionResult> Edit(string langid, LanguageEditModel model) { var lang = await Store.FindAsync(langid); if (lang == null) { return(NotFound()); } lang.CompileScript = model.CompileScript; lang.FileExtension = model.FileExtension; lang.TimeFactor = model.TimeFactor; lang.Name = model.Name; await Store.UpdateAsync(lang); await HttpContext.AuditAsync("updated", langid); return(RedirectToAction(nameof(Detail), new { langid })); }
public async Task <IActionResult> Edit(string langid, LanguageEditModel model) { var lang = await DbContext.Languages .Where(l => l.ExternalId == langid) .FirstOrDefaultAsync(); if (lang == null) { return(NotFound()); } lang.CompileScript = model.CompileScript; lang.FileExtension = model.FileExtension; lang.TimeFactor = model.TimeFactor; lang.Name = model.Name; DbContext.Languages.Update(lang); await DbContext.SaveChangesAsync(); return(RedirectToAction(nameof(Detail), new { langid })); }
public async Task <LanguageEditModel> Save(LanguageEditModel model) { return(await _service.Save(model)); }