Beispiel #1
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 = "修改失败" }));
        }