public IHttpActionResult PostAddToWishList(RateModel wishlist)
        {
            AddToWishList addToWishList = db.AddToWishLists.Where(i => i.ProducId == wishlist.ProductId && i.CustomerId == wishlist.CustomerId && i.Block == false).Include(i => i.Customer).Include(i => i.Product).FirstOrDefault();

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

            return(Ok(addToWishList));
        }
        public void TestFriends()
        {
            var accept = new AcceptFriend("targetid");

            Assert.IsNotNullOrEmpty(accept.RequestMethod.ToString());
            Assert.IsTrue(accept.EndPoint.Contains("targetid"));
            Assert.IsNotNull(accept.BodyParameters);

            var add = new AddFriend("targetid");

            Assert.IsNotNullOrEmpty(add.RequestMethod.ToString());
            Assert.IsTrue(add.EndPoint.Contains("targetid"));
            Assert.IsNotNull(add.BodyParameters);

            var toast = new ToastUntoast("targetid");

            Assert.IsNotNullOrEmpty(toast.RequestMethod.ToString());
            Assert.IsTrue(toast.EndPoint.Contains("targetid"));
            Assert.IsNotNull(toast.BodyParameters);

            var remove = new RemoveFriend("targetid");

            Assert.IsNotNullOrEmpty(remove.RequestMethod.ToString());
            Assert.IsTrue(remove.EndPoint.Contains("targetid"));
            Assert.IsNotNull(remove.BodyParameters);

            var removeWish = new RemoveFromWishList(1);

            Assert.IsNotNullOrEmpty(removeWish.RequestMethod.ToString());
            Assert.IsNotNullOrEmpty(removeWish.EndPoint);
            Assert.AreEqual(removeWish.BodyParameters["bid"], 1);


            var addWish = new AddToWishList(1);

            Assert.IsNotNullOrEmpty(addWish.RequestMethod.ToString());
            Assert.IsNotNullOrEmpty(addWish.EndPoint);
            Assert.AreEqual(addWish.BodyParameters["bid"], 1);

            var comment = new AddComment("checkin", "shout");

            Assert.IsNotNullOrEmpty(comment.RequestMethod.ToString());
            Assert.IsTrue(comment.EndPoint.Contains("checkin"));
            Assert.AreEqual(comment.BodyParameters["shout"], "shout");
        }
        public IHttpActionResult PostAddToWishList(AddToWishList addToWishList)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Product  prd      = db.Products.Find(addToWishList.ProducId);
            Customer customer = db.Customer.Find(addToWishList.CustomerId);

            if (prd == null)
            {
                return(BadRequest("product not found"));
            }

            if (customer == null)
            {
                return(BadRequest("customer not found"));
            }

            db.AddToWishLists.Add(addToWishList);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (db.AddToWishLists.Where(i => i.ProducId == addToWishList.ProducId && i.CustomerId == addToWishList.CustomerId).FirstOrDefault() != null)
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }
            var mess = new { message = "success", data = db.AddToWishLists.Where(i => i.CustomerId == addToWishList.CustomerId).Include(i => i.Product).Include(i => i.Customer).ToList() };

            return(Ok(mess));
        }
        public IHttpActionResult PutAddToWishList(AddToWishList addToWishList)
        {
            AddToWishList wishList = db.AddToWishLists.Where(i => i.ProducId == addToWishList.ProducId && i.CustomerId == addToWishList.CustomerId && i.Block == false).Include(i => i.Customer).Include(i => i.Product).FirstOrDefault();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (wishList == null)
            {
                return(BadRequest("not found"));
            }

            wishList.Block = addToWishList.Block;
            wishList.Date  = DateTime.Now;

            //db.Entry(addToWishList).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                //if (!AddToWishListExists(id))
                //{
                //    return NotFound();
                //}
                //else
                //{
                throw;
                //}
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PostDeleteWishItem(AddToWishList wishList)
        {
            if (db.Customer.Find(wishList.CustomerId) == null)
            {
                return(BadRequest("customer not exist"));
            }

            if (db.Products.Find(wishList.ProducId) == null)
            {
                return(BadRequest("product not exist"));
            }
            AddToWishList addToWishList = db.AddToWishLists.Where(i => i.CustomerId == wishList.CustomerId && i.ProducId == wishList.ProducId).FirstOrDefault();

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


            db.AddToWishLists.Remove(addToWishList);
            db.SaveChanges();

            return(Ok(new { message = "deleted successfully" }));
        }
        public async Task <IActionResult> AddItem([FromBody] AddToWishList model)
        {
            if (ModelState.IsValid)
            {
                var user = await _workContext.GetCurrentUser();

                var resultModel = new AddToWishListResult();

                var product = await _productRepository
                              .Query()
                              .Include(x => x.ThumbnailImage)
                              .SingleOrDefaultAsync(x => x.Id == model.ProductId);

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

                var wishList = await _wishListRepository
                               .Query()
                               .Include(x => x.Items)
                               .SingleOrDefaultAsync(x => x.UserId == user.Id);

                if (wishList == null)
                {
                    wishList = new Models.WishList()
                    {
                        UserId = user.Id
                    };

                    _wishListRepository.Add(wishList);
                    await _wishListRepository.SaveChangesAsync();
                }

                var existingWishlistItem = wishList
                                           .Items
                                           .SingleOrDefault(x => x.ProductId == model.ProductId);

                if (existingWishlistItem != null)
                {
                    resultModel.Message = "The product already exists in your wish list";
                    resultModel.Item    = new WishListItemVm()
                    {
                        Id           = existingWishlistItem.Id,
                        WishListId   = wishList.Id,
                        ProductName  = product.Name,
                        ProductImage = _mediaService.GetThumbnailUrl(product.ThumbnailImage),
                        Quantity     = existingWishlistItem.Quantity,
                    };
                }
                else
                {
                    var wishListItem = new WishListItem()
                    {
                        WishListId = wishList.Id,
                        ProductId  = model.ProductId,
                        Quantity   = model.Quantity
                    };

                    _wishListItemRepository.Add(wishListItem);

                    wishList.UpdatedOn = DateTimeOffset.Now;
                    await _wishListRepository.SaveChangesAsync();

                    resultModel.Message = "The product has been added to your wish list";
                    resultModel.Item    = new WishListItemVm()
                    {
                        Id           = wishListItem.Id,
                        WishListId   = wishList.Id,
                        ProductName  = product.Name,
                        ProductImage = _mediaService.GetThumbnailUrl(product.ThumbnailImage),
                        Quantity     = model.Quantity,
                    };
                }

                return(PartialView("AddToWishListResult", resultModel));
            }

            return(NotFound());
        }
Beispiel #7
0
 public void ClickAddToWishList()
 {
     AddToWishList.Click();
 }