Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
        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());
            }
        }
Exemplo n.º 3
0
 public void PostNewCard([FromBody] List <Card> newCards)
 {
     newCards.ForEach(x =>
     {
         cardContext.Add(x);
         cardContext.AddRange(x.Options);
     }
                      );
     cardContext.SaveChangesAsync();
 }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
0
        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));
        }