Пример #1
0
        public async Task <IActionResult> AddContacts(ContactListViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Contacts    = (await _contactService.GetContacts()).Select(c => new SelectListItem(c.FirstName + " " + c.LastName + "(" + c.Email + ")", c.Id.ToString())).ToList();
                model.Lists       = model.ListIds.Select(c => new SelectListItem("", c.ToString())).ToList();
                model.ListsString = GetSelectedListsString(model.ListIds.ToList());
                return(View(model));
            }

            var dto = new ContactListDTO
            {
                ContactIds = model.ContactIds,
                ListIds    = model.ListIds
            };

            await _contactService.AddContactsToLists(dto);

            TempData.Put("Toast", new Toast(ToastType.Success, string.Format(_stringLocalizer["Contacts are successfully added to lists"])));
            return(RedirectToAction(nameof(Index)));
        }