public IActionResult Post([FromBody] Tournament tournament) { try { if (tournament == null) { return(StatusCode(400, StatusCodes.ReturnStatusObject("No items have been provided."))); } var result = _tournamentRepository.Add(tournament); if (result) { _logger.LogInformation("Tournament Successfully Added"); return(StatusCode(200, StatusCodes.ReturnStatusObject("Successfully Added."))); } else { _logger.LogError("Tournament has Failed to Add. Tournament - {0}", tournament); return(StatusCode(400, StatusCodes.ReturnStatusObject("Tournament failed to add."))); } } catch (Exception e) { _logger.LogError("Error Tournament failed to add . Error - {0} , Data - {1}", e.Message, tournament); return(StatusCode(400, StatusCodes.ReturnStatusObject("Error Tournament Failed to Add."))); } }
public virtual async Task <ActionResult> Create(TournamentModel viewModel, HttpPostedFileBase upload) { if (ModelState.IsValid) { if (!_tournament.IsExist(viewModel.Title)) { var validImageTypes = new string[] { "image/gif", "image/jpeg", "image/jpg", "image/png" }; var httpPostedFileBases = upload as HttpPostedFileBase; if (upload != null && !validImageTypes.Contains(upload.ContentType)) { ModelState.AddModelError("", " پسوند تصویر انتخاب شده غیر مجاز است"); return(View()); } if (upload == null) { ModelState.AddModelError("", " بارگزاری تصویر اجباری است"); return(View()); } const string uploadDir = "~/Uploads/Tournament"; string fileName = DateTime.Now.Year + "" + DateTime.Now.Month + "" + DateTime.Now.Day + "" + DateTime.Now.Hour + "" + DateTime.Now.Minute + "" + DateTime.Now.Second + "" + Path.GetExtension(upload.FileName); var imagePath = Path.Combine(Server.MapPath(uploadDir), fileName); upload.SaveAs(imagePath); var tournam = new TournamentModel { Title = viewModel.Title, Logo = fileName, }; _tournament.Add(tournam); await _uow.SaveChangesAsync(); ViewBag.Status = true; return(View()); } else { ViewBag.Message = "عنوان وارد شده تکراری است."; return(View()); } } else { return(View()); } }
public int Post([FromBody] Tournament tournament) { return(_tournament.Add(tournament)); }