public ActionResult <Person> AddNew(Person person) { Thread.Sleep(5000); return(Unauthorized()); var personAfterInsert = _peopleService.AddNewPerson(person); return(Ok(personAfterInsert)); }
public async Task <ActionResult> Create(PersonDetailsViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } var response = await _peopleService.AddNewPerson(viewModel.PersonDetails); if (response.OperationSuccessful) { return(RedirectToAction("Index")); } else { viewModel.Errors.AddRange(response.Errors); return(View(viewModel)); } }
public IActionResult Add(AddNewPersonGetViewModel model) { if (ModelState.IsValid) { Person person = new Person { FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, Address = model.Address, Tags = new List <PersonTag>(model.SelectedTag.Select(c => new PersonTag { TagId = c }).ToList()) }; if (model?.Image?.Length > 0) { using (var ms = new MemoryStream()) { model.Image.CopyTo(ms); var fileBytes = ms.ToArray(); person.Image = Convert.ToBase64String(fileBytes); } } Person result = peopleService.AddNewPerson(person); if (result != null) { return(RedirectToAction("Index")); } } ViewBag.SelectedItem = model.SelectedTag; AddNewPersonDisplayViewModel modelforDisplay = new AddNewPersonDisplayViewModel { Address = model.Address, Email = model.Email, LastName = model.LastName, FirstName = model.FirstName }; modelforDisplay.TagsForDisplay = tagService.GetAllTags(); return(View(modelforDisplay)); }