Exemple #1
0
        public LacesResponse RemoveFromInterestQueue(ProductRequest request)
        {
            LacesResponse response = new LacesResponse();

            try
            {
                if (request.SecurityString == ConfigurationManager.AppSettings[Constants.APP_SETTING_SECURITY_TOKEN])
                {
                    // Confirm user and product exist
                    LacesDataModel.User.User       user    = new LacesDataModel.User.User(request.UserId);
                    LacesDataModel.Product.Product product = new LacesDataModel.Product.Product(request.ProductId);

                    UserInterestQueue userInterest = new UserInterestQueue();

                    userInterest.LoadByUserAndProductIds(user.UserId, product.ProductId);

                    if (userInterest.UserInterestQueueId == 0)
                    {
                        userInterest.UserId     = user.UserId;
                        userInterest.ProductId  = product.ProductId;
                        userInterest.Interested = false;

                        if (userInterest.Add())
                        {
                            response.Success = true;
                            response.Message = "Operation completed.";
                        }
                        else
                        {
                            response.Success = false;
                            response.Message = "An error occurred when communicating with the database.";
                        }
                    }
                    else if (userInterest.Interested == true)
                    {
                        userInterest.Interested = false;

                        if (userInterest.Update())
                        {
                            response.Success = true;
                            response.Message = "Operation completed.";
                        }
                        else
                        {
                            response.Success = false;
                            response.Message = "An error occurred when communicating with the database.";
                        }
                    }
                    else
                    {
                        response.Success = true;
                        response.Message = "Operation completed.";
                    }
                }
                else
                {
                    response.Success = false;
                    response.Message = "Invalid security token.";
                }
            }
            catch (Exception ex)
            {
                response         = new LacesResponse();
                response.Success = false;

                if (ex.Message.Contains("find user") || ex.Message.Contains("find product") || ex.Message.Contains("find like"))
                {
                    response.Message = ex.Message;
                }
                else
                {
                    response.Message = "An unexpected error has occurred; please verify the format of your request.";
                }
            }

            return(response);
        }
Exemple #2
0
        public GetDetailedProductResponse GetDetailedProduct(ProductRequest request)
        {
            GetDetailedProductResponse response = new GetDetailedProductResponse();

            try
            {
                if (request.SecurityString == ConfigurationManager.AppSettings[Constants.APP_SETTING_SECURITY_TOKEN])
                {
                    LacesDataModel.Product.Product product = new LacesDataModel.Product.Product(request.ProductId);

                    if (product.ProductStatusId != (int)ProductStatusOptions.Removed)
                    {
                        LacesDataModel.User.User user = new LacesDataModel.User.User(product.SellerId);

                        response.Product = new LacesAPI.Models.Response.Product();

                        response.Product.AskingPrice = product.AskingPrice;
                        response.Product.Brand       = product.Brand;
                        response.Product.Comments    = new List <int>();

                        List <Comment> comments = Comment.GetCommentsForProduct(product.ProductId);

                        foreach (Comment comment in comments)
                        {
                            response.Product.Comments.Add(comment.CommentId);
                        }

                        response.Product.CommentCount = response.Product.Comments.Count;
                        response.Product.ConditionId  = product.ConditionId;
                        response.Product.CreatedDate  = product.CreatedDate;
                        response.Product.Description  = product.Description;

                        List <UserLike> likes = UserLike.GetLikesForProduct(product.ProductId); // Consider adding aggregate functions to repo classes

                        response.Product.LikeCount     = likes.Count;
                        response.Product.Name          = product.Name;
                        response.Product.ProductImages = new List <LacesAPI.Models.Response.ImageInfo>();

                        List <Image> images = Image.GetImagesForProduct(product.ProductId);

                        foreach (Image image in images)
                        {
                            LacesAPI.Models.Response.ImageInfo imageInfo = new LacesAPI.Models.Response.ImageInfo();

                            imageInfo.DateLastChanged = image.UpdatedDate;
                            imageInfo.FileData        = File.ReadAllBytes(image.FilePath);
                            imageInfo.FileFormat      = image.FileFormat;
                            imageInfo.FileFormat      = image.FileName;

                            response.Product.ProductImages.Add(imageInfo);
                        }

                        response.Product.Size = product.Size;
                        response.UserName     = user.UserName;

                        Image userImage = new Image();

                        userImage.LoadAvatarByUserId(user.UserId);

                        response.UserProfilePic = new LacesAPI.Models.Response.ImageInfo();
                        response.UserProfilePic.DateLastChanged = userImage.UpdatedDate;
                        response.UserProfilePic.FileData        = File.ReadAllBytes(userImage.FilePath);
                        response.UserProfilePic.FileFormat      = userImage.FileFormat;
                        response.UserProfilePic.FileName        = userImage.FileName;
                        response.Product.Tags = new List <LacesAPI.Models.Response.Tag>();

                        List <LacesDataModel.Product.Tag> tags = LacesDataModel.Product.Tag.GetTagsForProduct(product.ProductId);

                        foreach (LacesDataModel.Product.Tag tag in tags)
                        {
                            LacesAPI.Models.Response.Tag respTag = new LacesAPI.Models.Response.Tag();

                            respTag.TagId       = tag.TagId;
                            respTag.Description = tag.Description;

                            response.Product.Tags.Add(respTag);
                        }

                        UserInterestQueue interest = new UserInterestQueue();

                        interest.LoadByUserAndProductIds(user.UserId, product.ProductId);

                        if (interest.UserInterestQueueId > 0)
                        {
                            if (interest.Interested)
                            {
                                response.UserInterestStatus = (int)UserInterestStatusOption.Interested;
                            }
                            else
                            {
                                response.UserInterestStatus = (int)UserInterestStatusOption.Uninterested;
                            }
                        }
                        else
                        {
                            response.UserInterestStatus = (int)UserInterestStatusOption.Unknown;
                        }

                        response.Success = true;
                        response.Message = "Product details retrieved succesfully.";
                    }
                    else
                    {
                        response.Success = false;
                        response.Message = "That product has been removed and cannot be updated.";
                    }
                }
                else
                {
                    response.Success = false;
                    response.Message = "Invalid security token.";
                }
            }
            catch (Exception ex)
            {
                response         = new GetDetailedProductResponse();
                response.Success = false;

                if (ex.Message.Contains("find user") || ex.Message.Contains("find product"))
                {
                    response.Message = ex.Message;
                }
                else
                {
                    response.Message = "An unexpected error has occurred; please verify the format of your request.";
                }
            }

            return(response);
        }