Exemplo n.º 1
0
        public async Task <IActionResult> PutTblPriceBookMain(int id, TblPriceBookMain tblPriceBookMain)
        {
            if (id != tblPriceBookMain.PartId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PostNewStates([FromBody] List <State> states)
        {
            _context.States.AddRange(states);
            await _context.SaveChangesAsync();

            return(new OkObjectResult(states));
        }
        public async Task <IActionResult> Create([Bind("ID,QuoteText,AuthorID")] Quote quote)
        {
            if (ModelState.IsValid)
            {
                _context.Add(quote);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuthorID"] = new SelectList(_context.Authors, "AuthorID", "Name", quote.AuthorID);
            return(View(quote));
        }
Exemplo n.º 4
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            QuoteModel.SetPrice();
            QuoteModel.SetSize();
            _context.Attach(QuoteModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!QuoteModelExists(QuoteModel.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Details", new { id = QuoteModel.ID }));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> DeleteQuote([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = _userManagement.Find(User.FindFirstValue(ClaimTypes.NameIdentifier));

            var repo = new QuoteRepository(_context);
            var q    = repo.Search(id);

            if (q == null)
            {
                // return 404?
                return(NotFound());
            }
            else
            {
                if (q.CreatedByUserId != user.Id)
                {
                    // Not created by this user??
                    return(Unauthorized());
                }
            }

            repo.DeleteQuote(q);

            await _context.SaveChangesAsync();

            return(Ok(user));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> OnLogin(string access_token)
        {
            // @TODO: Check our User record
            var nameId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var repo   = new UserRepository(_context);
            var user   = repo.Search(nameId);

            if (user == null)
            {
                user = await CreateNewUserAsync(nameId, access_token);
            }
            user.LastLogin = DateTime.UtcNow;

            await _context.SaveChangesAsync();

            return(Ok(user));
        }
Exemplo n.º 7
0
        public async Task <ActionResult <GetQuoteResponseVm> > CreateQuote([FromBody] CreateQuoteRequestVm toCreate)
        {
            var quote = _mapper.Map <Quote>(toCreate);
            await _context.AddAsync(quote);

            await _context.SaveChangesAsync();

            return(Ok(_mapper.Map <GetQuoteResponseVm>(quote)));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> PutQuoteItem(long id, QuoteItem quoteItem)
        {
            if (id != quoteItem.Id)
            {
                return(BadRequest());
            }

            _context.Entry(quoteItem).State = EntityState.Modified;
            if (quoteItem.author == "")
            {
                ModelState.AddModelError("Author", "Не добавлен автор");
            }
            if (quoteItem.quote == "")
            {
                ModelState.AddModelError("Quote", "Не добавлена цитата");
            }
            // если есть ошибки - возвращаем ошибку 400
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!QuoteItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            ModelQuote.Date = DateTime.Now;
            ModelQuote.SetSize();
            ModelQuote.Price = ModelQuote.SetPrice();

            _context.QuoteModel.Add(ModelQuote);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Details", new { id = ModelQuote.ID }));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            QuoteModel = await _context.QuoteModel.FindAsync(id);

            if (QuoteModel != null)
            {
                _context.QuoteModel.Remove(QuoteModel);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }