public void Update(UserBasket userBasket) { var updatedata = _dataContext.userBaskets.Find(userBasket.Id); updatedata.Quantity = userBasket.Quantity; _dataContext.SaveChanges(); }
public async Task AddItem(UserBasket newItem) { try { var userBasket = await basketCache.GetStringAsync(newItem.userId.ToString()); if (string.IsNullOrWhiteSpace(userBasket)) { // Se non esiste, creazione del carrello con elementi in input await SetBasket(newItem); userBasket = await basketCache.GetStringAsync(newItem.userId.ToString()); } else { // Se esiste, aggiunta al carrello degli elementi in input UserBasket cachedBasket = JsonConvert.DeserializeObject <UserBasket>(userBasket); foreach (var item in newItem.basketItems) { cachedBasket.basketItems.Add(item); } await SaveBasket(newItem.userId.ToString(), cachedBasket); } } catch (Exception ex) { throw ex; } }
public async Task AddItem(UserBasket newItem) { try { var userBasket = await basketCache.GetStringAsync(newItem.userId.ToString()); if (string.IsNullOrWhiteSpace(userBasket)) { await SetBasket(newItem); userBasket = await basketCache.GetStringAsync(newItem.userId.ToString()); } UserBasket cachedBasket = JsonConvert.DeserializeObject <UserBasket>(userBasket); foreach (var item in newItem.basketItems) { cachedBasket.basketItems.Add(item); } await SaveBasket(newItem.userId.ToString(), JsonConvert.SerializeObject(cachedBasket)); } catch (Exception ex) { throw ex; } }
public async Task <ActionResult> CompletePurchase(UserBasket items) { _context.basket.Add(items); await _context.SaveChangesAsync(); return(null); }
public async Task UpdateBasketFromUser(string user, int beerToAdd) { var coll = _db.GetCollection <UserBasket>("basket"); var item = coll.AsQueryable().FirstOrDefault(ub => ub.UserName == user); if (item == null) { var newBasket = new UserBasket() { BeerIds = new List <int> { beerToAdd }, UserName = user, LastUpdated = DateTime.UtcNow }; await coll.InsertOneAsync(newBasket); } else { await coll.UpdateOneAsync( Builders <UserBasket> .Filter.Eq(ub => ub.Id, item.Id), Builders <UserBasket> .Update.Set(ub => ub.LastUpdated, DateTime.UtcNow).Push(ub => ub.BeerIds, beerToAdd)); } }
public async Task <UserBasket> UpdateBasketAsync(UserBasket basket) { if (basket == null) { return(null); } var data = JsonSerializer.Serialize(basket); var existingBasket = await _context.Baskets.FirstOrDefaultAsync(p => p.Id == basket.Id); if (existingBasket == null) { // add new basket var newItem = new Basket(); newItem.Id = basket.Id; newItem.BasketData = data; newItem.LastUpdated = DateTimeOffset.Now; await _context.Baskets.AddAsync(newItem); await _context.SaveChangesAsync(); } else { // update existing basket existingBasket.BasketData = data; existingBasket.LastUpdated = DateTimeOffset.Now; _context.Baskets.Update(existingBasket); await _context.SaveChangesAsync(); } return(basket); }
private BasketDto MapToDto(UserBasket basket) { var items = basket.Items.Select(x => new KeyValuePair <int, double>(x.ProductId, x.Unit)); return(new BasketDto { User = basket.User, Items = new Dictionary <int, double>(items) }); }
public async Task SetBasket(UserBasket userBasket) { try { await SaveBasket(userBasket.userId.ToString(), userBasket); } catch (Exception ex) { throw ex; } }
public async Task <UserBasket> AddBasket() { UserBasket newUserBasket = new UserBasket(); //newProduct.UserId = _userService.GetUser().Id; newUserBasket.UserId = 1; // şimdilik 1 newUserBasket.Status = 0; await _unitOfWork.UserBaskets.AddAsync(newUserBasket); await _unitOfWork.CommitAsync(); return(newUserBasket); }
public async Task SetBasket(UserBasket userBasket) { try { var basketAsString = JsonConvert.SerializeObject(userBasket); await SaveBasket(userBasket.userId.ToString(), JsonConvert.SerializeObject(basketAsString)); } catch (Exception ex) { throw ex; } }
public void AddProduct <T>(T obj) { object[] _objects; if (obj is AnonymousBasket) { AnonymousBasket anon = obj as AnonymousBasket; _objects = new object[] { Enumerations.BasketType.Anonymous, anon.AnonymouseBasketID, anon.PackageID, anon.PurchasedUnits }; } else { UserBasket anon = obj as UserBasket; _objects = new object[] { Enumerations.BasketType.User, anon.UserID, anon.PackageID, anon.PurchasedUnits }; } SqlHelper.ExecuteNonQuery(Global.ConnectionString, "Basket_Add", _objects); }
public async Task <IActionResult> Register(RegisterViewModel rvm) { if (ModelState.IsValid) { ApplicationUser user = new ApplicationUser() { UserName = rvm.Email, Email = rvm.Email, FirstName = rvm.FirstName, LastName = rvm.LastName }; var result = await _userManager.CreateAsync(user, rvm.Password); UserBasket newUserBasket = new UserBasket(); newUserBasket.UserID = user.Email; _context.UserBasket.Add(newUserBasket); await _context.SaveChangesAsync(); if (result.Succeeded) { Claim fullNameClaim = new Claim("FullName", $"{user.FirstName} {user.LastName}"); Claim emailClaim = new Claim("Email", user.Email, ClaimValueTypes.Email); List <Claim> myclaims = new List <Claim>() { fullNameClaim, emailClaim }; await _userManager.AddClaimsAsync(user, myclaims); await _signInManager.SignInAsync(user, isPersistent : false); string subject = "Registration"; string msg = "<p>Thank you for registering for a new account with Bear Mountain</p>"; await _email.SendEmailAsync(rvm.Email, subject, msg); return(RedirectToAction("Index", "Home")); } } return(View()); }
public ActionResult Edit(UserBasket userBasket) { var usersesion = Session["user"]; if (usersesion == null) { return(RedirectToAction("Index", "Login")); } else { _userBasket.Update(userBasket); return(RedirectToAction("List")); } }
public bool Add(UserBasket obj) { var res = true; try { _context.UserBaskets.Add(obj); _context.SaveChanges(); } catch (Exception e) { res = false; } return(res); }
public async Task UpdateItem(int userId, int itemId, decimal newPrice) { try { var userBasket = await basketCache.GetStringAsync(userId.ToString()); UserBasket cachedBasket = JsonConvert.DeserializeObject <UserBasket>(userBasket); cachedBasket.basketItems.Single(itm => itm.menuItemId == itemId).price = newPrice; await SaveBasket(userId.ToString(), JsonConvert.SerializeObject(cachedBasket)); } catch (Exception ex) { throw ex; } }
public async Task UpdateItem(int userId, int itemId, bool available) { try { var userBasket = await basketCache.GetStringAsync(userId.ToString()); UserBasket cachedBasket = JsonConvert.DeserializeObject <UserBasket>(userBasket); cachedBasket.basketItems.Single(itm => itm.menuItemId == itemId).available = available; await SaveBasket(userId.ToString(), cachedBasket); } catch (Exception ex) { throw ex; } }
public ActionResult Index(UserBasket basket) { var user = Session["user"]; if (user == null) { return(RedirectToAction("Index", "Login")); } else { basket.UserName = Session["user"].ToString(); basket.Order = "NotCompleted"; _userBasket.Add(basket); return(RedirectToAction("Index", "Home")); } }
public async Task <UserBasket> GetBasket(int userId) { try { UserBasket cachedBasket = null; var userBasket = await basketCache.GetStringAsync(userId.ToString()); if (!string.IsNullOrWhiteSpace(userBasket)) { cachedBasket = JsonConvert.DeserializeObject <UserBasket>(userBasket); } return(cachedBasket); } catch (Exception ex) { throw ex; } }
public async Task RemoveItem(int userId, int itemId) { try { var userBasket = await basketCache.GetStringAsync(userId.ToString()); UserBasket cachedBasket = JsonConvert.DeserializeObject <UserBasket>(userBasket); var itemToRem = cachedBasket.basketItems.Single(itm => itm.menuItemId == itemId); cachedBasket.basketItems.Remove(itemToRem); await SaveBasket(userId.ToString(), cachedBasket); } catch (Exception ex) { throw ex; } }
public override async Task <UserBasket> Get(GetByUserRequest request, ServerCallContext context) { var jsonItems = await database.StringGetAsync(request.User); if (jsonItems.HasValue) { var items = JsonSerializer.Deserialize <Dictionary <int, double> >(jsonItems); var response = new UserBasket(); response.User = request.User; response.Items.AddRange(items.Select(x => new UserBasket.Types.BasketItem { ProductId = x.Key, Unit = x.Value })); return(response); } return(new UserBasket { User = request.User }); }
public ActionResult AddItemsToUserBasket([FromBody] JWTWithObject <List <string> > JWTWithItems) { var jwtFromDb = _db.JWTs .FirstOrDefault(o => o.Value == JWTWithItems.JwtValue); if (jwtFromDb == null) { return(NotFound("There is no such JWT")); } var userFromDB = _db.Users .FirstOrDefault(o => o.JWT == jwtFromDb); if (userFromDB == null) { return(NotFound("There is no such JWT")); } _db.Entry(userFromDB).Collection(u => u.UserBaskets).Load(); foreach (var item in JWTWithItems.Object) { var itemFromDB = _db.Items.FirstOrDefault(b => b.Name == item); //if (itemFromDB == null) // continue; //if (userFromDB.UserBaskets.FirstOrDefault(ub => ub.BasketId == itemFromDB.ID) != null) // continue; var ub = new UserBasket { ID = Guid.NewGuid(), UserID = userFromDB.Id, BasketId = itemFromDB.ID, UserLogin = userFromDB.Login }; _db.UserBaskets.Add(ub); } _db.SaveChanges(); return(Ok()); }
public void Add(UserBasket userBasket) { _dataContext.userBaskets.Add(userBasket); _dataContext.SaveChanges(); }
public void Update(UserBasket userBasket) { _userBasket.Update(userBasket); }
public UserBasket Add(UserBasket userBasket) { _userBasket.Add(userBasket); return(null); }
public IActionResult CompleteItemPurchase(int id, UserBasket userBasketItems) { _repository.CompletePurchase(userBasketItems); return(CreatedAtAction(nameof(GetCommandById), new { id = userBasketItems.UserBasketId }, userBasketItems)); }
public async Task <IActionResult> AddUserBasketItem([FromBody] UserBasket userBasket) { await basketService.AddItem(userBasket); return(Ok()); }
public async Task <IActionResult> SetUserBasket([FromBody] UserBasket userBasket) { await basketService.SetBasket(userBasket); return(Ok()); }