public ActionResult UpravljanjeSlikomProfila(UploadImagesModels uploadImagesModels) { string idKorisnika = User.Identity.GetUserId(); if (uploadImagesModels.ImageFile[0] == null) { TempData["shortMessage"] = "Niste odabrali niti jednu sliku..."; return(RedirectToAction("Profil", new { id = idKorisnika })); } else { Random rnd = new Random(); int brojGreski = 0; foreach (HttpPostedFileBase file in uploadImagesModels.ImageFile) { string extension = Path.GetExtension(file.FileName); System.Drawing.Image image = System.Drawing.Image.FromStream(file.InputStream, true, true); int width = image.Width; int height = image.Height; if ((extension == ".png" || extension == ".jpg" || extension == ".bmp" || extension == ".jpeg") && width >= 1080 && width <= 2160 && height >= 800 && height <= 1440) { // } else { brojGreski++; } } if (brojGreski > 0) { TempData["shortMessage"] = "Dopuštene su samo slike .png, .jpg ili .bmp formata i moraju biti minimalno 1080x800 te maksimalno 2160x1440 piksela..."; return(RedirectToAction("Profil", new { id = idKorisnika })); } else { foreach (HttpPostedFileBase file in uploadImagesModels.ImageFile) { string folderPath = "~/Images/"; string fileName = Path.GetFileNameWithoutExtension(file.FileName); string extension = Path.GetExtension(file.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; korisnik korisnik = db.korisnik.Find(User.Identity.GetUserId()); string putanjaSlike = Server.MapPath(korisnik.putanjaDoProfilneSlike); if (System.IO.File.Exists(putanjaSlike)) { System.IO.File.Delete(putanjaSlike); } korisnik.putanjaDoProfilneSlike = folderPath + fileName; fileName = Path.Combine(Server.MapPath("~/Images/"), fileName); file.SaveAs(fileName); db.SaveChanges(); } TempData["shortMessage"] = "Slika uspješno uploadana..."; return(RedirectToAction("Profil", new { id = idKorisnika })); } } }
// GET: Korisnik/Edit/5 public ActionResult Edit(string id) { IEnumerable <string> listaGradova = GetAllTowns(); IEnumerable <string> listaŽupanije = GetAllŽupanije(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } korisnik modelKorisnika = db.korisnik.Find(id); modelKorisnika.Gradovi = GetSelectListItems(listaGradova); modelKorisnika.Županije = GetSelectListItems(listaŽupanije); if (modelKorisnika == null) { return(HttpNotFound()); } if (id != User.Identity.GetUserId()) { return(View("NeovlašteniPristup")); } UploadImagesModels uploadSlika = new UploadImagesModels(); Tuple <korisnik, UploadImagesModels> tuple = Tuple.Create(modelKorisnika, uploadSlika); if (TempData["shortMessage"] != null) { ViewBag.Message = TempData["shortMessage"].ToString(); TempData.Remove("shortMessage"); } return(View(tuple)); }
public ActionResult UpravljanjeSlikama(string idPoduzeća) { if (idPoduzeća == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IEnumerable <images> images = from c in db.images where c.imageIdByPoduzeće.Equals(idPoduzeća) select c; if (idPoduzeća != User.Identity.GetUserId()) { return(View("NeovlašteniPristup")); } UploadImagesModels uploadSlika = new UploadImagesModels(); Tuple <IEnumerable <images>, UploadImagesModels> tuple = Tuple.Create(images, uploadSlika); if (TempData["shortMessage"] != null) { ViewBag.Message = TempData["shortMessage"].ToString(); TempData.Remove("shortMessage"); } return(View(tuple)); }
// GET: Korisnik/Edit/5 public ActionResult EditKorisnik(string id) { IEnumerable <string> listaGradova = GetAllTowns(); IEnumerable <string> listaŽupanije = GetAllŽupanije(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } korisnik modelKorisnika = db.korisnik.Find(id); modelKorisnika.Gradovi = GetSelectListItems(listaGradova); modelKorisnika.Županije = GetSelectListItems(listaŽupanije); if (modelKorisnika == null) { return(HttpNotFound()); } UploadImagesModels uploadSlika = new UploadImagesModels(); uploadSlika.idKorisnika = modelKorisnika.idKorisnik; Tuple <korisnik, UploadImagesModels> tuple = Tuple.Create(modelKorisnika, uploadSlika); if (TempData["shortMessage"] != null) { ViewBag.Message = TempData["shortMessage"].ToString(); TempData.Remove("shortMessage"); } return(View("~/Views/Admin/Korisnik/EditKorisnik.cshtml", tuple)); }
public ActionResult UpravljanjeSlikama(UploadImagesModels uploadImagesModels) { if (uploadImagesModels.ImageFile[0] == null) { TempData["shortMessage"] = "Niste odabrali niti jednu sliku..."; return(RedirectToAction("UpravljanjeSlikama", new { idPoduzeća = User.Identity.GetUserId() })); } else { Random rnd = new Random(); int brojGreski = 0; foreach (HttpPostedFileBase file in uploadImagesModels.ImageFile) { string extension = Path.GetExtension(file.FileName); System.Drawing.Image image = System.Drawing.Image.FromStream(file.InputStream, true, true); int width = image.Width; int height = image.Height; if ((extension == ".png" || extension == ".jpg" || extension == ".bmp" || extension == ".jpeg") && width >= 1080 && width <= 2160 && height >= 800 && height <= 1440) { // } else { brojGreski++; } } if (brojGreski > 0) { TempData["shortMessage"] = "Dopuštene su samo slike .png, .jpg ili .bmp formata i moraju biti minimalno 1080x800 te maksimalno 2160x1440 piksela..."; return(RedirectToAction("UpravljanjeSlikama", new { idPoduzeća = User.Identity.GetUserId() })); } else { foreach (HttpPostedFileBase file in uploadImagesModels.ImageFile) { string folderPath = "~/Images/"; string fileName = Path.GetFileNameWithoutExtension(file.FileName); string extension = Path.GetExtension(file.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; images images = new images { imagePathOnDisk = folderPath + fileName, imageId = DateTime.Now.ToString("yymmssfff") + rnd.Next(1, 100000000).ToString(), imageIdByPoduzeće = User.Identity.GetUserId() }; fileName = Path.Combine(Server.MapPath("~/Images/"), fileName); file.SaveAs(fileName); db.images.Add(images); db.SaveChanges(); } TempData["shortMessage"] = "Slike uspješno uploadane."; return(RedirectToAction("UpravljanjeSlikama", new { idPoduzeća = User.Identity.GetUserId() })); } } }
//korisnički profil koji vidi svaki korisnik public ActionResult Profil() { korisnik korisnik = db.korisnik.Find(User.Identity.GetUserId()); UploadImagesModels uploadSlika = new UploadImagesModels(); Tuple <korisnik, UploadImagesModels> tuple = Tuple.Create(korisnik, uploadSlika); if (TempData["shortMessage"] != null) { ViewBag.Message = TempData["shortMessage"].ToString(); TempData.Remove("shortMessage"); } return(View(tuple)); }
//profil poduzeća public ActionResult Profil() { poduzeće poduzeće = db.poduzeće.Find(User.Identity.GetUserId()); UploadImagesModels uploadSlika = new UploadImagesModels(); IEnumerable <slika> modelSlika = from c in db.slika where c.idPoduzeća.Equals(poduzeće.idPoduzeće) select c; Tuple <IEnumerable <slika>, poduzeće, UploadImagesModels> tuple = Tuple.Create(modelSlika, poduzeće, uploadSlika); if (TempData["status"] != null) { ViewBag.Message = TempData["status"].ToString(); TempData.Remove("status"); } if (TempData["shortMessage"] != null) { ViewBag.Message = TempData["shortMessage"].ToString(); TempData.Remove("shortMessage"); } return(View("~/Views/Poduzeće/Profil.cshtml", tuple)); }
public ActionResult UpravljanjeSlikamaPoduzeće(string idPoduzeća) { if (idPoduzeća == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IEnumerable <images> images = from c in db.images where c.imageIdByPoduzeće.Equals(idPoduzeća) select c; UploadImagesModels uploadSlika = new UploadImagesModels(); uploadSlika.idKorisnika = idPoduzeća; Tuple <IEnumerable <images>, UploadImagesModels> tuple = Tuple.Create(images, uploadSlika); if (TempData["shortMessage"] != null) { ViewBag.Message = TempData["shortMessage"].ToString(); TempData.Remove("shortMessage"); } return(View("~/Views/Admin/Poduzeće/UpravljanjeSlikamaPoduzeće.cshtml", tuple)); }