示例#1
0
        public ActionResult Details(int id)
        {
            var item = clubsRepo.GetById(id);

            var vm = new ClubDetailsForm();

            vm.InjectFrom(item);
            vm.SportCenterList = db.SportCenters.OrderBy(sc => sc.Id).ToList();
            vm.Culture         = getCulture();

            if (TempData["ViewData"] != null)
            {
                ViewData = (ViewDataDictionary)TempData["ViewData"];
            }

            return(PartialView("_Details", vm));
        }
示例#2
0
        public ActionResult Details(ClubDetailsForm frm)
        {
            var maxFileSize = GlobVars.MaxFileSize * 1000;
            var savePath    = Server.MapPath(GlobVars.ClubContentPath);
            var item        = clubsRepo.GetById(frm.ClubId);

            UpdateModel(item);

            var imageFile = GetPostedFile("ImageFile");

            if (imageFile != null)
            {
                if (imageFile.ContentLength > maxFileSize)
                {
                    ModelState.AddModelError("ImageFile", Messages.FileSizeError);
                }
                else
                {
                    var newName = SaveFile(imageFile, "img");
                    if (newName == null)
                    {
                        ModelState.AddModelError("ImageFile", Messages.FileError);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(item.PrimaryImage))
                        {
                            FileUtil.DeleteFile(savePath + item.PrimaryImage);
                        }

                        item.PrimaryImage = newName;
                    }
                }
            }

            var logoFile = GetPostedFile("LogoFile");

            if (logoFile != null)
            {
                if (logoFile.ContentLength > maxFileSize)
                {
                    ModelState.AddModelError("LogoFile", Messages.FileSizeError);
                }
                else
                {
                    var newName = SaveFile(logoFile, "logo");
                    if (newName == null)
                    {
                        ModelState.AddModelError("LogoFile", Messages.FileError);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(item.Logo))
                        {
                            FileUtil.DeleteFile(savePath + item.Logo);
                        }

                        item.Logo = newName;
                    }
                }
            }

            var indexFile = GetPostedFile("IndexFile");

            if (indexFile != null)
            {
                if (indexFile.ContentLength > maxFileSize)
                {
                    ModelState.AddModelError("IndexFile", Messages.FileSizeError);
                }
                else
                {
                    var newName = SaveFile(indexFile, "img");
                    if (newName == null)
                    {
                        ModelState.AddModelError("IndexFile", Messages.FileError);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(item.IndexImage))
                        {
                            FileUtil.DeleteFile(savePath + item.IndexImage);
                        }

                        item.IndexImage = newName;
                    }
                }
            }

            var docFile = GetPostedFile("DocFile");

            if (docFile != null)
            {
                if (docFile.ContentLength > maxFileSize)
                {
                    ModelState.AddModelError("DocFile", Messages.FileSizeError);
                }
                var isValid = SaveDocument(docFile, frm.ClubId);
                if (!isValid)
                {
                    ModelState.AddModelError("DocFile", Messages.FileError);
                }
            }

            if (ModelState.IsValid)
            {
                clubsRepo.Save();

                TempData["Saved"] = true;
            }
            else
            {
                TempData["ViewData"] = ViewData;
            }

            return(RedirectToAction("Details", new { id = item.ClubId }));
        }