public async Task <bool> Insert(Card card) { try { _cardContext.Add(card); return(await Save()); } catch (Exception e) { _logger.LogError($"Error in Insert: {e.Message}"); return(false); } }
public async Task <Card> AddProductToCardAsync(Guid customerID, Guid productID, int quantity) { using (var db = new CardContext()) { var card = db.Cards .Where(c => c.IsActive == true && c.CustomerID == customerID) .Include(m => m.CardItems) .Include(m => m.CardItems) .FirstOrDefault(); if (card != null) { if (card.CardItems.Any(ci => ci.ProductID != productID)) { card.CardItems.Add(new CardItem(customerID, productID, quantity)); } else { card.CardItems.Where(ci => ci.ProductID == productID).FirstOrDefault().Quantity += quantity; } } else { db.Add(new Card(customerID, new List <CardItem>() { new CardItem(customerID, productID, quantity) }, true)); } db.SaveChanges(); return(db.Cards.Where(c => c.CustomerID == customerID && c.IsActive).FirstOrDefault()); } }
public void PostNewCard([FromBody] List <Card> newCards) { newCards.ForEach(x => { cardContext.Add(x); cardContext.AddRange(x.Options); } ); cardContext.SaveChangesAsync(); }
public async Task <IActionResult> Create([Bind("Id,Type,Title,Percentage")] Skills skills) { if (ModelState.IsValid) { _context.Add(skills); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(skills)); }
public async Task <IActionResult> Create([Bind("Id,Title,PicAddress,About,Link")] Articles articles) { if (ModelState.IsValid) { _context.Add(articles); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(articles)); }
public async Task <IActionResult> Create([Bind("Id,Title,Explain1,Explain2")] Educations educations) { if (ModelState.IsValid) { _context.Add(educations); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(educations)); }
public async Task <IActionResult> Create([Bind("Id,Name,Family,Email,UserName,PassWord")] Users users) { if (ModelState.IsValid) { _context.Add(users); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(users)); }
public async Task <IActionResult> Create([Bind("ID,Title,Content,FileName")] Card card) { if (ModelState.IsValid) { card.Date = DateTime.Now; _context.Add(card); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(card)); }
public async Task <IActionResult> Create([Bind("Id,Number,PIN,AvailableMoney,Status")] Card card) { if (ModelState.IsValid) { card.Id = Guid.NewGuid(); _context.Add(card); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(card)); }