예제 #1
0
        public virtual async Task <ActionResult> Edit(int ID, ParticipantModel viewModel, HttpPostedFileBase upload)
        {
            ViewBag.SportType = SPList();
            if (ModelState.IsValid)
            {
                if (!_participant.IsExist(viewModel.Name, ID, viewModel.ParticipantTypeID, viewModel.CountryID))
                {
                    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/Participant";
                        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;
                    }

                    _participant.Edit(ID, viewModel);
                    await _uow.SaveChangesAsync();
                }
                else
                {
                    ViewBag.Message = "عنوان وارد شده در سیستم موجود است.";
                    return(View());
                }
            }
            return(View());
        }