Ejemplo n.º 1
0
 //POST:films/add_to_favorites
 public JsonResult AddFavoriteFilm(UserFilmProperties properties)
 {
     if (properties.film_id > 0 && !string.IsNullOrEmpty(properties.object_id))
     {
         bool success = false;
         var favoritFilmsIds = Repository.FavoriteFilms
             .Where(f => f.User_Id == properties.object_id)
             .Select(f => f.Film_Id).ToList();
         if(!favoritFilmsIds.Contains(properties.film_id))
         {
             success = Repository.AddFavoriteFilm(properties.object_id, properties.film_id);
             return new JsonResult { Data = new { OK = success } };
         }
         return new JsonResult
         {
             Data = new
             {
                 OK = false,
                 ErrorId = 1,
                 ErrorMessege = string.Format("User with id {0} have already add film with id {1}", properties.object_id, properties.film_id)
             }
         };
     }
     return new JsonResult {
         Data = new
         {
             OK = false,
             ErrorId = 2,
             ErrorMessege = string.Format("User with id {0} or film with id {1} does not exist", properties.object_id, properties.film_id)
         },
     };
 }
Ejemplo n.º 2
0
 //POST:films/add_download
 public JsonResult AddDownload(UserFilmProperties properties)
 {
     bool success = false;
     if (properties.film_id > 0 && !string.IsNullOrEmpty(properties.object_id))
     {
         success = Repository.AddDownload(properties.object_id, properties.film_id);
     }
     return new JsonResult
     {
         Data = new { OK = success },
         JsonRequestBehavior = JsonRequestBehavior.AllowGet
     };
 }
Ejemplo n.º 3
0
 public JsonResult IsFavorite(UserFilmProperties properties)
 {
     if (properties.film_id > 0 && !string.IsNullOrEmpty(properties.object_id))
     {
         bool contains = false;
             var userFavoriteFilms = Repository.FavoriteFilms.Where(f => f.User_Id == properties.object_id).ToList();
             if (userFavoriteFilms != null)
             {
                 contains = userFavoriteFilms.Select(film => film.Film_Id).Contains(properties.film_id);
                 return Json(new { OK = true, Contains = contains });
             }
             return new JsonResult
             {
                 Data = new
                 {
                     OK = false,
                     ErrorId = 1,
                     ErrorMessege = string.Format("User with id {0} doesn't have favorites films ", properties.object_id)
                 }
             };
     }
     return new JsonResult
     {
         Data = new
         {
             OK = false,
             ErrorId = 2,
             ErrorMessege = string.Format("User with id {0} or film with id {1} does not exist", properties.object_id, properties.film_id)
         }
     };
 }