public async Task <IActionResult> Add([Bind("")] PersonAddModel personAddModel) { if (!ModelState.IsValid) { ModelState.AddModelError(string.Empty, "Your information is don't valid"); return(View("Add")); } personAddModel.Person.IsPersonActive = true; // IsActivePerson'a özel güzel bir süreç oluştur. try { var result = await _schoolDataDbContext.AddAsync(personAddModel.Person); await _schoolDataDbContext.SaveChangesAsync(); return(RedirectToAction("List")); } catch (DbUpdateException error) { ModelState.AddModelError(string.Empty, "Unable to save changes" + "\n Message:" + error.Message.ToString() + "Inner Exception:" + error.InnerException.ToString()); } return(View(personAddModel)); }
public async Task <IActionResult> Edit(string id, PersonAddModel personAddModel) { if (int.Parse(id) != personAddModel.Person.Id) { ModelState.AddModelError("", "Id is Not Belongs the Role"); return(View(personAddModel)); } //personAddModel.Person.IsPersonActive=true; if (ModelState.IsValid) { var result = _schoolDataDbContext.Persons.Update(personAddModel.Person); if (result == null) { ModelState.AddModelError(string.Empty, "Model is not updated"); return(View(personAddModel)); } await _schoolDataDbContext.SaveChangesAsync(); return(RedirectToAction("List")); } return(View(personAddModel)); }
// GET: Person Edit public async Task <IActionResult> Edit(string id) { if (id == null) { ModelState.AddModelError(string.Empty, "Id is not have a value"); } var person = new PersonAddModel() { Person = await _schoolDataDbContext.Persons.FirstOrDefaultAsync(s => s.Id == int.Parse(id)) }; if (person == default) { ModelState.AddModelError(String.Empty, "Person Update Error!!"); return(RedirectToAction("List")); } return(View(person)); }
// POST api/PeopleApi public HttpResponseMessage PostPerson(PersonAddModel person) { if (ModelState.IsValid) { var newPerson = PeopleService.AddPerson(person.FirstName, person.LastName, person.Birthday, person.Email, person.Phone); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, PersonModel.FromPerson(newPerson)); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = newPerson.PersonId })); return(response); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
// GET: Person Details public async Task <IActionResult> Details(string id) { if (id == null) { ModelState.AddModelError(string.Empty, "Id don't have a value"); return(RedirectToAction("List")); } var person = new PersonAddModel { Person = await _schoolDataDbContext.Persons.FirstOrDefaultAsync(s => s.Id == int.Parse(id)) }; if (person == null) { ModelState.AddModelError(string.Empty, "Role is not avaliable"); return(RedirectToAction("List")); } return(View(person)); }