public async Task <PostProductShopManResultDTO> CreateProduct(PostProductShopManDTO postProductBrandDTO) { PostProductShopManResultDTO output = new PostProductShopManResultDTO(); var jwt = JsonConvert.DeserializeObject <SumProfileResponseDTO>(_httpContextAccessor.HttpContext.Request.Cookies["JWT"]); if (jwt != null) { _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwt.JWT); postProductBrandDTO.UserId = jwt.UserId; postProductBrandDTO.Product.SalePhone = jwt.Profile.PhoneNumber; postProductBrandDTO.Product.SaleEmail = jwt.Profile.Email; string apiUrl = $"/api/v1/Product/PostProductShopMan"; var json = JsonConvert.SerializeObject(postProductBrandDTO, Formatting.Indented); var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); var response = await _client.PostAsync(apiUrl, stringContent); if (response.IsSuccessStatusCode) { string responseStream = await response.Content.ReadAsStringAsync(); output = JsonConvert.DeserializeObject <PostProductShopManResultDTO>(responseStream); } } return(output); }
public async Task <PostProductShopManResultDTO> PostProductShopMan(PostProductShopManDTO model) { _logger.LogDebug($"PostProductShopMan: model : " + JsonConvert.SerializeObject(model)); var output = new PostProductShopManResultDTO(); if (model == null) { output.ErrorCode = "004"; output.Message = Utils.ConstMessage.GetMsgConst("004"); return(output); } else { try { Product productModel = _mapper.Map <Product>(model.Product); int ProductId = _repoWrapper.Product.PostProductShopman(productModel, model.MainImage, model.SubImage, model.UserId); if (ProductId != 0) { //Save MainImage SaveMainImage(model.MainImage, ProductId); //Save Sub Image SaveIllustrationImages(model.SubImage, ProductId); output.ProductId = ProductId; output.ErrorCode = "00"; output.Message = "Thêm mới thành công"; } else { output.Message = "001"; output.Message = Utils.ConstMessage.GetMsgConst("001"); } return(output); } catch (Exception ex) { _logger.LogError($"PostProductShopMan: " + ex.ToString()); output.ErrorCode = "001"; output.Message = Utils.ConstMessage.GetMsgConst("001"); return(output); } } }
public async Task <PostProductShopManResultDTO> PutProductShopMan(int ProductID, PostProductShopManDTO model, int IsRepair) { _logger.LogDebug($"PutProductShopMan: model : " + JsonConvert.SerializeObject(model) + " ProductID: " + ProductID); var output = new PostProductShopManResultDTO(); var checkCanEdit = _repoWrapper.Product.CanEditProduct(ProductID, model.UserId); //Check Can Edit if (!checkCanEdit) { output.ErrorCode = "PROD001"; output.Message = Utils.ConstMessage.GetMsgConst("PROD001"); return(output); } else { try { Product productModel = _mapper.Map <Product>(model.Product); productModel.Product_ID = ProductID; int ProductId = _repoWrapper.Product.PostProductShopman(productModel, model.MainImage, model.SubImage, model.UserId); if (ProductId != 0) { if (IsRepair == 1)// Tiếp tục chỉnh sửa delete subImage { var subImage = await _repoWrapper.ProductPicture.GetListDeleteProdPicture(ProductID); await _repoWrapper.Product.DeleteIllustrationImages(subImage); } //Save MainImage if (model.MainImage != null) { //Save MainImage SaveMainImage(model.MainImage, ProductId); } //Save Sub Image if (model.SubImage != null) { //Delete Image if (model.DeleteProdPicture != null) { await _repoWrapper.Product.DeleteIllustrationImages(model.DeleteProdPicture); } //Save Sub Image SaveIllustrationImages(model.SubImage, ProductId); } output.ProductId = ProductId; output.ErrorCode = "00"; output.Message = "Update thành công"; } else { output.ErrorCode = "001"; output.Message = Utils.ConstMessage.GetMsgConst("001"); } return(output); } catch (Exception ex) { _logger.LogError($"PutProductShopMan: " + ex.ToString()); output.ErrorCode = "001"; output.Message = Utils.ConstMessage.GetMsgConst("001"); return(output); } } }