public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { ViewData["CategoryId"] = new SelectList(_context.Set <Data.Category>(), "CategoryId", "CategoryName"); CheckArticleContent(); return(Page()); } _context.Update(Article); _context.UpdateRange(ArticleParameters); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ArticleExists(Article.ArticleId)) { return(NotFound()); } else { throw; } } var user = await _userManager.GetUserAsync(User); logger.Info("{user} edited article {article} - carrying {id} on {date}", user.Email, Article.ArticleName, Article.ArticleId, DateTime.Now); return(RedirectToPage("../Articles")); }
public async Task <IActionResult> OnPostAsync(List <string> ParameterName, List <string> ParameterDescription, List <string> ParameterUnit, List <string> DelParams) { var user = await _userManager.GetUserAsync(User); if (!ModelState.IsValid) { return(Page()); } if (ParameterName.Count != ParameterDescription.Count || ParameterName.Count != ParameterUnit.Count) { InitParameter(ParameterName, ParameterDescription, ParameterUnit); return(Page()); } for (int i = 0; i < ParameterName.Count; i++) { if (ParameterName.ElementAt(i) == "" || ParameterDescription.ElementAt(i) == "" || ParameterUnit.ElementAt(i) == "") { InitParameter(ParameterName, ParameterDescription, ParameterUnit); return(Page()); } if (ParameterName.ElementAt(i) == null || ParameterDescription.ElementAt(i) == null || ParameterUnit.ElementAt(i) == null) { InitParameter(ParameterName, ParameterDescription, ParameterUnit); return(Page()); } } _context.Update(ParentParameter); logger.Info("{user} updated ParentParameter {ppName} carrying -id {ppId} on {date}", user.Email, ParentParameter.ParentParameterName, ParentParameter.ParentParameterId, DateTime.Now); _context.UpdateRange(Parameters); try { await _context.SaveChangesAsync(); if (DelParams.Count > 0) { foreach (var item in DelParams) { if (item != null || item != "") { var temp = _context.Parameter.Where(p => p.ParameterId == Convert.ToInt32(item)).Single(); logger.Info("{user} edit-removed parameter {pName} carrying - id {pid} on {date}", user.Email, temp.ParameterName, temp.ParameterId, DateTime.Now); _context.Parameter.Remove(temp); } } await _context.SaveChangesAsync(); } if (ParameterName.Count != 0) { var ppId = ParentParameter.ParentParameterId; for (int i = 0; i < ParameterName.Count; i++) { _context.Parameter.Add( new Data.Parameter { ParameterDescription = ParameterDescription.ElementAt(i), ParameterName = ParameterName.ElementAt(i), ParameterUnit = ParameterUnit.ElementAt(i), ParentParameterId = ppId } ); logger.Info("{user} edit-added Parameter {pName} under ParentParameter {ppname} carrying -id {id} on {date}", user.Email, ParameterName.ElementAt(i), ParentParameter.ParentParameterName, ppId, DateTime.Now); } await _context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { if (!ParentParameterExists(ParentParameter.ParentParameterId)) { return(NotFound()); } else { throw; } } return(RedirectToPage("../Parameters")); }