コード例 #1
0
        public object Post(StandardCostModel model)
        {
            var errormessage = string.Empty;
            if (model == null)
            {
                errormessage = "报价不得为空";
            }
            else if (model.ProductModel == null || string.IsNullOrEmpty(model.ProductModel.PartNumber))
            {
                errormessage = "料号不能为空";
            }
            else if (model.QuotedTime == DateTime.MinValue)
            {
                errormessage = "报价日期不能为空";
            }
            else if (_standardCostService.GetStandardCosts().Any(n => n.Product.PartNumber == model.ProductModel.PartNumber && n.QuotedTime == model.QuotedTime))
            {
                errormessage = "报价不能重复";
            }

            if (string.IsNullOrEmpty(errormessage))
            {
                var product = _productService.GetProducts().FirstOrDefault(n => n.PartNumber == model.ProductModel.PartNumber);
                if (product == null || product.IsDeleted)
                {
                    errormessage = "找不到料号或料号被删除";
                }
                else
                {
                    var item = new StandardCost
                    {
                        Id = Guid.NewGuid(),
                        ProductId = product.Id,
                        Price = model.Price,
                        QuotedTime = model.QuotedTime,
                        Remark = model.Remark
                    };
                    try
                    {
                        _standardCostService.Insert(item);
                    }
                    catch (Exception ex)
                    {
                        return Failed(ex.Message);
                    }
                }
                
            }

            return string.IsNullOrEmpty(errormessage) ? Success() : Failed(errormessage);
        }
コード例 #2
0
        public object Put(StandardCostModel model)
        {
            var errormessage = string.Empty;
            if (model == null)
            {
                errormessage = "报价不得为空";
            }
            else if (model.ProductModel.Id == Guid.Empty)
            {
                errormessage = "产品不能为空";
            }
            else if (model.QuotedTime == DateTime.MinValue)
            {
                errormessage = "报价日期不能为空";
            }
            else
            {
                var item = _standardCostService.GetStandardCost(model.Id);
                if (item.IsDeleted)
                {
                    errormessage = "该报价已删除";
                }
                if (string.IsNullOrEmpty(errormessage))
                {
                    item.ProductId = model.ProductModel.Id;
                    item.Price = model.Price;
                    item.QuotedTime = model.QuotedTime;
                    item.Remark = model.Remark;
                    try
                    {
                        _standardCostService.Update();
                    }
                    catch (Exception ex)
                    {
                        errormessage = ex.Message;
                    }
                }
            }
            return string.IsNullOrEmpty(errormessage) ? Success() : Failed(errormessage);

        }