public virtual async Task <ActionResult> Edit(int ID, TournamentModel viewModel, HttpPostedFileBase upload) { if (ModelState.IsValid) { if (!_tournament.IsExist(viewModel.Title, ID)) { 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) { 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); viewModel.Logo = fileName; } _tournament.Edit(ID, viewModel); await _uow.SaveChangesAsync(); } else { ViewBag.Message = "عنوان وارد شده در سیستم موجود است."; return(View()); } } return(View()); }