Example #1
0
        public async Task <IActionResult> PutCard([FromRoute] string id, [FromBody] Card card)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != card.Id)
            {
                return(BadRequest());
            }

            _context.Entry(card).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CardExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #2
0
        public async Task <IActionResult> PutCardItem(System.Guid id, CardItemDTO cardItemDTO)
        {
            if (id != cardItemDTO.Id)
            {
                return(BadRequest());
            }

            var cardItem = await _context.CardItems.FindAsync(id);

            if (cardItem == null)
            {
                return(NotFound());
            }

            cardItem.Name        = cardItemDTO.Name;
            cardItem.IsAvailable = cardItemDTO.IsAvailable;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException) when(!CardItemExists(id))
            {
                return(NotFound());
            }

            return(NoContent());
        }
Example #3
0
        public virtual async Task <Guid> CreateAsync(TEntity entity)
        {
            await _context.Set <TEntity>().AddAsync(entity);

            await _context.SaveChangesAsync();

            return(entity.Id);
        }
Example #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));
        }
Example #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));
        }
        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));
        }
Example #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));
        }
Example #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));
        }
Example #10
0
 public void PostNewCard([FromBody] List <Card> newCards)
 {
     newCards.ForEach(x =>
     {
         cardContext.Add(x);
         cardContext.AddRange(x.Options);
     }
                      );
     cardContext.SaveChangesAsync();
 }
Example #11
0
        public async Task <ActionResult <Card> > Post(Card card)
        {
            if (card == null)
            {
                return(BadRequest());
            }

            if (card.Owner == "Ilya Cherkasov")
            {
                ModelState.AddModelError("Owner", "Недопустимое имя владельца - Ilya Cherkasov");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Cards.Add(card);
            await db.SaveChangesAsync();

            return(Ok(card));
        }
Example #12
0
 private async Task <bool> Save()
 {
     return(await _cardContext.SaveChangesAsync() > 0);
 }