public ActionResult Pricing() { using (var entities = new DB_WebgalleryEntities()) { return(View(entities.Feedbacks.OrderByDescending(x => x.Date).ToList())); } }
public ActionResult Gallery() { using (var entities = new DB_WebgalleryEntities()) { var model = entities.MainImages.Where(x => x.IsActive).ToList(); return(View(model)); } }
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())); } }
public ActionResult Index() { List <MainImageViewModel> images = new List <MainImageViewModel>(); using (var entities = new DB_WebgalleryEntities()) { images = entities.MainImages.Select(x => new MainImageViewModel() { Image = x, SubImageCount = x.SubImages.Count }).ToList(); } return(View(images)); }
public ActionResult Picture(int id) { if (id <= 0) { return(HttpNotFound()); } using (var entities = new DB_WebgalleryEntities()) { entities.Configuration.LazyLoadingEnabled = false; var model = entities.MainImages.Where(x => x.Id == id).FirstOrDefault(); entities.Entry(model).Collection(x => x.SubImages).Load(); return(View(model)); } }
public ActionResult Index(LoginModel model) { if (ModelState.IsValid) { using (var entities = new DB_WebgalleryEntities()) { if (entities.Admins.Any(x => x.UserName.Equals(model.Username, StringComparison.InvariantCultureIgnoreCase) && x.Password.Equals(model.Password))) { FormsAuthentication.SetAuthCookie(model.Username, false); return(RedirectToAction("gallery")); } else { ModelState.AddModelError("", "Username or password incorrect."); } } } return(View("Index", model)); }
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)); }
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)); }