public async Task <ProductIdDTO> ActionProductShopMan(ProductIdDTO productIdDTO, string Action) { ProductIdDTO output = new ProductIdDTO(); var jwt = JsonConvert.DeserializeObject <SumProfileResponseDTO>(_httpContextAccessor.HttpContext.Request.Cookies["JWT"]); if (jwt != null) { _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwt.JWT); productIdDTO.UserId = jwt.UserId; productIdDTO.ProductBrandId = jwt.ProductBrandId; string apiUrl = $"/api/v1/Product/ActionProductShopMan"; string paramRequest = $"?Action={Action}"; var json = JsonConvert.SerializeObject(productIdDTO, Formatting.Indented); var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); var response = await _client.PostAsync(apiUrl + paramRequest, stringContent); if (response.IsSuccessStatusCode) { string responseStream = await response.Content.ReadAsStringAsync(); output = JsonConvert.DeserializeObject <ProductIdDTO>(responseStream); } } return(output); }
public async Task <JsonResult> ActionProductShopMan(ProductIdDTO productIdDTO, string ActionString) { if (ActionString == "R") { var checkRenew = await _repoWrapper.Product.CheckRenewProduct(); if (checkRenew.ErrorCode == "00" || checkRenew.ErrorCode == "0") { var result = await _repoWrapper.Product.ActionProductShopMan(productIdDTO, ActionString); return(Json(result)); } else { return(Json(checkRenew)); } } else { if (ActionString == "K") { var result = await _repoWrapper.Product.ActionProductShopMan(productIdDTO, ActionString); return(Json(result)); } else { var result = await _repoWrapper.Product.ActionProductShopMan(productIdDTO, ActionString); return(Json(result.Message)); } } }
public async Task <JsonResult> ActionProductCanclePost(string ids, string ActionString) { ProductIdDTO ProductIdDTO = new ProductIdDTO(); if (ActionString == "H") { if (String.IsNullOrEmpty(ids)) { return(Json("Hủy tin đăng thất bại")); } var idArr = ids.Split(',').ToList(); foreach (var id in idArr) { var productId = Int32.Parse(id); ProductIdDTO.ProductId = productId; var result = await _repoWrapper.Product.ActionProductShopMan(ProductIdDTO, ActionString); } return(Json("00")); } else { if (ActionString == "D") { if (String.IsNullOrEmpty(ids)) { return(Json("Xóa tin đăng thất bại")); } var idArr = ids.Split(',').ToList(); foreach (var id in idArr) { var productId = Int32.Parse(id); ProductIdDTO.ProductId = productId; var result = await _repoWrapper.Product.ActionProductShopMan(ProductIdDTO, ActionString); } return(Json("00")); } else { return(Json("Thất bại")); } } }
public async Task <ProductIdDTO> ActionProductShopMan(ProductIdDTO model, string Action) { _logger.LogDebug($"ActionProductShopMan: model : " + JsonConvert.SerializeObject(model) + " Action: " + Action); var output = new ProductIdDTO(); output = model; try { var UserId = Guid.Parse(model.UserId); var checkProd = _repoWrapper.Product.FirstOrDefault(p => p.Product_ID == model.ProductId && p.CreateBy == UserId); if (checkProd != null) { if (Action == "R")// Renew { var checkRenew = await _repoWrapper.Product.CheckRenewProductByBrandId(model); if (checkRenew != null) { var brand = await _repoWrapper.Brand.FirstOrDefaultAsync(p => p.CreateBy == UserId); if (brand != null) { int productBrandType = brand.ProductBrandType_ID ?? 1; if (productBrandType == 1) { output.ErrorCode = "02"; // mapping client output.Message = $"Gian hàng của bạn không có quyền làm mới, Bạn cần nâng cấp gian hàng để có quyền này!"; } else { var QtyRenew = await _repoPaymentWrapper.PaymentServcie.FirstOrDefaultAsync(p => p.ServiceId == productBrandType); { if (checkRenew.NumberRenewInOneDay < QtyRenew.ReceiveFromCus) { var result = await _repoWrapper.Product.ActionProductShopman(model, Action); var countRenew = checkRenew.NumberRenewInOneDay == 1 ? 1 : checkRenew.NumberRenewInOneDay + 1; output.ErrorCode = "00"; output.Message = $"Số lần làm mới trong ngày {countRenew} / {QtyRenew.ReceiveFromCus}"; } else { output.ErrorCode = "01"; output.Message = $"Ban đã đạt giới hạn làm mới tin trong ngày ({QtyRenew.ReceiveFromCus} tin), hãy thử lại vào ngày mai"; } } } } } } else if (Action == "K") { var brand = await _repoWrapper.Brand.FirstOrDefaultAsync(p => p.CreateBy == UserId); var checkCountProd = await _repoWrapper.Product.CountProductByBrand(brand.ProductBrand_ID); var QtyPost = await _repoPaymentWrapper.PaymentServcie.FirstOrDefaultAsync(p => p.ServiceId == brand.ProductBrandType_ID); if (checkCountProd >= QtyPost.ProductQty) { output.ErrorCode = "02"; output.Message = $"Tin đăng đã vượt quá số lượng {QtyPost.ProductQty} bạn cần nâng cấp gian hàng để khôi phục tin đăng"; } else { var result = await _repoWrapper.Product.ActionProductShopman(model, Action); output.ErrorCode = result.ErrorCode; output.Message = result.Message; } } else { var result = await _repoWrapper.Product.ActionProductShopman(model, Action); output.ErrorCode = result.ErrorCode; output.Message = result.Message; } } else { output.ErrorCode = "001"; output.Message = "Không tồn tại: " + model.ProductId; } } catch (Exception ex) { _logger.LogError($"ActionProductShopMan: {ex.ToString()}"); output.ErrorCode = "001"; output.Message = "Có lỗi trong quá trình cập nhật"; } return(output); }