public async Task <ActionResult> Add(AddSportViewModel sportModel)
        {
            var sport = new DomainClasses.Sport
            {
                Name = sportModel.SportName
            };

            if (sportModel.SportCategories != null && sportModel.SportCategories.Any())
            {
                foreach (var sportCategory in sportModel.SportCategories)
                {
                    sport.SportCategories.Add(new SportCategory()
                    {
                        Name = sportCategory.Name
                    });
                }
            }

            if (sportModel.SportDetails != null && sportModel.SportDetails.Any())
            {
                foreach (var sportDetail in sportModel.SportDetails)
                {
                    sport.SportDetails.Add(new SportDetail()
                    {
                        Name = sportDetail.Name
                    });
                }
            }

            _sportService.Add(sport);

            await _dbContext.SaveChangesAsync();

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
Пример #2
0
        public async Task <IActionResult> Create(SportsViewModel sport)
        {
            if (ModelState.IsValid)
            {
                var newSport = await _sportService.Add(sport);

                return(RedirectToAction("Sport", "Admin", new { @sportId = newSport.Id }));
            }
            return(View(sport));
        }
Пример #3
0
 public IActionResult Create(SportsTree sportsTree)
 {
     try
     {
         if (sportsTree == null)
         {
             _logger.LogError("Create request failed invalid data submited");
             return(BadRequest("Invalid object submited"));
         }
         else
         {
             _logger.LogInformation("Record successfully added");
             _sportService.Add(sportsTree);
             return(Ok("Record successfully added"));
         }
     }
     catch (Exception ex)
     {
         _logger.LogError("Create operation failed", ex);
         return(BadRequest($"There was an error while processing your request {ex}"));
     }
 }