public ActionResult AddBook(GlobalBook item, HttpPostedFileBase file) { if (ModelState.IsValid) { try { var fileName = Guid.NewGuid().ToString(); var path = Path.Combine(Server.MapPath("~/App_Data/BooksBase/"), fileName); file.SaveAs(path); item.Created = DateTime.UtcNow; item.DataId = fileName; var result = _repository.Add(item, User.Identity.Name); if (result == null) { ViewBag.Message = "We have this position in Book List"; return(View("AddBook")); } } catch (Exception) { ViewBag.Message = "Upload failed"; return(View("AddBook")); } ViewBag.Message = "Upload successful"; return(RedirectToAction("GetAllMyBooks", new GlobalBook())); } return(View(item)); }
public GlobalBook Add(GlobalBook item, string login) { if (item == null) { throw new ArgumentNullException("item"); } var dbEntry = _repo.PersonProfiles.GetAll().SingleOrDefault(x => x.Login == login); if (dbEntry != null) { GlobalBook antiDoubleGlobalBook = _repo.GlobalBooks.GetAll().SingleOrDefault(x => x.Title == item.Title); if (antiDoubleGlobalBook == null) { var newDbEntry = new GlobalBookLike(item, dbEntry); dbEntry.GlobalBookLikes.Add(newDbEntry); _repo.PersonProfiles.Update(dbEntry); _repo.Commit(); return(new GlobalBook()); } return(null); } return(item); }