コード例 #1
0
        public void ShouldAddFavoriteProduct()
        {
            var usf = crudOnFavorites.AddProductToFavorites(username, productId).Result;

            Assert.AreEqual(usf.Username, username);
            Assert.AreEqual(usf.ProductId, productId);
            crudOnFavorites.DeleteProductFromFavorites(username, productId);
        }
コード例 #2
0
        public async Task <IHttpActionResult> Post(string username, int productId)
        {
            if (!await authorization.UserIsHimself(User.Identity.GetUserName(), username))
            {
                return(Unauthorized());
            }

            try
            {
                var usf = await crudOnFavorites.AddProductToFavorites(username, productId);

                var viewUsf = Mapper.Map <ViewUsersFavoriteProducts>(usf);

                return(Ok(viewUsf));
            }
            catch (Exception ex)
            {
                return(throwExceptionToUser.Throw(ex));
            }
        }