public ActionResult <Competition> AddCompetition(Competition competiton) { Competition obj; if (competiton.IdCompetition != 0) { obj = competitionService.Update(competiton); if (obj == null) { return(NoContent()); } } else { obj = competitionService.Add(competiton); } return(Ok(obj)); }
public async Task <ActionResult> Add(CompetitionViewModel competitionModel) { if (!string.IsNullOrEmpty(competitionModel.LogoImage)) { var tmpPath = Server.MapPath("~/App_Data/tmp/"); var logoImagePath = Server.MapPath("~/App_Data/Logo_Image/"); await CopyFileAsync(tmpPath + competitionModel.LogoImage, logoImagePath + competitionModel.LogoImage); } if (competitionModel.IsRegisterActive && competitionModel.IsPrintCardActive == false) { competitionModel.PrintCardStartDate = competitionModel.RegisterEndDate.Value.AddDays(3); } var competition = new DomainClasses.Competition { Name = competitionModel.Name, ReadyStartDate = competitionModel.ReadyStartDate, ReadyEndDate = competitionModel.ReadyEndDate, RegisterStartDate = competitionModel.RegisterStartDate, RegisterEndDate = competitionModel.RegisterEndDate, IsReadyActive = competitionModel.IsReadyActive, IsRegisterActive = competitionModel.IsRegisterActive, IsPrintCardActive = competitionModel.IsPrintCardActive, LogoImage = competitionModel.LogoImage, PrintCardEndDate = competitionModel.PrintCardEndDate, PrintCardStartDate = competitionModel.PrintCardStartDate, Rule = competitionModel.Rule.ToSafeHtml(), MaxCommonTechnicalStaffs = competitionModel.MaxCommonTechnicalStaffs }; _competitionService.Add(competition); await _dbContext.SaveChangesAsync(); return(Json(new { id = competition.Id })); }