Ejemplo n.º 1
0
        public LacesResponse ProcessTransaction(ProcessTransactionRequest request)
        {
            LacesResponse response = new LacesResponse();

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

                    Transaction trans = new Transaction();

                    trans.Amount          = request.Amount;
                    trans.BuyerId         = buyer.UserId;
                    trans.ProductId       = product.ProductId;
                    trans.ReferenceNumber = request.ReferenceNumber;
                    trans.SellerId        = seller.UserId;
                    trans.CreatedDate     = DateTime.Now;

                    if (trans.Add())
                    {
                        product.ProductStatusId = (int)ProductStatusOptions.Sold;

                        product.Update();

                        response.Success = true;
                        response.Message = "Transaction data saved succesfully.";
                    }
                    else
                    {
                        response.Success = false;
                        response.Message = "An error occurred when communicating with the database.";
                    }
                }
                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"))
                {
                    response.Message = ex.Message;
                }
                else
                {
                    response.Message = "An unexpected error has occurred; please verify the format of your request.";
                }
            }

            return(response);
        }
Ejemplo n.º 2
0
        public LacesResponse RemoveProduct(ProductRequest request)
        {
            LacesResponse response = new LacesResponse();

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

                    product.ProductStatusId = (int)ProductStatusOptions.Removed;

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

                if (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);
        }
Ejemplo n.º 3
0
        public LacesResponse UpdateProduct(UpdateProductRequest request)
        {
            LacesResponse response = new LacesResponse();

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

                    if (product.SellerId == request.UserId)
                    {
                        bool changed = false;

                        if (request.AskingPrice > 0)
                        {
                            product.AskingPrice = request.AskingPrice;
                            changed             = true;
                        }

                        if (request.Brand != null)
                        {
                            product.Brand = request.Brand;
                            changed       = true;
                        }

                        if (request.ConditionId > 0)
                        {
                            product.ConditionId = request.ConditionId;
                            changed             = true;
                        }

                        if (request.Description != null)
                        {
                            product.Description = request.Description;
                            changed             = true;
                        }

                        if (request.ProductName != null)
                        {
                            product.Name = request.ProductName;
                            changed      = true;
                        }

                        if (request.ProductStatusId > 0)
                        {
                            product.ProductStatusId = request.ProductStatusId;
                            changed = true;
                        }

                        if (request.ProductTypeId > 0)
                        {
                            product.ProductTypeId = request.ProductTypeId;
                            changed = true;
                        }

                        if (request.Size != null)
                        {
                            product.Size = request.Size;
                            changed      = true;
                        }

                        if (changed)
                        {
                            product.UpdatedDate = DateTime.Now;

                            if (product.Update())
                            {
                                response.Success = true;
                                response.Message = "Product successfully updated.";
                            }
                            else
                            {
                                response.Success = false;
                                response.Message = "An error occurred when communicating with the database.";
                            }
                        }
                        else
                        {
                            response.Success = true;
                            response.Message = "No changes were made.";
                        }
                    }
                    else
                    {
                        response.Success = false;
                        response.Message = "User cannot update this product.";
                    }
                }
                else
                {
                    response.Success = false;
                    response.Message = "Invalid security token.";
                }
            }
            catch (Exception ex)
            {
                response         = new LacesResponse();
                response.Success = false;

                if (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);
        }