public object Put(EnquiryModel model) { if (model == null) { return Failed("询价为空"); } var item = _enquiryService.GetEnquiry(model.Id); if (item == null || item.IsDeleted) { return Failed("找不到数据"); } item.Price = model.Price; try { _enquiryService.Update(); //todo 发送邮件 return Success(); } catch (Exception ex) { return Failed(ex.Message); } }
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); } }