public override Task <IViewProviderResult> BuildEditAsync(TagAdmin tag, IViewProviderContext updater) { EditTagViewModel editLabelViewModel = null; if (tag.Id == 0) { editLabelViewModel = new EditTagViewModel() { IsNewTag = true }; } else { editLabelViewModel = new EditTagViewModel() { Id = tag.Id, Name = tag.Name, Description = tag.Description }; } return(Task.FromResult(Views( View <EditTagViewModel>("Admin.Edit.Header", model => editLabelViewModel).Zone("header").Order(1), View <EditTagViewModel>("Admin.Edit.Content", model => editLabelViewModel).Zone("content").Order(1), View <EditTagViewModel>("Admin.Edit.Actions", model => editLabelViewModel).Zone("actions").Order(1), View <EditTagViewModel>("Admin.Edit.Footer", model => editLabelViewModel).Zone("footer").Order(1) ))); }
public ActionResult Save(string sourceType, string moduleKey, EditTagViewModel editTag) { var result = new DataJsonResult(); if (editTag.Id == Guid.Empty) { var tag = new Models.Tag { Id = KeyGenerator.GetGuidKey(), ModuleKey = moduleKey, SourceType = sourceType, Content = editTag.Content, CreateTime = DateTime.Now, Sort = editTag.Sort }; _currencyService.Create(tag); } else { var tag = _currencyService.GetSingleById <Models.Tag>(editTag.Id); tag.Content = editTag.Content; tag.Sort = editTag.Sort; _currencyService.Update(tag); } return(Json(result)); }
public async Task <IActionResult> CreatePost(EditTagViewModel viewModel) { var user = await _contextFacade.GetAuthenticatedUserAsync(); if (user == null) { return(Unauthorized()); } if (!ModelState.IsValid) { return(View(viewModel)); } // Create tag var tag = new Tag() { FeatureId = await GetFeatureIdAsync(), Name = viewModel.Name, Description = viewModel.Description, CreatedUserId = user.Id, CreatedDate = DateTimeOffset.UtcNow }; // Persist tag var result = await _tagManager.CreateAsync(tag); if (result.Succeeded) { // Indicate new tag so UpdateAsync does not execute within our view provider result.Response.IsNewTag = true; // Execute view providers await _viewProvider.ProvideUpdateAsync(result.Response, this); // Add confirmation _alerter.Success(T["Tag Added Successfully!"]); // Return return(RedirectToAction(nameof(Index))); } else { // Report any errors foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } return(View(viewModel)); }
public override async Task <IViewProviderResult> BuildUpdateAsync(TagAdmin tag, IViewProviderContext context) { if (tag == null) { throw new ArgumentNullException(nameof(tag)); } if (tag.IsNewTag) { return(await BuildEditAsync(tag, context)); } var model = new EditTagViewModel(); if (!await context.Updater.TryUpdateModelAsync(model)) { return(await BuildEditAsync(tag, context)); } model.Name = model.Name?.Trim(); model.Description = model.Description?.Trim(); if (context.Updater.ModelState.IsValid) { var user = await _contextFacade.GetAuthenticatedUserAsync(); if (user == null) { return(await BuildEditAsync(tag, context)); } // Update tag tag.Name = model.Name; tag.Description = model.Description; // Persist changes var result = await _tagManager.UpdateAsync((Tag)tag); foreach (var error in result.Errors) { context.Updater.ModelState.AddModelError(string.Empty, error.Description); } } return(await BuildEditAsync(tag, context)); }
public ActionResult Details(int Id) { Tag tag = _context.Tags.Where(x => x.Id == Id).FirstOrDefault(); if (tag == null) { return(RedirectToAction("Index", "Error")); } EditTagViewModel vm = new EditTagViewModel { Id = tag.Id, Name = tag.Name }; return(View(vm)); }
public async Task <ActionResult> Edit(EditTagViewModel vm) { if (ModelState.IsValid) { var api = CreateTrainingApi(); var tag = await api.GetTagAsync(ProjectId, vm.Id); tag.Name = vm.Name; tag.Description = vm.Description; await api.UpdateTagAsync(ProjectId, vm.Id, tag); TempData["Message"] = "Tag updated"; return(RedirectToAction("Index")); } return(View()); }
public ActionResult Details(EditTagViewModel vm) { if (!ModelState.IsValid) { return(View(vm)); } Tag tag = _context.Tags.Where(x => x.Id == vm.Id).FirstOrDefault(); if (tag == null) { return(RedirectToAction("Index", "Error")); } tag.Name = vm.Name; _context.SaveChanges(); return(RedirectToAction("Index", "Tags")); }
public async Task <ActionResult> Edit(Guid id) { var api = CreateTrainingApi(); var tag = await api.GetTagAsync(ProjectId, id); if (tag == null) { return(HttpNotFound()); } var vm = new EditTagViewModel { Id = id, Name = tag.Name, Description = tag.Description }; return(View(vm)); }
public void Update(Guid tagId, EditTagViewModel tag) { try { var result = FilmHausDbContext.Tags.Find(tagId); if (result == null) { throw new ArgumentNullException(); } result.Name = tag.Name; FilmHausDbContext.Entry(result).State = EntityState.Modified; FilmHausDbContext.SaveChanges(); } catch (InvalidOperationException ex) { throw ex; } }