Пример #1
0
        public ActionResult Edit(CMSNewsViewModel model, HttpPostedFileBase uploadFile)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (uploadFile != null && uploadFile.ContentLength > 0)
                    {
                        var imageId = UploadImage(_imageService, uploadFile);
                        model.CoverImageId = imageId;
                    }

                    _cmsNewsService.EditCMSNews(model);

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }

            ViewBag.AvailableCategories = PrepareAllCategoriesModel(model.Id);
            PopulateStatusDropDownList((Define.Status)model.Status);
            return(View(model));
        }
Пример #2
0
        public ActionResult Edit(CMSNewsView model, HttpPostedFileBase uploadFile)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (uploadFile != null && uploadFile.ContentLength > 0)
                    {
                        ImageUpload imageUpload = new ImageUpload {
                            IsScale = false, SavePath = ImageUpload.LoadPathCMSNews
                        };
                        ImageResult imageResult = imageUpload.RenameUploadFile(uploadFile);

                        if (imageResult.Success)
                        {
                            // Add new image to database
                            var photo = new share_Images
                            {
                                ImageName = imageResult.ImageName,
                                ImagePath = imageResult.ImagePath
                            };
                            var imageId = _productService.AddImage(photo);
                            if (imageId != null)
                            {
                                // Add banner
                                model.CoverImageId = imageId.Value;
                            }
                        }
                        else
                        {
                            ViewBag.Error = imageResult.ErrorMessage;
                        }
                    }

                    _cmsNewsService.EditCMSNews(model);

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }

            ViewBag.AvailableCategories = PrepareAllCategoriesModel(model.Id);
            PopulateStatusDropDownList((OnlineStore.Infractructure.Utility.Define.Status)model.Status);
            return(View(model));
        }