/// <summary> /// /// </summary> /// <param name="buyPrice"></param> /// <returns></returns> public bool CreateBuyPrice(BBuyPrice buyPrice) { bool result = false; if (this.CurrentUserPermission.CREATE_BUY_PRICE == 0) { throw new KMJXCException("没有权限创建采购询价单"); } if (buyPrice == null) { throw new KMJXCException("输入不正确"); } using (KuanMaiEntities db = new KuanMaiEntities()) { Buy_Price dbBuyPrice = new Buy_Price(); if (buyPrice.Created <= 0) { dbBuyPrice.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); } dbBuyPrice.Shop_ID = this.Shop.Shop_ID; if (buyPrice.Shop != null && buyPrice.Shop.ID > 0) { dbBuyPrice.Shop_ID = buyPrice.Shop.ID; } dbBuyPrice.User_ID = this.CurrentUser.ID; if (buyPrice.User != null && buyPrice.User.ID > 0) { dbBuyPrice.User_ID = buyPrice.User.ID; } dbBuyPrice.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); dbBuyPrice.Title = buyPrice.Title; dbBuyPrice.Description = buyPrice.Desc; db.Buy_Price.Add(dbBuyPrice); db.SaveChanges(); result = true; if (dbBuyPrice.ID > 0 && buyPrice.Details!=null && buyPrice.Details.Count>0) { result = result & this.SaveBuyPriceDetails(buyPrice.Details, dbBuyPrice.ID); } } return result; }
public ApiMessage CreateBuyPrice() { ApiMessage message = new ApiMessage() { Status = "ok" }; HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"]; HttpRequestBase request = context.Request; string user_id = User.Identity.Name; UserManager userMgr = new UserManager(int.Parse(user_id), null); BUser user = userMgr.CurrentUser; BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission); try { string details = request["price_details"]; string desc = request["desc"]; string title = request["title"]; int shopId = 0; int.TryParse(request["shop_id"], out shopId); if (!string.IsNullOrEmpty(details)) { details = HttpUtility.UrlDecode(details); } JArray jDetails = JArray.Parse(details); BBuyPrice buyPrice = new BBuyPrice() { Desc = desc, Title = title, Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now) }; buyPrice.Shop = new BShop() { ID = buyManager.Shop.Shop_ID }; if (shopId > 0) { buyPrice.Shop = new BShop() { ID = shopId }; } buyPrice.Details = new List<BBuyPriceDetail>(); for (int i = 0; i < jDetails.Count(); i++) { JObject jDetail = (JObject)jDetails[i]; BBuyPriceDetail bDetail = new BBuyPriceDetail(); bDetail.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); bDetail.Price = (double)jDetail["price"]; bDetail.Product = new BProduct() { ID = (int)jDetail["sku_id"], ParentID = (int)jDetail["product_id"] }; bDetail.Supplier = new BSupplier() { ID = (int)jDetail["supplier_id"] }; buyPrice.Details.Add(bDetail); } bool result = buyManager.CreateBuyPrice(buyPrice); } catch (System.Data.Entity.Validation.DbEntityValidationException dbex) { message.Status = "failed"; message.Message = dbex.Message; } catch (KM.JXC.Common.KMException.KMJXCException kex) { message.Status = "failed"; message.Message = kex.Message; } catch (Exception ex) { message.Status = "failed"; message.Message = ex.Message; } finally { } return message; }
/// <summary> /// /// </summary> /// <param name="buyPrice"></param> /// <returns></returns> public bool SaveBuyPrice(BBuyPrice buyPrice) { bool result = false; if (this.CurrentUserPermission.CREATE_BUY_PRICE == 0) { throw new KMJXCException("没有权限创建采购询价单"); } if (buyPrice == null) { throw new KMJXCException("输入不正确"); } using (KuanMaiEntities db = new KuanMaiEntities()) { Buy_Price dbBuyPrice = null; bool isNew = false; if (buyPrice.ID > 0) { dbBuyPrice = (from price in db.Buy_Price where price.ID == buyPrice.ID select price).FirstOrDefault<Buy_Price>(); if (dbBuyPrice == null) { isNew = true; dbBuyPrice = new Buy_Price(); } } else { isNew = true; dbBuyPrice = new Buy_Price(); } dbBuyPrice.Title = buyPrice.Title; dbBuyPrice.Description = buyPrice.Desc; if (string.IsNullOrEmpty(dbBuyPrice.Description)) { dbBuyPrice.Description = ""; } if (isNew) { dbBuyPrice.Shop_ID = this.Shop.Shop_ID; if (buyPrice.Shop != null && buyPrice.Shop.ID > 0) { dbBuyPrice.Shop_ID = buyPrice.Shop.ID; } dbBuyPrice.User_ID = this.CurrentUser.ID; if (buyPrice.User != null && buyPrice.User.ID > 0) { dbBuyPrice.User_ID = buyPrice.User.ID; } if (buyPrice.Created <= 0) { dbBuyPrice.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); } dbBuyPrice.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); db.Buy_Price.Add(dbBuyPrice); } db.SaveChanges(); result = true; if (dbBuyPrice.ID > 0 && buyPrice.Details != null && buyPrice.Details.Count > 0) { result = result & this.SaveBuyPriceDetails(buyPrice.Details, dbBuyPrice.ID); } } return result; }