Esempio n. 1
0
        public async Task <IActionResult> Create(ContactEditViewModel editModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(editModel));
            }

            var contact = ViewModel_to_model(new Contact(), editModel);

            contact.OwnerID = _userManager.GetUserId(User);

            var isAuthorized = await _authorizationService.AuthorizeAsync(User, contact, ContactOperations.Create);

            if (!isAuthorized)
            {
                return(new ChallengeResult());
            }

            _context.Add(contact);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }