public IActionResult Add() { AddPersonDisplayViewModel model = new AddPersonDisplayViewModel(); model.TagForDisplay = TagRepo.GetAll(); return(View(model)); }
public IActionResult Add(AddPersonSelectViewModel model) { if (ModelState.IsValid) { if (PersonService.CheckUniqeEmail(model.Email)) { 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 fileByte = ms.ToArray(); person.Image = Convert.ToBase64String(fileByte); } } PersonRepo.Add(person); return(RedirectToAction("List")); } else { //this Email in not Available,please change by another email; } } List <Tag> oldTagfind = new List <Tag>(); foreach (int item in model.SelectedTag) { var t = TagRepo.Get(item); oldTagfind.Add(t); } AddPersonDisplayViewModel displayViewModel = new AddPersonDisplayViewModel { FirstName = model.FirstName, LastName = model.LastName, Address = model.Address, Email = model.Email, oldTag = oldTagfind }; displayViewModel.TagForDisplay = TagRepo.GetAll(); return(View(displayViewModel)); }