コード例 #1
0
        public ActionResult Create(TutorialInputViewModel model)
        {
            if (model != null && this.ModelState.IsValid)
            {
                var    currentUserId = this.UserProfile.Id;
                var    newArticle    = this.Mapper.Map <Tutorial>(model);
                var    imageUploader = new ImageUplouder();
                var    images        = new HashSet <Image>();
                string folderPath    = this.Server.MapPath(WebConstants.ImagesMainPathMap + currentUserId);

                if (model.Files != null && model.Files.Count() > 0)
                {
                    foreach (var file in model.Files)
                    {
                        if (file != null &&
                            (file.ContentType == WebConstants.ContentTypeJpg || file.ContentType == WebConstants.ContentTypePng) &&
                            file.ContentLength < WebConstants.MaxImageFileSize)
                        {
                            images.Add(imageUploader.UploadImage(file, folderPath, currentUserId));
                        }
                    }
                }

                newArticle.Type     = TutorialType.FPS;
                newArticle.AuthorId = currentUserId;
                newArticle.Images   = images;

                var result = this.tutorials.Create(newArticle);

                // TODO: Fix Redirect
                return(this.RedirectToAction("Details", "FPS", new { area = "", id = result }));
            }

            return(this.View(model));
        }
コード例 #2
0
        public ActionResult Edit(TutorialInputViewModel model)
        {
            if (model != null && this.ModelState.IsValid)
            {
                var    currentUserId  = this.UserProfile.Id;
                var    updatedArticle = this.Mapper.Map <Tutorial>(model);
                var    imageUploader  = new ImageUplouder();
                var    images         = new HashSet <Image>();
                string folderPath     = this.Server.MapPath(WebConstants.ImagesMainPathMap + currentUserId);

                if (model.Files != null && model.Files.Any())
                {
                    foreach (var file in model.Files)
                    {
                        if (file != null &&
                            (file.ContentType == WebConstants.ContentTypeJpg || file.ContentType == WebConstants.ContentTypePng) &&
                            file.ContentLength < WebConstants.MaxImageFileSize)
                        {
                            images.Add(imageUploader.UploadImage(file, folderPath, currentUserId));
                        }
                    }
                }

                images.ForEach(x => updatedArticle.Images.Add(x));

                this.tutorials.Update(model.Id, updatedArticle);

                // TODO: Fix Redirect
                return(this.RedirectToAction("Details", "FPS", new { area = "", id = model.Id }));
            }

            return(this.View(model));
        }