public object Post(EnquiryModel model)
        {
            if (model == null)
            {
                return Failed("询价不得为空");
            }
            if (model.CustomerModel == null || model.ProductModel == null)
            {
                return Failed("产品或者客户不得为空");
            }
            if (string.IsNullOrEmpty(model.ProductModel.PartNumber))
            {
                return Failed("料号不得为空");
            }
            var customer = _customerService.GetCustomer(model.CustomerModel.Id);
            if (customer == null)
            {
                return Failed("找不到客户");
            }
            var product =
               _productService.GetProducts().FirstOrDefault(n => n.PartNumber == model.ProductModel.PartNumber.Trim());
            if (product == null)
            {
                if (_productService.GetProducts().Any(n => n.PartNumber == model.ProductModel.PartNumber.Trim()))
                {

                    return Failed("料号已存在");
                }
                product = new Product
                {
                    Id = Guid.NewGuid(),
                    PartNumber = model.ProductModel.PartNumber.Trim(),
                    ProductType = string.IsNullOrEmpty(model.ProductModel.ProductType)
                            ? model.ProductModel.ProductType
                            : model.ProductModel.ProductType.Trim().ToUpper(),
                    Voltage =
                        string.IsNullOrEmpty(model.ProductModel.Voltage)
                            ? model.ProductModel.Voltage
                            : model.ProductModel.Voltage.Trim(),
                    Capacity =
                        string.IsNullOrEmpty(model.ProductModel.Capacity)
                            ? model.ProductModel.Capacity
                            : model.ProductModel.Capacity.Trim(),
                    Pitch =
                        string.IsNullOrEmpty(model.ProductModel.Pitch)
                            ? model.ProductModel.Pitch
                            : model.ProductModel.Pitch.Trim(),
                    Level =
                        string.IsNullOrEmpty(model.ProductModel.Level)
                            ? model.ProductModel.Level
                            : model.ProductModel.Level.Trim(),
                    SpecificDesign =
                        string.IsNullOrEmpty(model.ProductModel.SpecificDesign)
                            ? model.ProductModel.SpecificDesign
                            : model.ProductModel.SpecificDesign.Trim(),

                };
                _productService.Insert(product);
            }
            var currentDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            var currentPosition =
                _employeesService.GetEmployee(HttpContext.Current.User.Identity.GetUser().EmployeeId)
                    .EmployeePostions.Where(
                        n => n.StartDate <= currentDate && (n.EndDate == null || n.EndDate >= currentDate) && n.IsDeleted == false)
                    .Select(n => n.Position)
                    .FirstOrDefault();
            if (currentPosition == null)
            {
                return Failed("找不到相关职位");
            }
            try
            {
                _enquiryService.Insert(new Enquiry
                {
                    Id = Guid.NewGuid(),
                    CustomerId = customer.Id,
                    ProductId = product.Id,
                    PositionId = currentPosition.Id
                });
                return Success();
            }
            catch (Exception ex)
            {
                return Failed(ex.Message);
            }
        }
Esempio n. 2
0
 public void Insert(Product product)
 {
     DbContext.Products.Add(product);
     Update();
 }
        public object Post(ProductModel model)
        {
            if (model == null)
            {
                return Failed("产品不能为空");
            }
            if (string.IsNullOrEmpty(model.PartNumber))
            {
                return Failed("料号不能为空");
            }
            if (_productService.GetProducts().Any(n => n.PartNumber == model.PartNumber.Trim()))
            {

                return Failed("料号不能重复");
            }
            var item = new Product
            {
                Id = Guid.NewGuid(),
                PartNumber = model.PartNumber.Trim().ToUpper(),
                ProductType = string.IsNullOrEmpty(model.ProductType) ? model.ProductType : model.ProductType.Trim().ToUpper(),
                Voltage = string.IsNullOrEmpty(model.Voltage) ? model.Voltage : model.Voltage.Trim(),
                Capacity = string.IsNullOrEmpty(model.Capacity) ? model.Capacity : model.Capacity.Trim(),
                Pitch = string.IsNullOrEmpty(model.Pitch) ? model.Pitch : model.Pitch.Trim(),
                Level = string.IsNullOrEmpty(model.Level) ? model.Level : model.Level.Trim(),
                SpecificDesign =
                    string.IsNullOrEmpty(model.SpecificDesign) ? model.SpecificDesign : model.SpecificDesign.Trim(),
                Price = model.Price
            };
            try
            {
                _productService.Insert(item);
            }
            catch (Exception ex)
            {
                return Failed(ex.Message);
            }
            return Success();
        }