public ActionResult Create(MatchViewModel collection) { try { if (ModelState.IsValid) { if (collection.AwayClubId.Value == collection.HomeClubId.Value) { ViewBag.EventsList = new SelectList(_dropDownService.GetEvents(), "id", "name", collection?.EventId ?? null); ModelState.AddModelError(string.Empty, "میزبان و مهمان بصورت یکسان انتخاب شده اند."); return(View(collection)); } if (_matchService.CheckExist(_mapper.Map <Match>(collection), null)) { ViewBag.EventsList = new SelectList(_dropDownService.GetEvents(), "id", "name", collection?.EventId ?? null); ModelState.AddModelError(string.Empty, "این مسابقه قبلا ثبت شده است."); return(View(collection)); } var model = _mapper.Map <Match>(collection); model.Priority = !model.Priority.HasValue ? 0 : model.Priority; model.PredictionWeight = (!model.PredictionWeight.HasValue || model.PredictionWeight.Value == 0) ? 1 : model.PredictionWeight; _matchService.InsertWithLog(model, AdminHelper.AdminId); if (!string.IsNullOrEmpty(collection.PreviousUrl)) { return(Redirect(collection.PreviousUrl)); } return(RedirectToAction("Index")); } ViewBag.EventsList = new SelectList(_dropDownService.GetEvents(), "id", "name", collection.EventId); ModelState.AddModelError(string.Empty, GeneralMessages.DefectiveEntry); } catch (Exception ex) { _logger.Error(ex); if (ex.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, GeneralMessages.Duplicated); } else { if (ex.InnerException != null && ex.InnerException.Source.Equals(GeneralMessages.ExceptionSource)) { ModelState.AddModelError(string.Empty, ex.Message); } else { ModelState.AddModelError(string.Empty, GeneralMessages.UnexpectedError); } } ViewBag.EventsList = new SelectList(_dropDownService.GetEvents(), "id", "name", collection.EventId); } return(View(collection)); }