コード例 #1
0
 public ActionResult UpdateFeedback(Feedback model)
 {
     using (var entities = new DB_WebgalleryEntities())
     {
         if (model != null)
         {
             model.Date = DateTime.Now;
             entities.Feedbacks.Add(model);
             entities.SaveChanges();
         }
         return(Json(model.Date.ToString()));
     }
 }
コード例 #2
0
        public ActionResult Edit(MainImage model, HttpPostedFileBase file)
        {
            string        FileExtension  = (file.FileName.Split('.')[1]).ToLower();
            List <string> KnowExtensions = new List <string>()
            {
                "jpg", "jpeg", "png", "tif"
            };

            if (!KnowExtensions.Any(x => x == FileExtension))
            {
                ModelState.AddModelError("file", "Invalid file format");
            }

            if (ModelState.IsValid)
            {
                string filePath = Server.MapPath("~/images/") + model.Customer.Name.ToLower().Replace(" ", "_") + "/" + model.CustomerId + "/sub/";

                if (!System.IO.Directory.Exists(filePath))
                {
                    System.IO.Directory.CreateDirectory(filePath);
                }

                file.SaveAs(filePath + file.FileName);

                SubImage image = new SubImage()
                {
                    MainImageId = model.Id,
                    Name        = model.Customer.Name.ToLower().Replace(" ", "_") + "/" + model.CustomerId + "/sub/" + file.FileName
                };

                using (var entities = new DB_WebgalleryEntities())
                {
                    entities.SubImages.Add(image);
                    entities.SaveChanges();
                }

                return(RedirectToAction("gallery"));
            }
            return(View(model));
        }
コード例 #3
0
        public ActionResult Contact(ContactModel model, HttpPostedFileBase file)
        {
            if (string.IsNullOrEmpty(model.Pack))
            {
                ModelState.AddModelError("Pack", "Pack is required.");
            }
            if (string.IsNullOrEmpty(model.Size))
            {
                ModelState.AddModelError("Size", "Size is required.");
            }
            if (file == null)
            {
                ModelState.AddModelError("file", "File is required.");
            }

            string        FileExtension  = (file.FileName.Split('.')[1]).ToLower();
            List <string> KnowExtensions = new List <string>()
            {
                "jpg", "jpeg", "png", "tif"
            };

            if (!KnowExtensions.Any(x => x == FileExtension))
            {
                ModelState.AddModelError("file", "Invalid file format");
            }

            if (ModelState.IsValid)
            {
                Customer customer = new Customer()
                {
                    Name    = model.Name,
                    Email   = model.Email,
                    Message = model.Message,
                    Phoneno = model.PhoneNo.ToString(),
                    Size    = model.Size,
                    Pack    = model.Pack,
                    Attach  = file.FileName
                };

                using (var entities = new DB_WebgalleryEntities())
                {
                    entities.Customers.Add(customer);
                    entities.SaveChanges();
                }

                string filePath = Server.MapPath("~/images/") + customer.Name.ToLower().Replace(" ", "_") + "/" + customer.Id + "/";

                if (!System.IO.Directory.Exists(filePath))
                {
                    System.IO.Directory.CreateDirectory(filePath);
                }

                file.SaveAs(filePath + file.FileName);

                MainImage mainImage = new MainImage()
                {
                    IsActive   = true,
                    Name       = customer.Name.ToLower().Replace(" ", "_") + "/" + customer.Id + "/" + file.FileName,
                    CustomerId = customer.Id
                };
                using (var entities = new DB_WebgalleryEntities())
                {
                    entities.MainImages.Add(mainImage);
                    entities.SaveChanges();
                }

                return(RedirectToAction("Index", "Home"));
            }
            return(View(model));
        }