Esempio n. 1
0
        public int Add(ProductAddRequest model, int userId)
        {
            int id = 0;

            Guid guid = Guid.NewGuid();

            string procName = "[dbo].[Products_Insert]";

            _data.ExecuteNonQuery(procName,
                                  inputParamMapper : delegate(SqlParameterCollection col)
            {
                AddCommonParams(model, col);
                col.AddWithValue("@CreatedBy", userId);
                col.AddWithValue("@SKU", guid);
                SqlParameter idOut = new SqlParameter("@Id", SqlDbType.Int);
                idOut.Direction    = ParameterDirection.Output;

                col.Add(idOut);
            },
                                  returnParameters : delegate(SqlParameterCollection returnCollection)
            {
                object oId = returnCollection["@Id"].Value;

                Int32.TryParse(oId.ToString(), out id);
            });
            return(id);
        }
Esempio n. 2
0
        public async Task <ProductDTO> Add(ProductAddRequest model)
        {
            var oProduct = _mapper.Map <Product>(model);

            if (model.Image != null)
            {
                string mainRoute  = @"C:\ApiProducts\Files\Images";
                string imgName    = Guid.NewGuid().ToString() + Path.GetExtension(model.Image.FileName);
                string finalRoute = Path.Combine(mainRoute, imgName);

                Directory.CreateDirectory(mainRoute);

                using (var fs = new FileStream(finalRoute, FileMode.Create))
                {
                    await model.Image.CopyToAsync(fs);

                    oProduct.ImageRoute = finalRoute;
                }
            }

            oProduct.ProductStatusId = 1;

            var ok = await _repository.Add(oProduct);

            if (ok)
            {
                return(_mapper.Map <ProductDTO>(oProduct));
            }

            return(null);
        }
        private void Insert(ProductAddRequest productAdd)
        {
            var product = _context.Set <Product_List>();

            product.Add(new Product_List {
                p_name = productAdd.p_name, p_price = productAdd.p_price, p_desc = productAdd.p_desc
            });
            _context.SaveChanges();
        }
Esempio n. 4
0
        /// <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 async Task AddProduct(ProductAddRequest productAddRequest)
        {
            var product = new Product()
            {
                Name = productAddRequest.Name, Price = productAddRequest.Price
            };

            await this.repository.Insert <Product>(product);

            await this.repository.Save();
        }
        public HttpResponseMessage Add(ProductAddRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Modal is not Valid"));
            }
            ItemResponse <int> responseBody = new ItemResponse <int>();
            UserBase           user         = _authService.GetCurrentUser();
            int userId = user.Id;

            responseBody.Item = _service.Insert(model, userId);
            return(Request.CreateResponse(HttpStatusCode.Created, responseBody));
        }
        public async Task AddProductAsync(ProductAddRequest customerRequest)
        {
            _nullCheckMethod.CheckIfRequestIsNull(customerRequest);

            var product = await _unitOfWork.Products.GetProductByModelAsync(customerRequest.Model);

            _nullCheckMethod.CheckIFObjectAlreadyExist(product);

            var _product = Mapper.Map <Product>(customerRequest);

            _unitOfWork.Products.AddProduct(_product);
            await _unitOfWork.CompleteAsync();
        }
Esempio n. 8
0
 public IHttpActionResult Post(ProductAddRequest model)
 {
     try
     {
         ItemResponse <int> response = new ItemResponse <int>
         {
             Item         = _productService.Insert(model),
             IsSuccessful = true
         };
         return(Ok(response));
     }
     catch (Exception ex) { return(BadRequest(ex.Message)); }
 }
        public ProductResponse Any(ProductAddRequest request)
        {
            if (Validator != null)
            {
                Validator.ValidateAndThrow(request, ApplyTo.Post);
            }

            OnBeforeProductAddRequest(request);

            var output = Repository.Create(request);

            OnAfterProductAddRequest(request, output);
            return(output);
        }
        public HttpResponseMessage Add(ProductAddRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
            ItemResponse <int> response = new ItemResponse <int>();

            string userId = _userService.GetCurrentUserId();

            response.Item = _productService.Insert(model, userId);

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Esempio n. 11
0
 private static void AddCommonParams(ProductAddRequest model, SqlParameterCollection col)
 {
     col.AddWithValue("@Manufacturer", model.Manufacturer);
     col.AddWithValue("@Year", model.Year);
     col.AddWithValue("@Name", model.Name);
     col.AddWithValue("@Description", model.Description);
     col.AddWithValue("@ProductTypeId", model.ProductTypeId);
     col.AddWithValue("@VendorId", model.VendorId);
     col.AddWithValue("@ConditionTypeId", model.ConditionTypeId);
     col.AddWithValue("@IsVisible", model.IsVisible);
     col.AddWithValue("@IsActive", model.IsActive);
     col.AddWithValue("@PrimaryImage", model.PrimaryImage);
     col.AddWithValue("@Specifications", model.Specifications);
 }
        public async Task <ProductAddResponse> Add(ProductAddRequest request)
        {
            var product = request.ProductToAdd.MapToModel();

            product.Fields = request.ProductToAdd.Fields.MapToModel();
            await base.BaseBeforeAddAsync(product, request.RequestOwner);

            await _productFacade.AddAsync(product);

            await base.BaseAfterAddAsync(product, request.RequestOwner);

            return(new ProductAddResponse()
            {
                Access = ResponseAccess.Granted
            });
        }
Esempio n. 13
0
        public int Insert(ProductAddRequest model)
        {
            int id = 0;

            Adapter.ExecuteQuery("Product_Product_Insert", new[] {
                SqlDbParameter.Instance.BuildParameter("@Name", model.Name, System.Data.SqlDbType.NVarChar),
                SqlDbParameter.Instance.BuildParameter("@ProductListingId", model.ProductListingId, System.Data.SqlDbType.Int),
                SqlDbParameter.Instance.BuildParameter("@Description", model.Description, System.Data.SqlDbType.NVarChar),
                SqlDbParameter.Instance.BuildParameter("@ProductAvatar", model.ProductAvatar, System.Data.SqlDbType.NVarChar),
                SqlDbParameter.Instance.BuildParameter("@UserBaseId", model.UserBaseId, System.Data.SqlDbType.Int),
                SqlDbParameter.Instance.BuildParameter("@Id", id, System.Data.SqlDbType.Int, 0, ParameterDirection.Output)
            }, (parameters =>
            {
                id = parameters.GetParmValue <int>("@Id"); //for inserts
            }));
            return(id);
        }
        public ProductResponse Create(ProductAddRequest request)
        {
            using (var adapter = DataAccessAdapterFactory.NewDataAccessAdapter())
            {
                OnBeforeProductAddRequest(adapter, request);

                var entity = request.FromDto();
                entity.IsNew = true;

                if (adapter.SaveEntity(entity, true))
                {
                    OnAfterProductAddRequest(adapter, request);
                    return(new ProductResponse(entity.ToDto()));
                }
            }

            throw new InvalidOperationException();
        }
Esempio n. 15
0
        public async Task <IActionResult> AddProduct(ProductAddRequest productAddRequest)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await _productService.AddProductAsync(productAddRequest);

                    return(RedirectToAction("Index", "Product"));
                }

                return(View(productAddRequest));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Esempio n. 16
0
        public virtual IHttpActionResult Add(ProductAddRequest request)
        {
            var entity = new Product
            {
            };
            var result = _productService.Add(entity);

            if (result > 0)
            {
                return(Succeed(new ProductAddResponse
                {
                    Id = entity.Id
                }, "新增成功"));
            }
            else
            {
                return(Fail("新增失败"));
            }
        }
        public RespondModel AddProduct(ProductAddRequest productadd)
        {
            RespondModel modelRespond = new RespondModel();

            try
            {
                if (productadd.p_price.GetType() != typeof(int) || productadd.p_price <= 0)
                {
                    modelRespond.status  = "validate";
                    modelRespond.message = "request product price";
                    return(modelRespond);
                }

                if (string.IsNullOrEmpty(productadd.p_name))
                {
                    modelRespond.status  = "validate";
                    modelRespond.message = "request product name";
                    return(modelRespond);
                }

                if (string.IsNullOrEmpty(productadd.p_desc))
                {
                    modelRespond.status  = "validate";
                    modelRespond.message = "request product desc";
                    return(modelRespond);
                }

                Insert(productadd);

                modelRespond.status  = "success";
                modelRespond.message = "insert product success";
            }
            catch (Exception ex)
            {
                modelRespond.status  = "errortrycatch";
                modelRespond.message = ex.ToString();
            }

            return(modelRespond);
        }
Esempio n. 18
0
        public int Insert(ProductAddRequest data, int userId)
        {
            using (var con = GetConnection())
            {
                var cmd = con.CreateCommand();
                cmd.CommandText = "Products_Insert";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Title", data.Title);
                cmd.Parameters.AddWithValue("@Body", data.Body);
                cmd.Parameters.AddWithValue("@Price", data.Price);
                cmd.Parameters.AddWithValue("@ContactPerson", data.ContactPerson);
                cmd.Parameters.AddWithValue("@CompanyId", data.CompanyId);
                cmd.Parameters.AddWithValue("@PhoneNumber", data.PhoneNumber);
                cmd.Parameters.AddWithValue("@PhotoUrl", data.PhotoUrl);
                cmd.Parameters.AddWithValue("@UserId", userId);

                cmd.Parameters.Add("@Id", SqlDbType.Int).Direction = ParameterDirection.Output;

                cmd.ExecuteNonQuery();

                return((int)cmd.Parameters["@Id"].Value);
            }
        }
Esempio n. 19
0
        public ActionResult <ItemResponse <int> > Create(ProductAddRequest model)
        {
            ObjectResult result = null;
            int          userId = _authService.GetCurrentUserId();

            try
            {
                int id = _service.Add(model, userId);
                ItemResponse <int> response = new ItemResponse <int>()
                {
                    Item = id
                };
                result = Created201(response);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.ToString());
                ErrorResponse response = new ErrorResponse($"Generic Error: {ex.Message}");
                result = StatusCode(500, response);
            }

            return(result);
        }
        public IActionResult Add([FromBody] ProductAddRequest productadd)
        {
            var respond = _BLProduct.AddProduct(productadd);

            return(Ok(respond));
        }
Esempio n. 21
0
 public ProductAddCommand(ProductAddRequest product)
 {
     _product = product;
 }
Esempio n. 22
0
 /// <summary>
 /// 添加产品信息
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public ProductAddResponse AddProduct(ProductAddRequest request)
 {
     return(ApiRequestHelper.Post <ProductAddRequest, ProductAddResponse>(request));
 }
 partial void OnAfterProductAddRequest(IDataAccessAdapter adapter, ProductAddRequest request);
 /// <summary>
 /// taobao.product.add
 /// 上传一个产品,不包括产品非主图和属性图片(B商家专用)
 /// </summary>
 /// <param name="cid">必填 商品类目ID.调用taobao.itemcats.get获取;注意:必须是叶子类目 id. </param>
 /// <param name="imagefilepath">必填 产品主图片,本地文件路径 支持的文件类型:gif,jpg,png,jpeg</param>
 /// <param name="outerid">外部产品ID </param>
 /// <param name="props">属性,属性值的组合.格式:pid:vid;pid:vid;</param>
 /// <param name="binds">非关键属性结构:pid:vid;pid:vid. 最大支持512字节</param>
 /// <param name="saleprops">销售属性结构:pid:vid;pid:vid</param>
 /// <param name="customerprops">用户自定义属性,结构:pid1:value1;pid2:value2</param>
 /// <param name="price">产品市场价.精确到2位小数;单位为元.如:200.07</param>
 /// <param name="name">产品名称,最大30个字符</param>
 /// <param name="desc">产品描述.最大不超过25000个字符 </param>
 /// <param name="major">是不是主图 默认true</param>
 /// <param name="markettime">上市时间。目前只支持鞋城类目传入此参数</param>
 /// <param name="propertyalias"销售属性值别名。格式为pid1:vid1:alias1;pid1:vid2:alia2。只有少数销售属性值支持传入别名,比如颜色和尺寸></param>
 /// <param name="pakinglist">包装清单。注意,在管控类目下,包装清单不能为空,同时保证清单的格式为: 名称:数字;名称:数字; 其中,名称不能违禁、不能超过60字符,数字不能超过999 </param>
 /// <param name="extraingo">存放产品扩展信息,由List(ProductExtraInfo)转化成jsonArray存入. </param>
 /// <param name="markid">市场ID,1为新增C2C市场的产品信息, 2为新增B2C市场的产品信息。 不填写此值则C用户新增B2C市场的产品信息,B用户新增B2C市场的产品信息。</param>
 /// <param name="sellpt">商品卖点描述,长度限制为20个汉字 </param>
 /// <returns></returns>
 public static Product AddProduct(long? cid, string imagefilepath, string outerid, string props, string binds, string saleprops, string customerprops,
     string price, string name, string desc, bool? major, DateTime markettime, string propertyalias,
     string pakinglist, string extraingo, string markid, string sellpt)
 {
     ITopClient client = TopClientService.GetTopClient();
     ProductAddRequest req = new ProductAddRequest();
     req.Cid = cid;
     FileItem fItem = new FileItem(imagefilepath);
     req.Image = fItem;
     req.OuterId = outerid;
     req.Props = props;
     req.Binds = binds;
     req.SaleProps = saleprops;
     req.CustomerProps = customerprops;
     req.Price = price;
     req.Name = name;
     req.Desc = desc;
     req.Major = major;
     req.MarketTime = markettime;
     req.PropertyAlias = propertyalias;
     req.PackingList = pakinglist;
     req.ExtraInfo = extraingo;
     req.MarketId = markid;
     req.SellPt = sellpt;
     ProductAddResponse response = client.Execute(req, SessionKey);
     return response.Product;
 }
Esempio n. 25
0
        public IActionResult AddProduct([FromBody] ProductAddRequest request)
        {
            if (request == null)
            {
                return(BadRequest());
            }
            if (request.Price < 0.01M || request.DiscountedPrice < 0)
            {
                return(BadRequest("Bad price entered"));
            }
            var product = new Product()
            {
                Description     = request.Description,
                DisplayName     = request.DisplayName,
                DiscountedPrice = request.DiscountedPrice,
                Price           = request.Price,
                IsFeatured      = request.IsFeatured,
                IsEnabled       = request.IsEnabled
            };

            var productContext = _dbContext.Set <Product>();
            var imageList      = new List <Image>();

            if (!string.IsNullOrEmpty(request.Thumbnail))
            {
                var thumbnail = new Image()
                {
                    Product     = product,
                    ImageBase64 = request.Thumbnail,
                    Type        = ImageTypeEnum.Thumbnail
                };
                imageList.Add(thumbnail);
            }
            if (request.Images.Count == 1)
            {
                var image = new Image()
                {
                    Product     = product,
                    ImageBase64 = request.Images.FirstOrDefault(),
                    Type        = ImageTypeEnum.MainImage
                };
                imageList.Add(image);
            }
            else if (request.Images.Count > 1)
            {
                var mainImage = new Image()
                {
                    Product     = product,
                    ImageBase64 = request.Images.FirstOrDefault(),
                    Type        = ImageTypeEnum.MainImage
                };
                imageList.Add(mainImage);
                request.Images.Remove(request.Images.FirstOrDefault());
                foreach (var tempImage in request.Images)
                {
                    var image = new Image()
                    {
                        Product     = product,
                        ImageBase64 = tempImage,
                        Type        = ImageTypeEnum.OtherImage
                    };
                    imageList.Add(image);
                }
            }

            product.Images = imageList;

            productContext.Add(product);

            var result = _dbContext.SaveChanges();

            if (result > 0)
            {
                product.Images = null;
                return(Ok(product));
            }

            return(BadRequest("Nothing changed in database"));
        }
 public ProductAddResponse AddProducts(ProductAddRequest request)
 {
     return(ProductBll.Instance.ProductAdd(request));
 }
Esempio n. 27
0
 /// <summary>
 /// 添加产品信息
 /// </summary>
 /// <returns></returns>
 public JsonResult AddProduct(ProductAddRequest addRequest)
 {
     return(Json(ProductBll.Instance.AddProduct(addRequest)));
 }
 partial void OnAfterProductAddRequest(ProductAddRequest request, ProductResponse response);
 partial void OnBeforeProductAddRequest(ProductAddRequest request);
Esempio n. 30
0
        public async Task <IActionResult> ProductAdd(ProductAddRequest product)
        {
            var result = await _mediator.Send(new ProductAddCommand(product));

            return(Ok(result));
        }
Esempio n. 31
0
        public async Task <IActionResult> AddProduct(ProductAddRequest productAddRequest)
        {
            await productService.AddProduct(productAddRequest);

            return(Ok());
        }