/// <summary> /// 添加产品信息 /// </summary> /// <returns></returns> public ProductAddResponse ProductAdd(ProductAddRequest request) { ProductAddResponse response = new ProductAddResponse(); //非空判断 if (string.IsNullOrEmpty(request.Products.ProductName)) { response.Status = false; response.Message = "产品名称不能为空"; return(response); } if (request.Products.TradeId <= 0) { response.Status = false; response.Message = "请选择应用行业"; return(response); } if (request.Products.AddressId <= 0) { response.Status = false; response.Message = "请选择归属地"; return(response); } if (request.Products.StageId <= 0) { response.Status = false; response.Message = "请选择产品阶段"; return(response); } if (string.IsNullOrEmpty(request.Products.ProductDetail)) { response.Status = false; response.Message = "产品描述不能为空"; return(response); } if (request.Products.UserId <= 0) { response.Status = false; response.Message = "请选择产品经理"; return(response); } var res = ProductDal.Instance.AddProduct(request.Products); if (res > 0) { response.Status = true; response.Message = "添加成功"; } else { response.Status = false; response.Message = "添加失败"; } return(response); }
public ActionResult ProductAddComplete(Product product, HttpPostedFileBase PImage) { if (ModelState.IsValid) { product.Situation = SystemConstannts.Situation.BEKLEMEDE; product.Date = DateTime.Now; product.User_ID = (HttpContext.Session["User"] as User).ID; product.Image = PImage.FileName; HttpResponseMessage result; using (HttpClient client = new HttpClient()) { using (var content = new MultipartFormDataContent()) { byte[] Bytes = new byte[PImage.InputStream.Length + 1]; PImage.InputStream.Read(Bytes, 0, Bytes.Length); var fileContent = new ByteArrayContent(Bytes); fileContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment") { FileName = PImage.FileName }; content.Add(fileContent); client.DefaultRequestHeaders.Add(SystemConstannts.apiKey, SystemConstannts.apiValue); var requestUri = "http://localhost:2765/api/Product/AddProductImageToFolder"; result = client.PostAsync(requestUri, content).Result; } } if (result.StatusCode == HttpStatusCode.OK) { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:2765/"); client.DefaultRequestHeaders.Add(SystemConstannts.apiKey, SystemConstannts.apiValue); result = client.PostAsJsonAsync("api/Product/AddProduct", product).Result; } if (result.StatusCode == HttpStatusCode.OK) { string resultString = result.Content.ReadAsStringAsync().Result; if (resultString != "{\"Product\":null}") { ProductAddResponse addResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <ProductAddResponse>(resultString); if (addResponse.Code == 1) { return(RedirectToAction("MyProducts", "UserProfil")); } } } } } return(RedirectToAction("AddProduct")); }
public object AddProduct(Product product) { ProductAddResponse addResponse = new ProductAddResponse(); try { _productService.Add(product); addResponse.setError(Common.SystemConstants.SystemConstannts.ERROR_CODES.SUCCESS); addResponse.Product = product; } catch (Exception ex) { addResponse.setError(Common.SystemConstants.SystemConstannts.ERROR_CODES.SYSTEMERROR); addResponse.Product = null; } return(addResponse); }