Пример #1
0
        /// <summary>
        /// This method return receipt to accept.
        /// </summary>
        /// <param name="familyID">family the receipt belongs to</param>
        /// <param name="receiptToUpdate">receipt we need to return to accept</param>
        public void ReturnReceiptToAccept(string familyID, ReceiptToReturn receiptToUpdate)
        {
            //first we update status to -1
            DBConnection.UpdateStatus(familyID, receiptToUpdate.receiptID, "-1");
            string marketId = receiptToUpdate.marketID;

            //than we need to find similar products
            foreach (MetaData product in receiptToUpdate.products)
            {
                string productId = product.getsID();
                if (DBConnection.SelectQuery("select SID from OptionalProducts AS OP WHERE OP.MarketID='" + marketId + "' AND OP.ProductID ='" + productId + "'").Count == 0)
                {
                    List<ResearchProduct> optionalProducts = jwd.GetTopFiveSimilarProducts(product.description);
                    DBConnection.InsertOptionalProducts(marketId, productId, optionalProducts);
                }
            }

            //after finished, set status to 0
            DBConnection.UpdateStatus(familyID, receiptToUpdate.receiptID, "0");
        }
Пример #2
0
 public HttpResponseMessage ReturnToAccept(string familyID, [FromBody] ReceiptToReturn receipt)
 {
     try
     {
         var    httpRequest = HttpContext.Current.Request;
         string token       = httpRequest.Headers["Authorization"];
         if (UsersMngr.IsGlobalAdmin(token) || UsersMngr.IsLocalAdmin(token))
         {
             string username = UsersMngr.getUsernameByToken(token);
             _logger.Info($"USER:{username}     |ACTION: Return receipt to accept started, familyID {familyID}, receipt {receipt.receiptID}    |NAVIGATION:");
             ReceiptMngr.ReturnReceiptToAccept(familyID, receipt);
             return(Request.CreateResponse(HttpStatusCode.OK));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.Forbidden));
         }
     }
     catch (Exception e)
     {
         _logger.Error($"Error - ReturnToAccept, familyID: {familyID} receiptID: {receipt.receiptID}");
         return(Request.CreateResponse(HttpStatusCode.InternalServerError));
     }
 }
Пример #3
0
        /// <summary>
        /// This method update reciept data after saving receipt.
        /// First delete all products of given receipt.
        /// Then add all products of updated receipt.
        /// </summary>
        /// <param name="familyID">family the receipt belongs to</param>
        /// <param name="receiptToUpdate">receipt we need to update</param>
        public void UpdateReceiptData(string familyID, ReceiptToReturn receiptToUpdate)
        {
            try
            {
                ProductDescriptionParser pdp = new ProductDescriptionParser();
                string receiptID = receiptToUpdate.receiptID;
                List<MetaData> sortedProducts = receiptToUpdate.products.ToList();

                //delete -> insert -> updateStatus
                DBConnection.DeleteReceiptData(receiptID);
                foreach (MetaData product in sortedProducts)
                {
                    string productID = product.getsID();
                    string productDescription = product.getDescription();
                    //Parse the desc to find quantity
                    double quantityInDesc;
                    string quantityFoundInDesc = pdp.GetQuantityFromDescription(productDescription);
                    string productQuantity = product.getQuantity();

                    //if not found quantity in description
                    if (quantityFoundInDesc.Equals("") || productQuantity.Contains('.'))
                    {
                        //if qunatitny is float (0.35 for example) than we set quantityFoundInDesc to 1
                        if (productQuantity.Contains('.'))
                        {
                            quantityFoundInDesc = "1";
                        }

                        //not float, set quantityFoundInDesc to 0.1 (default is 100 gr)
                        else
                        {
                            quantityFoundInDesc = "0.1";
                        }
                    }


                    //found quantity in description
                    else
                    {
                        if (double.TryParse(pdp.GetQuantityFromDescription(productDescription), out quantityInDesc))
                        {
                            quantityFoundInDesc = (quantityInDesc / 1000) + "";
                        }
                    }

                    string productPrice = product.getPrice();
                    ResearchProduct rp = product.getOptionalProductsChosen();
                    DBConnection.InsertReceiptData(familyID, receiptID, productID, productDescription, productQuantity, quantityFoundInDesc, productPrice, 0, true);
                    if (rp != null)
                    {
                        DBConnection.DeleteOptionalData(receiptToUpdate.marketID, product.getsID()); //delete all optional exists
                        DBConnection.InsertOptionalProduct(receiptToUpdate.marketID, product.getsID(), rp);
                    }

                    //not chosen - delete all up to 5 optionals
                    else if (rp == null)
                    {
                        DBConnection.DeleteOptionalData(receiptToUpdate.marketID, product.getsID());

                    }
                }
                DBConnection.UpdateStatus(familyID, receiptID, "1");
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }