Esempio n. 1
0
        public ActionResult <FavouritePackage> PostFavouritePackage(FavouritePackage favouritePackage)
        {
            if (favouritePackage.Type != "moment" && favouritePackage.Type != "post")
            {
                return(BadRequest());
            }

            if (favouritePackage.Privacy != "public" && favouritePackage.Privacy != "private")
            {
                return(BadRequest());
            }

            _context.FavouritePackage.Add(favouritePackage);
            try{
                _context.SaveChanges();
            }
            catch (DbUpdateException) {
                if (FavouritePackageExists(favouritePackage.Account, favouritePackage.Name))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetFavouritePackage", new { id = favouritePackage.Account }, favouritePackage));
        }
Esempio n. 2
0
        public IActionResult PutFavouritePackage(FavouritePackage editFavPackage)
        {
            if (editFavPackage.Privacy != "public" && editFavPackage.Privacy != "private")
            {
                return(BadRequest());
            }
            FavouritePackage fav = _context.FavouritePackage.Find(editFavPackage.Account, editFavPackage.Name);

            if (fav == null)
            {
                return(NotFound());
            }

            fav.Privacy = editFavPackage.Privacy;

            try{
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException) {
                throw;
            }

            return(NoContent());
        }