コード例 #1
0
        public SaveProductRes SaveProduct(SaveProductReq saveProductReq)
        {
            var result = new SaveProductRes()
            {
                Result  = 0,
                Message = $"Đã xảy ra lỗi, vui lòng thử lại sau."
            };

            try
            {
                DynamicParameters parameters = new DynamicParameters();
                parameters.Add(@"ID", saveProductReq.ID);
                parameters.Add(@"ProductName", saveProductReq.ProductName);
                parameters.Add(@"BrandID", saveProductReq.BrandID);
                parameters.Add(@"CategoryID", saveProductReq.CategoryID);
                parameters.Add(@"Price", saveProductReq.Price);
                var response = SqlMapper.ExecuteScalar <int>(con, "proc_SaveProduct", param: parameters, commandType: CommandType.StoredProcedure);
                result.Result  = response;
                result.Message = saveProductReq.ID != 0 ?
                                 $"Sản phẩm đã được tạo thành công." :
                                 $"Sản phẩm đã được cập nhật thành công";
                return(result);
            }
            catch (Exception ex)
            {
                return(result);
            }
        }
コード例 #2
0
        public async Task <SaveProductRes> Save(SaveProductReq request)
        {
            var result = new SaveProductRes()
            {
                ProductId = 0,
                Message   = "Something went wrong, please contact administrator."
            };

            try
            {
                DynamicParameters parameters = new DynamicParameters();
                parameters.Add("@ProductId", request.ProductId);
                parameters.Add("@ProductName", request.ProductName);
                parameters.Add("@Price", request.Price);
                parameters.Add("@AvatarPath", request.AvatarPath);
                parameters.Add("@CategoryId", request.CategoryId);
                parameters.Add("@AquariumSizeId", request.AquariumSizeId);
                parameters.Add("@Status", request.Status);

                result = await SqlMapper.QueryFirstOrDefaultAsync <SaveProductRes>(cnn : connection,
                                                                                   sql : "sp_SaveProduct",
                                                                                   param : parameters,
                                                                                   commandType : CommandType.StoredProcedure);

                return(result);
            }
            catch (Exception)
            {
                return(result);
            }
        }
コード例 #3
0
        public async Task <Response> Save(SaveProductReq request)
        {
            var result = new Response()
            {
                Id      = 0,
                Message = "Something went wrong, please contact administrator."
            };

            try
            {
                DynamicParameters parameters = new DynamicParameters();
                parameters.Add("@Id", request.Id);
                parameters.Add("@ProductName", request.Productname);
                parameters.Add("@CategoryId", request.CategoryId);
                parameters.Add("@BrandId", request.BrandId);
                parameters.Add("@Price", request.Price);
                parameters.Add("@Description", request.Description);
                parameters.Add("@StatusProduct", request.StatusProduct);
                parameters.Add("@DateofSale", request.DateofSale);
                parameters.Add("@UserId", request.UserId);
                parameters.Add("@Image", request.Image);
                parameters.Add("@Images", request.Images);

                result = await SqlMapper.QueryFirstOrDefaultAsync <Response>(cnn : connection, sql : "sp_SaveProduct", param : parameters, commandType : CommandType.StoredProcedure);

                return(result);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                return(result);
            }
        }
コード例 #4
0
 public async Task <SaveProductRes> Save(SaveProductReq request)
 {
     return(await productRepository.Save(request));
 }
コード例 #5
0
 public SaveProductRes SaveProduct([FromBody] SaveProductReq request)
 {
     return(productService.SaveProductRes(request));
 }
コード例 #6
0
 public SaveProductRes SaveProductRes(SaveProductReq saveProductReq)
 {
     return(productRepository.SaveProduct(saveProductReq));
 }
コード例 #7
0
        public async Task <OkObjectResult> Save(SaveProductReq request)
        {
            var result = await productService.Save(request);

            return(Ok(result));
        }