public async System.Threading.Tasks.Task <ActionResult> DevelopmentToolsEdit(ContestsDevelopmentToolsEditViewModel model) { if (ModelState.IsValid) { if (await _db.DevelopmentTools.AnyAsync(d => d.ContestId == model.ContestId && d.Name == model.Name)) { ModelState.AddModelError("", "Компилятор в данном контесте с таким именем уже существует"); } else { var developmentTool = new DevelopmentTool { ContestId = model.ContestId, Id = (Guid)model.DevelopmentToolId, Name = model.Name, CompileCommand = model.CompileCommand, CommandArgs = model.CommandArgs }; _db.Entry(developmentTool).State = EntityState.Modified; await _db.SaveChangesAsync(); return(RedirectToAction("Edit", new { id = model.ContestId })); } } return(View(model)); }
public async System.Threading.Tasks.Task <ActionResult> DevelopmentToolsEdit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var developmentTool = await _db.DevelopmentTools.FindAsync(id); if (developmentTool == null) { return(HttpNotFound()); } var contest = _db.Contests.Find(developmentTool.ContestId); if (contest == null) { return(HttpNotFound()); } if (contest.TeacherId != User.Identity.GetUserId() && !User.IsInRole("administrator") && !_db.ContestTeachers.Any(ct => ct.ContestId == contest.Id)) { TempData["Message"] = "Вы не имеете право редактировать компиляторы для этого контеста"; return(RedirectToAction("Edit", new { id = developmentTool.ContestId })); //ViewBag.ErrorMessage = "Вы не имеете право редактировать компиляторы для этого контеста"; //return View("Error"); } var model = new ContestsDevelopmentToolsEditViewModel { DevelopmentToolId = id, ContestId = developmentTool.ContestId, Name = developmentTool.Name, CompileCommand = developmentTool.CompileCommand, CommandArgs = developmentTool.CommandArgs }; return(View(model)); }