public async Task <IActionResult> GetCartDetailsByUserId() { try { //Doubt returning only productid and quantity is sufficient or we have to fetch the products as well? //Doubt when user added items it was possible then the items sold out. This case is left to be handled. Guid userId = Guid.Parse(User.Identity.Name); var response = await _cartBAL.GetCartByUserId(userId); return(Ok(_mapper.Map <CartViewModel>(response))); } catch (Exception ex) { ExceptionLogging.SendErrorToText(ex); return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); } }
public async Task <int> UpdateToCart([FromBody] List <Cart> obj) { try { var res = -1; List <Cart> lst = new List <Cart>(); if (obj[0].SetNo > 0) { lst = _ICartBAL.GetCartByUserId(obj[0]).Result; } foreach (var item in obj) { if (item.SetNo > 0) { List <Cart> lstselect = lst.Where(x => x.SetNo == item.SetNo && x.ProductId == item.ProductId).ToList(); if (lstselect.Count > 0) { foreach (var itemnew in lstselect) { Cart _obj = new Cart(); _obj.ProductSizeId = itemnew.ProductSizeId; _obj.Quantity = item.Quantity; _obj.UserID = item.UserID; res = await this._ICartBAL.AddToCart(_obj); } } } else { res = await this._ICartBAL.AddToCart(item); } } return(res); } catch (Exception ex) { ErrorLogger.Log($"Something went wrong inside CartController UpdateToCart action: {ex.Message}"); ErrorLogger.Log(ex.StackTrace); Logger.LogError($"Something went wrong inside CartController UpdateToCart action: {ex.Message}"); return(-1); } }