public IActionResult AddProductToCart(int productId, int quantity = 1) { ProductAddToOrderViewModel result; if (UserName == null) { //here the code for managing the un authorize customer to store cart in temp table with uniqe id and store the id in user cookie to retrive the data string tempCartId = httpContextAccessor.HttpContext.Request.Cookies["tempCartId"]; if (tempCartId == null || tempCartId == "") { Guid g = Guid.NewGuid(); tempCartId = g.ToString(); CookieOptions option = new CookieOptions(); option.Expires = DateTime.Now.AddDays(7); Response.Cookies.Append("tempCartId", tempCartId, option); } result = cartServices.addToTempCart(tempCartId, productId, quantity); } else { result = cartServices.addToCart(UserName, productId, quantity); } return(Json(result)); }