Пример #1
0
 public ActionResult AddMovie(GlobalMovie item, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var fileName = Guid.NewGuid().ToString();
             var path     = Path.Combine(Server.MapPath("~/App_Data/MoviesBase/"), 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("AddMovie"));
             }
         }
         catch (Exception)
         {
             ViewBag.Message = "Upload failed";
             return(View("AddMovie"));
         }
         ViewBag.Message = "Upload successful";
         return(RedirectToAction("GetAllMyMovies", new GlobalMovie()));
     }
     return(View(item));
 }
Пример #2
0
        public GlobalMovie Add(GlobalMovie item, string login)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            var dbEntry = _repo.PersonProfiles.GetAll().SingleOrDefault(x => x.Login == login);

            if (dbEntry != null)
            {
                GlobalMovie antiDoubleGlobalMovie = _repo.GlobalMovies.GetAll().SingleOrDefault(x => x.Title == item.Title);
                if (antiDoubleGlobalMovie == null)
                {
                    var newDbEntry = new GlobalMovieLike(item, dbEntry);
                    dbEntry.GlobalMovieLikes.Add(newDbEntry);
                    _repo.PersonProfiles.Update(dbEntry);
                    _repo.Commit();
                    return(new GlobalMovie());
                }
                return(null);
            }
            return(item);
        }