Beispiel #1
0
        public async Task <IHttpActionResult> RejectSaleMonad(LeaderShip_InputDto leaderShip_Input)
        {
            var        userId     = ((UserIdentity)User.Identity).UserId;
            LeaderShip leaderShip = new LeaderShip
            {
                Id       = IdentityManager.NewId(),
                Sale_Id  = leaderShip_Input.Sale_Id,
                User_DId = userId,
                Des      = leaderShip_Input.Des
            };

            db.LeaderShips.Add(leaderShip);

            var result = new Product_Sale {
                Id = leaderShip_Input.Sale_Id
            };

            db.Entry(result).State = EntityState.Unchanged;
            result.Is_Or           = 20;//撤销

            if (await db.SaveChangesAsync() > 0)
            {
                return(Json(new { code = 200, msg = "确认成功" }));
            }
            return(Json(new { code = 210, msg = "确认失败" }));
        }
Beispiel #2
0
        public async Task <IHttpActionResult> SetSaleProduct(ProductSaleInput productSaleInput)
        {
            Product_Sale product_Sale = new Product_Sale
            {
                Id                  = IdentityManager.NewId(),
                Behoof              = productSaleInput.Behoof,
                Des                 = productSaleInput.Des,
                FishProductId       = productSaleInput.FishProductId,
                ProductNumber       = productSaleInput.ProductNumber,
                QuasiPurchaseNumber = productSaleInput.ProductNumber,
                Sale_Time           = DateTime.Now,
                Userid              = productSaleInput.Userid,
                Sale_Price          = productSaleInput.Sale_Price,
                SupplierId          = productSaleInput.SupplierId,
                Is_Or               = 1
            };

            db.Product_Sales.Add(product_Sale);
            if (await db.SaveChangesAsync() > 0)
            {
                return(Json(new { code = 200, msg = "添加销售申请成功" }));
            }



            return(Json(new { code = 201, msg = "失败" }));
        }
Beispiel #3
0
        public async Task <IHttpActionResult> EdditSaleMonad(ProductSaleInput productSaleInput)
        {
            Product_Sale type_res = new Product_Sale {
                Id = productSaleInput.Id
            };

            // var type_res = await Task.Run(() => db.Product_Sales.SingleOrDefaultAsync(p => p.Id == productSaleInput.Id));
            type_res.Behoof              = productSaleInput.Behoof;
            type_res.Des                 = productSaleInput.Des;
            type_res.ProductNumber       = productSaleInput.ProductNumber;
            type_res.QuasiPurchaseNumber = productSaleInput.QuasiPurchaseNumber;
            type_res.Sale_Price          = productSaleInput.Sale_Price;
            type_res.SupplierId          = productSaleInput.SupplierId;
            type_res.Userid              = productSaleInput.Userid;

            db.Configuration.ValidateOnSaveEnabled = false;
            db.Entry(type_res).State = System.Data.Entity.EntityState.Unchanged;
            //Type type = typeof(ProductSaleInput);
            //Assembly assembly = Assembly.GetExecutingAssembly();
            //object o = assembly.CreateInstance(type.FullName);
            //PropertyInfo[] propertyInfos = o.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
            //string str = string.Empty;
            //str += string.Format("类名称:{0}", type.Name);
            /* if (item.Name != "Id" && item.Name != "z_FnishedProduct" && item.Name != "Supplier" && item.Name != "userDetails")*/      /*item.GetValue(type_res) != null && !string.IsNullOrWhiteSpace(value.ToString()) && name != "Id"&& (long)item.GetValue(type_res) != 0&& (double)item.GetValue(type_res)!=null*/
            foreach (var item in type_res.GetType().GetProperties())
            {
                string name = item.Name;
                //  object value = item.GetValue(type_res);

                object value = item.GetValue(type_res);
                if (item.GetValue(type_res) != null && value.ToString() != "" && item.Name != "Id" &&
                    value.ToString() != "0" && item.Name != "z_FnishedProduct" && item.Name != "Supplier" && item.Name != "userDetails")
                {
                    Console.WriteLine(item.Name);
                    db.Entry(type_res).Property(item.Name).IsModified = true;
                }
                else
                {
                    if (item.Name != "z_FnishedProduct" && item.Name != "Supplier" && item.Name != "userDetails")
                    {
                        Console.WriteLine(item.Name);
                        db.Entry(type_res).Property(item.Name).IsModified = false;
                    }
                }
            }
            if (await db.SaveChangesAsync() > 0)
            {
                db.Configuration.ValidateOnSaveEnabled = true;
                return(Json(new { code = 200, msg = "修改成功" }));
            }

            return(Json(new { code = 301, msg = "修改失败" }));
        }
        public object removeSaleProduct(int productID, int saleID, int quantity)
        {
            db.Configuration.ProxyCreationEnabled = false;
            dynamic toReturn = new ExpandoObject();

            try
            {
                Product product = db.Products.Where(x => x.ProductID == productID).FirstOrDefault();
                if (product != null)
                {
                    Sale sale = db.Sales.Where(x => x.SaleID == saleID).FirstOrDefault();
                    if (sale != null)
                    {
                        Container_Product container_Product = db.Container_Product.Where(x => x.ContainerID == sale.ContainerID && x.ProductID == product.ProductID).FirstOrDefault();
                        if (container_Product != null)
                        {
                            container_Product.CPQuantity = (container_Product.CPQuantity + quantity);
                            db.SaveChanges();

                            Product_Sale product_Sale = db.Product_Sale.Where(x => x.ProductID == product.ProductID && x.SaleID == sale.SaleID).FirstOrDefault();
                            if (product_Sale != null)
                            {
                                db.Product_Sale.Remove(product_Sale);
                                db.SaveChanges();

                                toReturn.Product_Sale = product_Sale;
                            }
                        }
                        else
                        {
                            toReturn.Error = "Container Not Found";
                        }
                    }
                    else
                    {
                        toReturn.Error = "Sale Not Found";
                    }
                }
                else
                {
                    toReturn.Error = "Product Not Found";
                }
            }
            catch
            {
                toReturn.Error = "Product Removal Unsuccessful";
            }

            return(toReturn);
        }
        public object cancelSale(int saleID)
        {
            db.Configuration.ProxyCreationEnabled = false;
            dynamic toReturn = new ExpandoObject();

            try
            {
                //get sale
                Sale newSale = db.Sales.Where(x => x.SaleID == saleID).FirstOrDefault();
                if (newSale != null)
                {
                    //get container
                    Container container = db.Containers.Where(x => x.ContainerID == newSale.ContainerID).FirstOrDefault();



                    //get list of products in Sale
                    List <Product_Sale> product_Sales = db.Product_Sale.Where(x => x.SaleID == newSale.SaleID).ToList();

                    if (container != null)
                    {
                        if (product_Sales != null)
                        {
                            foreach (var prod in product_Sales)
                            {
                                Product product = db.Products.Where(x => x.ProductID == prod.ProductID).FirstOrDefault();
                                if (product != null)
                                {
                                    Container_Product container_Product = db.Container_Product.Where(x => x.ContainerID == newSale.ContainerID && x.ProductID == product.ProductID).FirstOrDefault();
                                    if (container_Product != null)
                                    {
                                        container_Product.CPQuantity = (container_Product.CPQuantity + prod.PSQuantity);
                                        db.SaveChanges();

                                        Product_Sale product_Sale = db.Product_Sale.Where(x => x.ProductID == product.ProductID && x.SaleID == newSale.SaleID).FirstOrDefault();
                                        if (product_Sale != null)
                                        {
                                            db.Product_Sale.Remove(product_Sale);
                                            db.SaveChanges();
                                        }
                                    }
                                }
                                else
                                {
                                    toReturn.Error = "Product Not Found";
                                }

                                //get list of payment
                                List <Payment> payments = db.Payments.Where(x => x.SaleID == newSale.SaleID).ToList();
                                if (payments.Count != 0)
                                {
                                    foreach (Payment payment in payments)
                                    {
                                        db.Payments.Remove(payment);
                                        db.SaveChanges();
                                    }
                                }

                                toReturn.Message = "Sale Cancelled";
                            }
                        }
                        else
                        {
                            toReturn.Message = "Cancelling Sale Failed";
                        }
                    }
                    else
                    {
                        toReturn.Error = "Container Not Found";
                    }
                }


                else
                {
                    toReturn.Error = "Cancel Failed: Sale Not Found";
                }
            }
            catch
            {
                toReturn.Error = "Sale Cancellation Unsuccessfully Completed";
            }

            return(toReturn);
        }
        public object addSaleProduct(int productID, int saleID, int quantity)
        {
            db.Configuration.ProxyCreationEnabled = false;
            dynamic toReturn = new ExpandoObject();

            try
            {
                Product product = db.Products.Where(x => x.ProductID == productID).FirstOrDefault();
                if (product != null)
                {
                    Sale sale = db.Sales.Where(x => x.SaleID == saleID).FirstOrDefault();
                    if (sale != null)
                    {
                        Container_Product container_Product = db.Container_Product.Where(x => x.ContainerID == sale.ContainerID && x.ProductID == product.ProductID).FirstOrDefault();
                        if (container_Product != null)
                        {
                            if (quantity > container_Product.CPQuantity)
                            {
                                toReturn.Error = "Only " + container_Product.CPQuantity + "Of " + product.ProdName + "In Stock";
                                return(toReturn);
                            }
                            else
                            {
                                container_Product.CPQuantity = (container_Product.CPQuantity - quantity);
                                db.SaveChanges();

                                Product_Sale product_Sale = db.Product_Sale.Where(x => x.ProductID == product.ProductID && x.SaleID == sale.SaleID).FirstOrDefault();
                                if (product_Sale == null)
                                {
                                    Product_Sale newProduct_Sale = new Product_Sale();
                                    newProduct_Sale.ProductID  = product.ProductID;
                                    newProduct_Sale.Product    = product;
                                    newProduct_Sale.SaleID     = sale.SaleID;
                                    newProduct_Sale.Sale       = sale;
                                    newProduct_Sale.PSQuantity = quantity;
                                    db.Product_Sale.Add(newProduct_Sale);
                                    db.SaveChanges();

                                    toReturn.Product_Sale = db.Product_Sale.ToList().LastOrDefault();
                                }
                                else
                                {
                                    product_Sale.PSQuantity = product_Sale.PSQuantity + quantity;
                                    db.SaveChanges();

                                    toReturn.Product_Sale = product_Sale;
                                }
                            }
                        }
                        else
                        {
                            toReturn.Error = "Container Not Found";
                        }
                    }
                    else
                    {
                        toReturn.Error = "Sale Not Found";
                    }
                }
                else
                {
                    toReturn.Error = "Product Not Found";
                }
            }
            catch
            {
                toReturn.Error = "Product Add Unsuccessful";
            }

            return(toReturn);
        }