public ActionResult Edit(Portfolio portfolio, HttpPostedFileBase mediaUrl, string fileName) { Portfolio entity = db.Portfolio.Find(portfolio.Id); if (entity == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ModelState.Remove("mediaUrl"); if (mediaUrl != null) { bool valid = true; if (!mediaUrl.CheckImageType()) { ModelState.AddModelError("mediaUrl", "Photo is not required!"); valid = false; } if (!mediaUrl.CheckImageSize(5)) { ModelState.AddModelError("mediaUrl", "Photo is not required!"); valid = false; } if (valid) { string newPath = mediaUrl.SaveImage(Server.MapPath("~/Uploads")); if (!string.IsNullOrWhiteSpace(entity.MediaUrl)) { Server.MoveFile("~/Uploads" , entity.MediaUrl , string.Format("archive/{0}-{1}", entity.Id, entity.MediaUrl)); } entity.MediaUrl = newPath; } } else if (!string.IsNullOrWhiteSpace(entity.MediaUrl) && string.IsNullOrWhiteSpace(fileName)) { entity.MediaUrl = null; } if (ModelState.IsValid) { entity.Name = portfolio.Name; entity.Category = portfolio.Category; entity.Link = portfolio.Link; db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(portfolio)); }
public ActionResult Create([Bind(Include = "Id,Name,Description,MediaUrl,LanguageId")] Services services, HttpPostedFileBase mediaUrl) { if (mediaUrl == null) { ModelState.AddModelError("mediaUrl", "Şəkil seçilməyib!"); } else { if (!mediaUrl.CheckImageType()) { ModelState.AddModelError("mediaUrl", "Şəkil uyğun deyil!"); } if (!mediaUrl.CheckImageSize(5)) { ModelState.AddModelError("mediaUrl", "Şəklin ölçüsü uyğun deyil!"); } } if (ModelState.IsValid) { services.MediaUrl = mediaUrl.SaveImage(Server.MapPath("~/media")); db.Services.Add(services); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.LanguageId = new SelectList(db.Language, "Id", "Name", services.LanguageId); return(View(services)); }
public ActionResult Create(News news, HttpPostedFileBase mediaUrl) { if (mediaUrl == null) { ModelState.AddModelError("mediaUrl", "Şəkil seçilməyib!"); } else { if (!mediaUrl.CheckImageType()) { ModelState.AddModelError("mediaUrl", "Şəkil uyğun deyil!"); } if (!mediaUrl.CheckImageSize(5)) { ModelState.AddModelError("mediaUrl", "Şəklin ölçüsü uyğun deyil!"); } } if (ModelState.IsValid) { news.MediaUrl = mediaUrl.SaveImage(Server.MapPath("~/Template/media")); db.News.Add(news); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Category, "Id", "Name", news.CategoryId); return(View(news)); }
public ActionResult Create(Portfolio portfolio, HttpPostedFileBase mediaUrl) { if (mediaUrl == null) { ModelState.AddModelError("mediaUrl", "Photo doesn't selected!"); } else { if (!mediaUrl.CheckImageType()) { ModelState.AddModelError("mediaUrl", "Photo is not required!"); } if (!mediaUrl.CheckImageSize(5)) { ModelState.AddModelError("mediaUrl", "Photo size is not required!"); } } if (!ModelState.IsValid) { throw new NullReferenceException(); } string newPath = mediaUrl.SaveImage(Server.MapPath("~/Uploads")); portfolio.MediaUrl = newPath; db.Portfolio.Add(portfolio); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "Id,Name,MediaUrl,Link")] Clients clients, HttpPostedFileBase mediaUrl) { if (mediaUrl == null) { ModelState.AddModelError("mediaUrl", "Şəkil seçilməyib!"); } else { if (!mediaUrl.CheckImageType()) { ModelState.AddModelError("mediaUrl", "Şəkil uyğun deyil!"); } if (!mediaUrl.CheckImageSize(5)) { ModelState.AddModelError("mediaUrl", "Şəklin ölçüsü uyğun deyil!"); } } if (ModelState.IsValid) { clients.MediaUrl = mediaUrl.SaveImage(Server.MapPath("~/media")); db.Clients.Add(clients); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(clients)); }
public ActionResult Edit([Bind(Include = "Id,Name,Description,MediaUrl,LanguageId")] Services services, HttpPostedFileBase mediaUrl, string fileName) { Services entity = db.Services.Find(services.Id); if (entity == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ModelState.Remove("mediaUrl"); if (mediaUrl != null) { bool valid = true; if (!mediaUrl.CheckImageType()) { ModelState.AddModelError("mediaUrl", "Şəkil uyğun deyil!"); valid = false; } if (!mediaUrl.CheckImageSize(5)) { ModelState.AddModelError("mediaUrl", "Şəklin ölçüsü uyğun deyil!"); valid = false; } if (valid) { string newPath = mediaUrl.SaveImage(Server.MapPath("~/media")); //System.IO.File.Move(Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl)), // Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl))); if (!string.IsNullOrWhiteSpace(entity.MediaUrl)) { services.MediaUrl = mediaUrl.SaveImage(Server.MapPath("~/media")); } entity.MediaUrl = newPath; } } else if (!string.IsNullOrWhiteSpace(entity.MediaUrl) && string.IsNullOrWhiteSpace(fileName)) { entity.MediaUrl = null; } if (ModelState.IsValid) { entity.LanguageId = services.LanguageId; entity.Name = services.Name; entity.Description = services.Description; db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.LanguageId = new SelectList(db.Language, "Id", "Name", services.LanguageId); return(View(services)); }
public ActionResult Edit([Bind(Include = "Id,Name,MediaUrl,Link")] Clients clients, HttpPostedFileBase mediaUrl, string fileName) { Clients entity = db.Clients.Find(clients.Id); if (entity == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ModelState.Remove("mediaUrl"); if (mediaUrl != null) { bool valid = true; if (!mediaUrl.CheckImageType()) { ModelState.AddModelError("mediaUrl", "Şəkil uyğun deyil!"); valid = false; } if (!mediaUrl.CheckImageSize(5)) { ModelState.AddModelError("mediaUrl", "Şəklin ölçüsü uyğun deyil!"); valid = false; } if (valid) { string newPath = mediaUrl.SaveImage(Server.MapPath("~/media")); //System.IO.File.Move(Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl)), // Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl))); if (!string.IsNullOrWhiteSpace(entity.MediaUrl)) { clients.MediaUrl = mediaUrl.SaveImage(Server.MapPath("~/media")); } entity.MediaUrl = newPath; } } else if (!string.IsNullOrWhiteSpace(entity.MediaUrl) && string.IsNullOrWhiteSpace(fileName)) { entity.MediaUrl = null; } if (ModelState.IsValid) { //entity.MediaUrl = mediaUrl.SaveImage(Server.MapPath("~/media")); entity.Name = clients.Name; entity.Link = clients.Link; db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(clients)); }
public ActionResult AddBackgrounds(AcademicBackground academic, HttpPostedFileBase mediaUrl) { if (academic == null) { throw new NullReferenceException(); } if (mediaUrl != null) { bool valid = true; if (!mediaUrl.CheckImageType()) { ModelState.AddModelError("mediaUrl", "Şəkil uyğun deyil!"); valid = false; } if (!mediaUrl.CheckImageSize(5)) { ModelState.AddModelError("mediaUrl", "Şəklin ölçüsü uyğun deyil!"); valid = false; } if (valid) { string newPath = mediaUrl.SaveImage(Server.MapPath("~/Template/media")); //System.IO.File.Move(Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl)), // Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl))); academic.mediaUrl = newPath; } } else if (string.IsNullOrWhiteSpace(academic.mediaUrl)) { academic.mediaUrl = null; } var person = db.PersonDetails.FirstOrDefault(); if (ModelState.IsValid) { academic.CreationDate = DateTime.UtcNow; db.AcademicBackground.Add(academic); db.SaveChanges(); } return(View("EditCV")); }
public ActionResult AddAcademicBack(AcademicBackground AcBack, HttpPostedFileBase Image, string fileName) { if (Image != null) { bool valid = true; if (!Image.CheckImageType()) { ModelState.AddModelError("mediaUrl", "Şəkil uyğun deyil!"); valid = false; } if (!Image.CheckImageSize(5)) { ModelState.AddModelError("mediaUrl", "Şəklin ölçüsü uyğun deyil!"); valid = false; } if (valid) { string newPath = Image.SaveImage(Server.MapPath("~/Template/Media/")); //System.IO.File.Move(Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl)), // Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl))); AcBack.Image = newPath; } } else if (!string.IsNullOrWhiteSpace(AcBack.Image) && !string.IsNullOrWhiteSpace(fileName)) { AcBack.Image = null; } if (ModelState.IsValid) { AcBack.CreatedDate = DateTime.Now; db.AAcademicBackgroundca.Add(AcBack); db.SaveChanges(); } return(RedirectToAction("EditCV")); }
public ActionResult AddExperiences(ProfessionalExperience experience, HttpPostedFileBase mediaUrl, string fileName) { if (experience == null) { throw new NullReferenceException(); } if (mediaUrl != null) { bool valid = true; if (!mediaUrl.CheckImageType()) { ModelState.AddModelError("mediaUrl", "Şəkil uyğun deyil!"); valid = false; } if (!mediaUrl.CheckImageSize(5)) { ModelState.AddModelError("mediaUrl", "Şəklin ölçüsü uyğun deyil!"); valid = false; } if (valid) { string newPath = mediaUrl.SaveImage(Server.MapPath("~/Template/media")); //System.IO.File.Move(Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl)), // Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl))); experience.MediaUrl = newPath; } } else if (string.IsNullOrWhiteSpace(experience.MediaUrl)) { experience.MediaUrl = null; } if (ModelState.IsValid) { experience.CreationDate = DateTime.UtcNow; db.ProfessionalExperiences.Add(experience); db.SaveChanges(); } return(View("EditCV")); }
public ActionResult CreateProduct(Product product, HttpPostedFileBase PhotoPath1, HttpPostedFileBase PhotoPath2, HttpPostedFileBase PhotoPath3, HttpPostedFileBase PhotoPath4, HttpPostedFileBase PhotoPath5) { if (PhotoPath1 == null) { ModelState.AddModelError("photo1", "Şəkil seçilməyib!"); } else { if (!PhotoPath1.CheckImageType()) { ModelState.AddModelError("PhotoPath1", "Şəkil uyğun deyil!"); } if (!PhotoPath1.CheckImageSize(5)) { ModelState.AddModelError("PhotoPath1", "Şəklin ölçüsü uyğun deyil!"); } } if (PhotoPath2 != null) { if (!PhotoPath2.CheckImageType()) { ModelState.AddModelError("PhotoPath2", "Şəkil uyğun deyil!"); } if (!PhotoPath2.CheckImageSize(5)) { ModelState.AddModelError("PhotoPath2", "Şəklin ölçüsü uyğun deyil!"); } } if (PhotoPath3 != null) { if (!PhotoPath3.CheckImageType()) { ModelState.AddModelError("PhotoPath3", "Şəkil uyğun deyil!"); } if (!PhotoPath3.CheckImageSize(5)) { ModelState.AddModelError("PhotoPath3", "Şəklin ölçüsü uyğun deyil!"); } } if (PhotoPath4 != null) { if (!PhotoPath4.CheckImageType()) { ModelState.AddModelError("PhotoPath4", "Şəkil uyğun deyil!"); } if (!PhotoPath4.CheckImageSize(5)) { ModelState.AddModelError("PhotoPath4", "Şəklin ölçüsü uyğun deyil!"); } } if (PhotoPath5 != null) { if (!PhotoPath5.CheckImageType()) { ModelState.AddModelError("PhotoPath5", "Şəkil uyğun deyil!"); } if (!PhotoPath5.CheckImageSize(5)) { ModelState.AddModelError("PhotoPath5", "Şəklin ölçüsü uyğun deyil!"); } } if (ModelState.IsValid) { product.PhotoPath1 = PhotoPath1.SaveImage(Server.MapPath("~/Areas/media")); if (PhotoPath2 != null) { product.PhotoPath2 = PhotoPath2.SaveImage(Server.MapPath("~/Areas/media")); } if (PhotoPath3 != null) { product.PhotoPath3 = PhotoPath3.SaveImage(Server.MapPath("~/Areas/media")); } if (PhotoPath4 != null) { product.PhotoPath4 = PhotoPath4.SaveImage(Server.MapPath("~/Areas/media")); } if (PhotoPath5 != null) { product.PhotoPath5 = PhotoPath5.SaveImage(Server.MapPath("~/Areas/media")); } db.Product.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }
public ActionResult Edit(News news, HttpPostedFileBase mediaUrl, string fileName) { News entity = db.News.Find(news.Id); if (entity == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ModelState.Remove("mediaUrl"); if (mediaUrl != null) { bool valid = true; if (!mediaUrl.CheckImageType()) { ModelState.AddModelError("mediaUrl", "Şəkil uyğun deyil!"); valid = false; } if (!mediaUrl.CheckImageSize(5)) { ModelState.AddModelError("mediaUrl", "Şəklin ölçüsü uyğun deyil!"); valid = false; } if (valid) { string newPath = mediaUrl.SaveImage(Server.MapPath("~/Template/media")); //System.IO.File.Move(Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl)), // Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl))); if (!string.IsNullOrWhiteSpace(entity.MediaUrl)) { Server.MoveFile("~/Template/media" , entity.MediaUrl , string.Format("archive/{0}-{1}", entity.Id, entity.MediaUrl)); } entity.MediaUrl = newPath; } } else if (!string.IsNullOrWhiteSpace(entity.MediaUrl) && string.IsNullOrWhiteSpace(fileName)) { entity.MediaUrl = null; } if (ModelState.IsValid) { entity.Title = news.Title; entity.Body = news.Body; entity.Author = news.Author; entity.IsPopular = news.IsPopular; entity.ModifiedDate = DateTime.UtcNow.AddHours(4); entity.CategoryId = news.CategoryId; db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Category, "Id", "Name", news.CategoryId); return(View(news)); }
public ActionResult AddExperience(ProfessionalExperience newExperiencee, HttpPostedFileBase imgPath, string fileName) { if (imgPath != null) { bool valid = true; if (!imgPath.CheckImageType()) { ModelState.AddModelError("mediaUrl", "Şəkil uyğun deyil!"); valid = false; } if (!imgPath.CheckImageSize(5)) { ModelState.AddModelError("mediaUrl", "Şəklin ölçüsü uyğun deyil!"); valid = false; } if (valid) { string newPath = imgPath.SaveImage(Server.MapPath("~/Template/Media/Experience")); //System.IO.File.Move(Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl)), // Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl))); newExperiencee.imgPath = newPath; } } else if (!string.IsNullOrWhiteSpace(newExperiencee.imgPath) && !string.IsNullOrWhiteSpace(fileName)) { newExperiencee.imgPath = null; } if ((newExperiencee.Location == null) || (newExperiencee.Duration == null) || (newExperiencee.JobTitle == null) || (newExperiencee.CompanyName == null) || (newExperiencee.Details == null)) { TempData["Fill all Inputs Experience"] = "Company's Name, Job Title, Location, Duration, and Details must be filled!! "; return(RedirectToAction("EditPage", "Edit")); } else { ProfessionalExperience newExperience = new ProfessionalExperience { Duration = newExperiencee.Duration, JobTitle = newExperiencee.JobTitle, CompanyName = newExperiencee.CompanyName, Location = newExperiencee.Location, Details = newExperiencee.Details, CreatedDate = DateTime.UtcNow, imgPath = newExperiencee.imgPath, }; db.ProfessionalExperience.Add(newExperiencee); db.SaveChanges(); return(RedirectToAction("EditPage", "Edit")); } }
public ActionResult AddAcademicBacground(AcademicBackground acBackground, HttpPostedFileBase imgPath, string filename) { if (imgPath != null) { bool valid = true; if (!imgPath.CheckImageType()) { ModelState.AddModelError("mediaUrl", "Şəkil uyğun deyil!"); valid = false; } if (!imgPath.CheckImageSize(5)) { ModelState.AddModelError("mediaUrl", "Şəklin ölçüsü uyğun deyil!"); valid = false; } if (valid) { string newPath = imgPath.SaveImage(Server.MapPath("~/Template/Media/AcademicBackground")); //System.IO.File.Move(Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl)), // Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl))); acBackground.imgPathAc = newPath; } } else if (!string.IsNullOrWhiteSpace(acBackground.imgPathAc) && !string.IsNullOrWhiteSpace(filename)) { acBackground.imgPathAc = null; } if ((acBackground.Qualification == null) || (acBackground.UniversityName == null) || (acBackground.YearOfObtention == null) || (acBackground.Degree == null)) { TempData["Fill all Inputs AcBack"] = "Qualification, University's Name, Year Of Obtention, and Degree must be filled!! "; return(RedirectToAction("EditPage", "Edit")); } else { AcademicBackground newAcademicBackground = new AcademicBackground { Qualification = acBackground.Qualification, Degree = acBackground.Degree, UniversityName = acBackground.UniversityName, YearOfObtention = acBackground.YearOfObtention, Details = acBackground.Details, CreatedDate = DateTime.Now, imgPathAc = acBackground.imgPathAc, }; db.AcademicBackground.Add(newAcademicBackground); db.SaveChanges(); return(RedirectToAction("EditPage", "Edit")); } }
public ActionResult saveChange(Person person, HttpPostedFileBase imgPath, string fileName) { Person entity = db.Person.FirstOrDefault(); if (entity == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (imgPath != null) { bool valid = true; if (!imgPath.CheckImageType()) { ModelState.AddModelError("mediaUrl", "Şəkil uyğun deyil!"); valid = false; } if (!imgPath.CheckImageSize(5)) { ModelState.AddModelError("mediaUrl", "Şəklin ölçüsü uyğun deyil!"); valid = false; } if (valid) { string newPath = imgPath.SaveImage(Server.MapPath("~/Template/Media/Profile")); //System.IO.File.Move(Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl)), // Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl))); entity.imgPath = newPath; } } else if (!string.IsNullOrWhiteSpace(entity.imgPath) && !string.IsNullOrWhiteSpace(fileName)) { entity.imgPath = null; } if ((person.FullName == null) || (person.Location == null) || (person.Experience == null) || (person.Degree == null) || (person.CareerLevel == null) || (person.Email == null) || (person.Fax == null)) { TempData["PersonInfomation"] = "Fill All inputs"; return(RedirectToAction("EditPage", "Edit")); } var lastPerson = db.Person.FirstOrDefault(); lastPerson.FullName = person.FullName; lastPerson.Age = person.Age; lastPerson.Location = person.Location; lastPerson.Experience = person.Experience; lastPerson.Degree = person.Degree; lastPerson.Phone = person.Phone; lastPerson.CareerLevel = person.CareerLevel; lastPerson.Email = person.Email; lastPerson.Fax = person.Fax; lastPerson.Website = person.Website; lastPerson.imgPath = entity.imgPath; db.Entry(lastPerson).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); if (Request.IsAjaxRequest()) { var person1 = db.Person.FirstOrDefault(); return(PartialView("~/Areas/Admin/Views/Shared/PartialViews/_personDetails.cshtml", person1)); } return(RedirectToAction("EditPage", "Edit")); }
public ActionResult addInfos(PersonDetails postPerson, HttpPostedFileBase mediaUrl, string fileName) { if (mediaUrl != null) { bool valid = true; if (!mediaUrl.CheckImageType()) { ModelState.AddModelError("mediaUrl", "Şəkil uyğun deyil!"); valid = false; } if (!mediaUrl.CheckImageSize(5)) { ModelState.AddModelError("mediaUrl", "Şəklin ölçüsü uyğun deyil!"); valid = false; } if (valid) { string newPath = mediaUrl.SaveImage(Server.MapPath("~/Template/media")); //System.IO.File.Move(Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl)), // Server.MapPath(System.IO.Path.Combine("~/Template/media", entity.MediaUrl))); postPerson.MediaUrl = newPath; } } else if (string.IsNullOrWhiteSpace(postPerson.MediaUrl)) { postPerson.MediaUrl = null; } var personExists = db.PersonDetails.Any(); var person = db.PersonDetails.FirstOrDefault(); if (personExists) { if (ModelState.IsValid) { person.Age = postPerson.Age; person.CareerLevel = postPerson.CareerLevel; person.Degree = postPerson.Degree; person.Email = postPerson.Email; person.Experience = postPerson.Experience; person.Fax = postPerson.Fax; person.Location = postPerson.Location; person.MediaUrl = postPerson.MediaUrl; person.Name = postPerson.Name; person.Phone = postPerson.Phone; person.Website = postPerson.Website; person.ModifiedDate = DateTime.UtcNow; person.MediaUrl = postPerson.MediaUrl; db.SaveChanges(); return(PartialView("EditCV")); } } if (ModelState.IsValid) { postPerson.MediaUrl = mediaUrl.SaveImage(Server.MapPath("~/Template/media")); postPerson.CreationDate = DateTime.UtcNow; db.PersonDetails.Add(postPerson); db.SaveChanges(); } return(View("EditCV")); }