public async Task <Person> AddPersonAsync(Person person) { _context.People.Add(person); await _context.SaveChangesAsync(); return(person); }
public async Task <IActionResult> PutPerson(int code, Person person) { try { if (code != person.Code) { return(BadRequest()); } _context.Entry(person).State = EntityState.Modified; await _context.SaveChangesAsync(); return(CreatedAtAction( nameof(GetPerson), new { code = person.Code, person }, person )); } catch (DbUpdateConcurrencyException) when(!PersonExists(code)) { return(NotFound()); } catch (System.Exception) { return(UnprocessableEntity()); } }
public async Task <ActionResult <Person> > PutPerson(Guid id, Person person) { if (id != person.Id) { return(BadRequest()); } _context.Entry(person).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PersonExists(id)) { return(NotFound()); } else { throw; } } return(await GetPerson(id)); }
public async Task <IActionResult> PutEmail([FromRoute] int id, [FromBody] Email email) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != email.EmailId) { return(BadRequest()); } _context.Entry(email).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmailExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <int> CreateAsync(Person entity) { _context.Person.Add(entity); var response = await _context.SaveChangesAsync(); return(response); }
public async Task <IActionResult> Create([Bind("Name, Surname, Patronymic, Tel, Position,TagId,Image")] PersonModel person) { Person _person = new Person { Name = person.Name, Surname = person.Surname, Patronymic = person.Patronymic, Tel = person.Tel, Position = person.Position, TagId = person.TagId }; if (ModelState.IsValid && RidCheck(person.TagId)) { if (person.Image != null) { byte[] imageData = null; using (var binaryReader = new BinaryReader(person.Image.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)person.Image.Length); } _person.Image = imageData; } _context.Add(_person); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(person)); }
// Seed database with example Persons public void SeedDatabase() { if (!_context.Persons.Any()) { Person[] people = new Person[] { new Person(FName: "John", LName: "Doe", Address: "243 N. 253 E.", Age: 23, Interests: "Paddleboarding, Surfing"), new Person(FName: "Jacob", LName: "Smith", Address: "353 S. 132 W.", Age: 30, Interests: "Programming, Baseball"), new Person(FName: "Dane", LName: "Littlefield", Address: "234 N. 432 E.", Age: 25, Interests: "Volleyball, Crocheting"), }; foreach (Person person in people) { _context.Persons.Add(person); _context.SaveChangesAsync(); } } //_context.Persons.Add(person); //await _context.SaveChangesAsync(); //return CreatedAtAction("GetPerson", new { id = person.Id }, person); }
// PUT api/Place/5 public async Task <IHttpActionResult> PutPlace(int id, Place place) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != place.Id) { return(BadRequest()); } db.Entry(place).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PlaceExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> PutPerson([FromRoute] int id, [FromBody] Person person) { if (id != person.Id) { _logger.LogWarning("ID {id} does not equal person ID", id); return(BadRequest()); } _context.Entry(person).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PersonExists(id)) { _logger.LogWarning("Could not put person with ID {id}", id); return(NotFound()); } else { throw; } } _logger.LogInformation("Put person with ID {id}", id); return(NoContent()); }
public async Task <ActionResult> Login(UserCredentials user) { Person person = await db.Persons.FirstOrDefaultAsync(x => x.Login == user.Login && x.Password == user.Password); if (person == null) { return(BadRequest(new { errorText = "Invalid username or password" })); } var identity = GetIdentity(person); var encodedJwt = tokenService.CreateJWT(identity); var refreshToken = tokenService.CreateRefreshToken(); person.RefreshToken = refreshToken.Token; db.Persons.Update(person); await db.SaveChangesAsync(); var response = new { access_token = encodedJwt, refresh_token = refreshToken, username = identity.Name }; return(Ok(response)); }
public async Task <ActionResult <Person> > PostTodoItem(Person item) { _context.Persons.Add(item); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetPerson), new { id = item.Id }, item)); }
public async Task <IActionResult> PutPerson([FromRoute] int id, [FromBody] Person person) { if (!ModelState.IsValid) { return(HttpBadRequest(ModelState)); } if (id != person.Id) { return(HttpBadRequest()); } _context.Entry(person).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PersonExists(id)) { return(HttpNotFound()); } else { throw; } } return(new HttpStatusCodeResult(StatusCodes.Status204NoContent)); }
public async Task <int> CreatePerson(string name) { var person = _personContext.Persons.Add(new Person { Name = name }); await _personContext.SaveChangesAsync(); return(person.Entity.Id); }
public async Task <IActionResult> Create([Bind("PersonId,Name,CPF,Birthday,Age")] Person person) { if (ModelState.IsValid) { _context.Add(person); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(person)); }
public async Task <IActionResult> Create([Bind("PersonId,firstName,lastName,birthDate,age")] Person person) { if (ModelState.IsValid) { _context.Add(person); await _context.SaveChangesAsync(); return(RedirectToAction("PersonDetails")); } return(View(person)); }
public async Task <IActionResult> Create([Bind("ID,Name,YoB")] Human human) { if (ModelState.IsValid) { _context.Add(human); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(human)); }
public async Task <IActionResult> Create([Bind("Id,Name,Creator,YearCreation,ImageUrl,Description")] Person person) { if (ModelState.IsValid) { _context.Add(person); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(person)); }
public async Task <IActionResult> Create(Person person) { if (ModelState.IsValid) { _context.Person.Add(person); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(person)); }
public async Task <IActionResult> Create([Bind("CityId,CityName,ZipCode,CountryRegion")] City city) { if (ModelState.IsValid) { _context.Add(city); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(city)); }
public async Task <IActionResult> Create([Bind("PersonId,FullName,EmpCode,Position,OfficeLocation")] Person person) { if (ModelState.IsValid) { personContext.Add(person); await personContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(person)); }
public async Task <IActionResult> Create([Bind("Id,Nombre,Apellido,Estado,Carrera")] Persona persona) { if (ModelState.IsValid) { _context.Add(persona); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(persona)); }
public async Task <IActionResult> Create([Bind("EmailId,EmailAddress")] Email email) { if (ModelState.IsValid) { _context.Add(email); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(email)); }
public async Task <DbPerson> AddAsync(DbPerson person) { // Как это сделать по-человечески? //var lastId = _context.Persons.Select(dbPerson => dbPerson.Id).Last(); //person.Id = lastId + 1; var result = await _context.Persons.AddAsync(person); await _context.SaveChangesAsync(); return(result.Entity); }
public async Task <IActionResult> Create([Bind("ID,PersonID,Address")] EMailAddress eMailAddress) { if (ModelState.IsValid) { _context.Add(eMailAddress); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["PersonID"] = new SelectList(_context.People, "ID", "ID", eMailAddress.PersonID); return(View(eMailAddress)); }
// POST: PersonEntities/Create // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see http://go.microsoft.com/fwlink/?LinkId=317598. //[ValidateAntiForgeryToken] public async Task <IActionResult> CreatePerson([Bind("Id,FirstName,LastName,Title,Age,City,PostCode")] PersonEntity personEntity) { if (ModelState.IsValid) { _context.Add(personEntity); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([Bind("ID,Number,PersonID")] PhoneNumber phoneNumber) { if (ModelState.IsValid) { _context.Add(phoneNumber); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["PersonID"] = new SelectList(_context.People, "ID", "FirstName", phoneNumber.PersonID); return(View(phoneNumber)); }
public async Task <ActionResult> Create([Bind(Include = "Id,Name,Age")] Person person) { if (ModelState.IsValid) { db.People.Add(person); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(person)); }
public async Task <IActionResult> Create([Bind("AddressId,StreetAddress,AddressType,CityId")] Address address) { if (ModelState.IsValid) { _context.Add(address); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CityId"] = new SelectList(_context.City, "CityId", "CityName", address.CityId); return(View(address)); }
public async Task <ActionResult <Models.Person> > PostPerson(Models.Person person) { if (person.Id != 0) { return(BadRequest("Id must be zero or undefined")); } _context.Persons.Add(person); await _context.SaveChangesAsync(); return(Ok(person)); }
public async Task <IActionResult> Create([Bind("PersonId,FullName,EmailId,AddressId")] Person person) { if (ModelState.IsValid) { _context.Add(person); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AddressId"] = new SelectList(_context.Address, "AddressId", "StreetAddress", person.AddressId); ViewData["EmailId"] = new SelectList(_context.Email, "EmailId", "EmailAddress", person.EmailId); return(View(person)); }