public IActionResult Create(ProductPriceViewModel productPriceViewModel) { productPriceViewModel.ProductId = productPriceViewModel.ProductId == 0 ? null : productPriceViewModel.ProductId; productPriceViewModel.PriceId = productPriceViewModel.PriceId == 0 ? null : productPriceViewModel.PriceId; if (ModelState.IsValid) { var productPrice = new ProductPrice { ProductId = productPriceViewModel.ProductId, PriceValue = productPriceViewModel.PriceValue, PriceId = productPriceViewModel.PriceId }; _work.ProductPrice.Add(productPrice); bool isSaved = _work.Save() > 0; if (isSaved) { return(Json(true)); } return(Json(false)); } return(Json(false)); }
/// <summary> /// Delete an entity. /// </summary> /// <param name="model"></param> public void Delete(ProductPriceViewModel model) { var entity = model.ToEntity(); this._ProductPricesRepository.Delete(entity); #region Commit Changes this._unitOfWork.Commit(); #endregion }
/// <summary> /// Throw an exception if name is exist. /// </summary> /// <param name="model">ProductPrice view model</param> public void ThrowExceptionIfExist(ProductPriceViewModel model) { ConditionFilter <ProductPrice, long> condition = new ConditionFilter <ProductPrice, long> { Query = (entity => entity.Name == model.Name && entity.Id != model.Id) }; var existEntity = this._ProductPricesRepository.Get(condition).FirstOrDefault(); if (existEntity != null) { throw new ItemAlreadyExistException(); } }
/// <summary> /// Update an entity. /// </summary> /// <param name="model"></param> /// <returns></returns> public ProductPriceViewModel Update(ProductPriceViewModel model) { this.ThrowExceptionIfExist(model); var entity = model.ToEntity(); entity = this._ProductPricesRepository.Update(entity); #region Commit Changes this._unitOfWork.Commit(); #endregion model = entity.ToModel(); return(model); }
public HttpResponseMessage GetProductPrice(QueryProductPrice value) { ProductPriceViewModel message = new ProductPriceViewModel(); string restr = ""; if (ModelState.IsValid) { try { _logger.WriteLog_Info <ECMALL商品价格请求>(JsonConvert.SerializeObject(value), null, "请求", null); WebClient client = new WebClient(); client.Headers.Add("Content-Type", "application/json;charset=utf8"); //IsoDateTimeConverter iso = new IsoDateTimeConverter(); //iso.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; string update = JsonConvert.SerializeObject(value); byte[] reByte_Api = client.UploadData(_ISetting.oms.Base_Url + "/api/Product/GetProductPrice", "Post", Encoding.UTF8.GetBytes(update)); restr = Encoding.UTF8.GetString(reByte_Api); _logger.WriteLog_Info <ECMALL商品价格请求>(restr, null, "return", null); } catch (Exception ex) { _logger.WriteLog_Error <ECMALL商品价格请求>(JsonConvert.SerializeObject(value), null, "2", ex); //api_message.MessageCode = ((int)m_Code.Faile).ToString(); message.success = false; message.msg = "oms连接错误"; restr = JsonConvert.SerializeObject(message); } } else { var modelstate = BadRequest(ModelState); string returestr = ""; foreach (var item in modelstate.ModelState.Keys) { returestr += "Key:" + item + "value:" + (modelstate.ModelState?[item].Errors != null ? (modelstate.ModelState?[item].Errors?[0].ErrorMessage + " " + modelstate.ModelState?[item].Errors?[0].Exception?.Message) : "");// item.Errors != null ? item.Errors[0].ErrorMessage + "\r\n" : ""; } //api_message.ErrorMsg = returestr; //api_message.MessageCode = ((int)m_Code.Faile).ToString(); message.msg = returestr; message.success = false; restr = JsonConvert.SerializeObject(message); _logger.WriteLog_Error <ECMALL商品价格请求>(JsonConvert.SerializeObject(value), null, "3", null); _logger.WriteLog_Error <ECMALL商品价格请求>(JsonConvert.SerializeObject(message), "4", null, null); } return(new HttpResponseMessage { Content = new StringContent(restr, Encoding.UTF8) }); }