Exemple #1
0
        public async Task <IActionResult> Create([Bind("Id,Nome,Sobrenome,Email,DataDeNascimento")] Autor autor)
        {
            try
            {
                if (ModelState.IsValid == false)
                {
                    return(View(autor));
                }


                var client  = new RestClient();
                var request = new RestRequest("https://localhost:5001/api/autors", DataFormat.Json);
                request.AddJsonBody(autor);

                var response = client.Post <AutorViewModel>(request);
                _context.Add(autor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch (System.Exception ex)
            {
                ModelState.AddModelError("APP_ERROR", ex.Message);
                return(View(autor));
            }
        }
        public TodoItem Add(TodoItem todoitem)
        {
            var addedTodoItem = _context.Add(todoitem);

            _context.SaveChanges();
            todoitem.Id = addedTodoItem.Entity.Id;

            return(todoitem);
        }
 public IActionResult Post([FromBody] Equips equip)
 {
     if (ModelState.IsValid)
     {
         db.Add(equip);
         db.SaveChanges();
         return(CreatedAtAction("GetEquips", new { id = equip.EquipID }, equip));
     }
     return(BadRequest(ModelState));
 }
Exemple #4
0
        public async Task <IActionResult> Create([Bind("Id,Nome,Sobrenome,TurmaId")] Aluno aluno)
        {
            if (ModelState.IsValid)
            {
                _context.Add(aluno);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(aluno));
        }
Exemple #5
0
        public async Task <IActionResult> Create([Bind("Id,Make,Model,Year,VIN,Colour,DealershipID")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
        public async Task <IActionResult> Create([Bind("ID,Name,Email,PhoneNumber")] Dealership dealership)
        {
            if (ModelState.IsValid)
            {
                _context.Add(dealership);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(dealership));
        }
Exemple #7
0
        public async Task <IActionResult> Create([Bind("FirstName,LastName,UserName,Email,Company,Position,BirthDate")] Member member)
        {
            if (ModelState.IsValid)
            {
                _context.Add(member);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(member));
        }
Exemple #8
0
        public async Task <IActionResult> Create([Bind("Id,Titulo,ISBN,Ano,AutorId")] Livro livro)
        {
            if (ModelState.IsValid)
            {
                _context.Add(livro);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(livro));
        }
Exemple #9
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> Create([FromBody] userLogin userLogin)
        {
            if (ModelState.IsValid)
            {
                //Encriptar pass
                userLogin.Password = Seguridad.Encriptarpass(userLogin.Password);


                _context.Add(userLogin);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(userLogin));
        }