public IActionResult Edit([FromForm] ContestViewModel contest) { var contestToEdit = _contestRepository.GetItem(contest.ContestId); if (contestToEdit == null) { return(BadRequest("Nothing to edit")); } contestToEdit.Title = contest.Title; contestToEdit.Content = contest.Content; contestToEdit.StartDate = contest.StartDate; contestToEdit.EndDate = contest.EndDate; _contestRepository.Update(contestToEdit); _contestRepository.Save(); return(RedirectToAction(nameof(Index))); }
public async Task <ContestResponseModel> SaveContest(ContestUpdateModel contestResponse) { var user = await _userContext.GetUser() ?? throw new Exception("User not found"); int institutionId = contestResponse.InstitutionId == 0 && user.InstitutionId.HasValue ? user.InstitutionId.Value : contestResponse.InstitutionId; Contest contestEntity = _mapper.Map <Contest>(contestResponse); contestEntity.InstitutionId = institutionId; await _repository.Save(contestEntity); await _contestCategoryMappingsRepository.SaveCategoryMappings(contestEntity.Id, contestResponse.ContestCategories); await _contestRingsRepository.SaveCategoryRings(contestEntity.Id, contestResponse.Rings); return(_mapper.Map <ContestResponseModel>(contestEntity)); }
public Contest Add(Contest contest) { contest.Validate(); return(_contestRepository.Save(contest)); }