Beispiel #1
0
        /// <summary>
        /// Method for check object as Bought
        /// </summary>
        /// <param name="contentId">contents object</param>
        /// <param name="userId">users identifier</param>
        /// <param name="contentState">contents state</param>
        /// <returns>update objects state</returns>
        public ContentCartDto SetState(long contentId, long userId, CartEnums.StateCartContent contentState)
        {
            // Verify long contentId
            if (contentId <= 0)
            {
                throw new ArgumentException(Resources.InvalidContentId);
            }

            // Get object by contentId
            var contentCartForUpdateList = this.repositoryContentCart
                                           .Find(item => item.ProductId == contentId & item.CreatorId == userId & item.StateContent == CartEnums.StateCartContent.InCart)
                                           .ToList();

            if (contentCartForUpdateList.Count() == 0)
            {
                throw new ExistContentInCartExceptions(Resources.NotExistContentInCart);
            }

            contentCartForUpdateList[0].StateContent = contentState;

            // Update change
            var contentCartAfterUpdate = this.repositoryContentCart.Update(contentCartForUpdateList[0]);

            // Check update property StateContent
            if (contentCartAfterUpdate.StateContent != contentState)
            {
                throw new UpdateContentInCartExseptions(Resources.UpdateContentInCart);
            }

            // Output mapping object ContentCart to object ContentCartDto
            return(Mapper.Map <ContentCartDto>(contentCartAfterUpdate));
        }
Beispiel #2
0
        /// <summary>
        /// Checking the existence of content in cart
        /// </summary>
        /// <param name="contentId">content id</param>
        /// <param name="userId">user identifier</param>
        /// <param name="contentState">content state</param>
        /// <returns>true - content exist in cart
        /// false - content doesn`t exist in cart</returns>
        public bool ExistInCart(long contentId, long userId, CartEnums.StateCartContent contentState)
        {
            var resultFind = this.repositoryContentCart
                             .Find(item => item.ProductId == contentId &
                                   item.CreatorId == userId & item.StateContent == contentState);

            return(resultFind.Count() != 0);
        }
Beispiel #3
0
        /// <summary>
        /// Async checking the existence of content in cart
        /// </summary>
        /// <param name="contentId">content id</param>
        /// <param name="userId">user identifier</param>
        /// <param name="contentState">content state</param>
        /// <returns>true - content exist in cart
        /// false - content doesn`t exist in cart</returns>
        public async Task <bool> ExistInCartAsync(long contentId, long userId, CartEnums.StateCartContent contentState)
        {
            var resultFindAsync = await this.repositoryContentCart
                                  .FindAsync(item => item.ProductId == contentId&
                                             item.CreatorId == userId& item.StateContent == contentState)
                                  .ConfigureAwait(false);

            return(resultFindAsync.Count() != 0);
        }
Beispiel #4
0
        /// <summary>
        /// Async method for check object as Bought
        /// </summary>
        /// <param name="contentId">contents object</param>
        /// <param name="userId">users identifier</param>
        /// <param name="contentState">contents state</param>
        /// <returns>object with update state</returns>
        public async Task <ContentCartDto> SetStateAsync(long contentId, long userId, CartEnums.StateCartContent contentState)
        {
            // Verify long contentId
            if (contentId <= 0)
            {
                throw new ArgumentException(Resources.InvalidContentId);
            }

            // Get object by contentId
            var contentCartForUpdateList = await this.repositoryContentCart
                                           .FindAsync(item => item.ProductId == contentId& item.CreatorId == userId& item.StateContent == CartEnums.StateCartContent.InCart)
                                           .ConfigureAwait(false);

            if (contentCartForUpdateList.Count() == 0)
            {
                throw new ExistContentInCartExceptions(Resources.NotExistContentInCart);
            }

            // Change state content
            var contentObjForUpdate = contentCartForUpdateList.AsQueryable().ElementAt(0);

            contentObjForUpdate.StateContent = contentState;

            // Update change
            var contentCartAfterUpdate = await this.repositoryContentCart.UpdateAsync(contentObjForUpdate).ConfigureAwait(false);

            // Check update property StateContent
            if (contentCartAfterUpdate.StateContent != contentState)
            {
                throw new UpdateContentInCartExseptions(Resources.UpdateContentInCart);
            }

            var contentCart = Mapper.Map <ContentCartDto>(contentCartAfterUpdate);

            // Output mapping object ContentCart to object ContentCartDto
            return(contentCart);
        }