public ActionResult Create(Kontakt kontakt, HttpPostedFileBase image) { kontakt.DatumKreiranja = DateTime.Today; kontakt.DatumIzmjene = DateTime.Today; if (ModelState.IsValid) { if (image != null) { kontakt.MimeTypeSlika = image.ContentType; kontakt.SlikaDatoteka = new byte[image.ContentLength]; image.InputStream.Read(kontakt.SlikaDatoteka, 0, image.ContentLength); } else { kontakt.MimeTypeSlika = "image/jpeg"; kontakt.SlikaDatoteka = KontaktInitializer.getFileBytes("\\Slike\\unknown.jpg"); } db.Kontakts.Add(kontakt); db.SaveChanges(); return RedirectToAction("Index"); } return View(kontakt); }
public ActionResult Create() { // Keriraj novi Graf / Create the new photo Kontakt newPhoto = new Kontakt(); newPhoto.PrezimeIme = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(User.Identity.Name); newPhoto.DatumKreiranja = DateTime.Today; newPhoto.DatumIzmjene = DateTime.Today; return View(newPhoto); }
public ActionResult Edit(Kontakt kontakt, HttpPostedFileBase image) { if (ModelState.IsValid) { if (image != null) { kontakt.MimeTypeSlika = image.ContentType; kontakt.SlikaDatoteka = new byte[image.ContentLength]; image.InputStream.Read(kontakt.SlikaDatoteka, 0, image.ContentLength); } kontakt.DatumKreiranja = kontakt.DatumKreiranja; kontakt.DatumIzmjene = DateTime.Today; db.Entry(kontakt).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(kontakt); }