public async Task <IActionResult> Create([Bind("Name,Position,Category")] Member member) { ModelState.Remove("Category.Name"); if (ModelState.IsValid) { var memberExists = await context.Member.FirstOrDefaultAsync(m => m.Name == member.Name); if (memberExists != null) { return(ValidationProblem(detail: "Member name already exists.")); } member.Category = (memberService.IsJuniorEditor(member)) ? context.Category .First(c => c.Name == member.Category.Name) : null; context.Add(member); await context.SaveChangesAsync(); logger.Log($"{HttpContext.User.Identity.Name} created member `{member.Name}` with position {member.Position} " + $"(Category = {member.Category.Name}) "); return(RedirectToAction(nameof(Index))); } return(View(member)); }
public async Task <IActionResult> Create([Bind("Number,FallYear,SpringYear")] Volume volume) { if (ModelState.IsValid) { context.Add(volume); await context.SaveChangesAsync(); logger.Log($"{HttpContext.User.Identity.Name} created Volume {volume.Number}."); return(RedirectToAction(nameof(Index), "Home")); } return(View(volume)); }
public async Task <ActionResult> Create([Bind("Name,Position")] Member member) { if (ModelState.IsValid) { context.Add(member); await context.SaveChangesAsync(); logger.Log($"{HttpContext.User.Identity.Name} created writer `{member.Name}`"); return(RedirectToAction(nameof(Index))); } return(View(member)); }
public async Task <IActionResult> Create([Bind("Name,Tag")] Category category) { if (ModelState.IsValid) { context.Add(category); category.SetLanguage(Regex.IsMatch(category.Name, @"^[a-zA-Z.\-+\s]*$") ? OutlookConstants.Language.English : OutlookConstants.Language.Arabic); await context.SaveChangesAsync(); logger.Log($"{HttpContext.User.Identity.Name} created Category `{category.Name}` and ID `{category.Id}`."); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create(int?id, [Bind("Number,ArabicTheme,EnglishTheme")] Issue issue) { if (ModelState.IsValid) { if (id == null) { return(ValidationProblem(detail: "Volume Id cannot be null")); } issue.Volume = await context.Volume.FindAsync(id); context.Add(issue); await context.SaveChangesAsync(); var Volume = await context.Volume.FindAsync(id); logger.Log($"{HttpContext.User.Identity.Name} created Issue `{issue.Number}` in Volume {Volume.Number} "); return(RedirectToAction(nameof(Index), new { id = id })); } return(View(issue)); }
public async Task <IActionResult> Create([FromRoute] int?id, string NewWriter, IFormFile Picture, [Bind("Language,Category,Writer,Title,Subtitle,Text")] Article article) { ModelState.Remove("Category.Name"); ModelState.Remove("Writer.Name"); if (ModelState.IsValid) { if (id == null) { return(ValidationProblem(detail: "Issue Id cannot be null")); } article.Issue = await context.Issue.FindAsync(id); article.DateTime = DateTime.Now; // Assign value to the MemberID that refers to the writer of the article article.Category = context.Category .First(c => c.Name == article.Category.Name); articleService.SetArticleWriter(article, (article.Writer.Name == "+ NEW WRITER") ? NewWriter : article.Writer.Name); if (Picture != null) { await articleService.AddArticlePicture(article, Picture, env.WebRootPath); } context.Add(article); await context.SaveChangesAsync(); logger.Log($"{HttpContext.User.Identity.Name} created article of title `{article.Title}` and ID `{article.Id}`"); return(RedirectToAction(nameof(Index), new { id = id })); } return(View(article)); }