Пример #1
0
        public NotificationDto AddToCartNotify(AddToCartNotifyDto data)
        {
            if (data == null)
            {
                throw new ArgumentException(Resources.NullOrEmptyValue, nameof(data));
            }

            if (string.IsNullOrWhiteSpace(data.ProductName))
            {
                throw new ArgumentException(Resources.NullOrEmptyValueString, nameof(data.ProductName));
            }

            if (data.ReceiverId < 1)
            {
                throw new ArgumentException(Resources.LessThanOrEqualToZeroValue, nameof(data.ReceiverId));
            }

            var notification = Mapper.Map <NotificationDto>(data);

            notification.Title = Resources.DefaultNotificationTitle;

            _signulRHub.Clients.User(notification.ReceiverId.ToString()).UpdateNotices(notification);

            return(notification);
        }
Пример #2
0
        /// <summary>
        /// Add new item in cart with return save item for update view
        /// </summary>
        /// <param name="contentId">contents identifier</param>
        /// <param name="userId">users identifier</param>
        /// <returns>this save item</returns>
        public ContentCartDto AddInCart(long contentId, long userId)
        {
            // Verify long contentId
            if (contentId <= 0)
            {
                throw new ArgumentException(Resources.InvalidContentId);
            }

            // Check exist Product in repository
            if (this.repositoryProduct.Get(contentId) == null)
            {
                throw new ExistContentInCartExceptions(Resources.ExistProductInDataBase);
            }

            // Check exist Content in Cart with state = InBougth for current user
            if (this.ExistInCart(contentId, userId, CartEnums.StateCartContent.InPaid))
            {
                throw new ExistContentInCartExceptions(Resources.ContentAlreadyBougth);
            }

            // Check exist Content in Cart with state = InCart for current user
            if (this.ExistInCart(contentId, userId, CartEnums.StateCartContent.InCart))
            {
                throw new ExistContentInCartExceptions(Resources.ExistContentInCart);
            }

            var contentCart = new ContentCart()
            {
                CreatorId = userId, ProductId = contentId
            };

            // Save object ContentCart in repository
            var addContentCart = this.repositoryContentCart.Add(contentCart);

            // If the object is not added to the database
            // return null
            if (addContentCart == null)
            {
                throw new AddContentInCartExceptions(Resources.ResourceManager.GetString("AddContentInCart"));
            }

            // Get information about Product by Id
            var product = this.repositoryProduct.Get(contentId);

            // Create object AddToCartNotifyDto
            var objectNotify = new AddToCartNotifyDto()
            {
                ReceiverId = userId, ProductName = product.ProductName
            };

            var notification = this.serviceNotification.AddToCartNotify(objectNotify);

            // Create ContentCartDto
            var contentCartDto = Mapper.Map <ContentCartDto>(product);

            contentCartDto.Id        = addContentCart.Id;
            contentCartDto.CreatorId = userId;

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