Esempio n. 1
0
        public IActionResult Post([FromForm] MemberViewModel member)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (_context.CheckIfMemberExists(member.Email) == false)
                    {
                        var newMember = Mapper.Map <Member>(member);
                        _context.AddMember(newMember);

                        return(View("Success", member));
                    }
                    else
                    {
                        ModelState.AddModelError("Error", "Email already exists");
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to save new Member: {0}", ex);
            }

            return(View("Error", new ErrorViewModel()
            {
                Email = member.Email,
                Message = ModelState.ValidationState.ToString()
            }));
        }