// GET: Author/Details/5 public ActionResult Details(int id) { var model = _unitOfWork.Repo.GetAuthors().FirstOrDefault(b => b.AuthorId == id); AuthorViewModelImage AVM = new AuthorViewModelImage { Author = model, AuthorImage = model.Slike.FirstOrDefault(b => b.AuthorId == model.AuthorId) }; AVM.ImagePath = AVM.AuthorImage.PathImage; return(View(AVM)); }
public ActionResult Create(Author model, HttpPostedFileBase file) { AuthorImage slikaInfo = new AuthorImage(); AuthorViewModelImage AVM = new AuthorViewModelImage(); if (file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(@"\SlikeAutora", fileName); slikaInfo.PathImage = path; slikaInfo.AuthorId = model.AuthorId; slikaInfo.Author = model; _unitOfWork.Repo.AddSlikaAutora(slikaInfo); byte[] uploadedFile = new byte[file.ContentLength]; var SlikaFajl = file.InputStream.Read(uploadedFile, 0, uploadedFile.Length); AVM.Author = model; AVM.AuthorImage = slikaInfo; AVM.Author.Slike.Add(slikaInfo); // model.Slike.Add(); // AVM.ImagePath = model.Slika; } if (ModelState.IsValid == false) { return(View(AVM)); } try { _unitOfWork.Repo.AddAuthor(model); _unitOfWork.Repo.AddSlikaAutora(slikaInfo); _unitOfWork.Complete(); return(View("Details", AVM)); } catch { return(View("Error")); } }