Example #1
0
        public ActionResult EditGallery(GalleryModel model)
        {
            CommonDataService cds = new CommonDataService();

            CommonModel cm = new CommonModel();

            cm = cds.GenerateCommonModel();
            Session["FaceBook"] = cm.FaceBook;
            Session["Twitter"] = cm.Twitter;
            Session["Youtube"] = cm.Youtube;
            Session["Instagram"] = cm.Instagram;
            Session["PhoneNumber"] = cm.PhoneNumber;
            Session["Email"] = cm.Email;
            Session["ShoppingHours"] = cm.ShoppingHours;
            GalleryDataService dataservice = new GalleryDataService();
            string galleryId = (string)Request.Form["edit_GalleryId"];
            string imageString = (string)Request.Form["edit_ImageString"];
            string galleryTitle = (string)Request.Form["edit_GalleryTitle"];
            string galleryDescription = (string)Request.Form["edit_GalleryDescription"];
            try
            {
                if (ModelState.IsValid)
                {
                    WebImage photo = null;
                    var newFileName = "";
                    var imagePath = "";

                    photo = WebImage.GetImageFromRequest();
                    if (photo != null)
                    {
                        newFileName = Guid.NewGuid().ToString() + "_" +
                            Path.GetFileName(photo.FileName);
                        imagePath = @"Contents\Images\Gallery\" + newFileName;

                        photo.Save(@"~\" + imagePath);
                        model.GalleryId = int.Parse(galleryId);
                        model.ImageString = imagePath;

                    }
                    else
                    {
                        model.GalleryId = int.Parse(galleryId);
                        model.ImageString = imageString;
                    }

                    dataservice.UpdateGallery(model);
                    return RedirectToAction("Edit", "Gallery");
                }
                else
                {
                    model.GalleryId = int.Parse(galleryId);
                    model.ImageString = imageString;
                    return View(model);
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {
                model = null;
                dataservice = null;
            }
        }