示例#1
0
        public async Task <IActionResult> Register([Bind("Login, Password, ConfirmPassword, Email")] RegisterViewModel registerViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    registerViewModel.Password = HashProfile.GetSaltedHashData(registerViewModel.Password, registerViewModel.PasswordSalt);
                    DbUser userModel = _mapper.Map <DbUser>(registerViewModel);
                    DbContext.Add(userModel);
                    await DbContext.SaveChangesAsync();

                    if (SendConfirmationEmail(userModel))
                    {
                        return(RedirectToAction("Login", "Auth"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Unable to send confirmation e-mail. ");
                        DbContext.Users.Remove(userModel);
                        await DbContext.SaveChangesAsync();

                        return(View(registerViewModel));
                    }
                }
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(registerViewModel));
        }
        public async Task <IActionResult> Create([Bind("Id,Title,Content,Date")] TaskModel model)
        {
            if (ModelState.IsValid)
            {
                Entities.Task newTask = new Entities.Task();

                newTask.Id      = model.Id;
                newTask.Title   = model.Title;
                newTask.Content = model.Content;
                newTask.Date    = model.Date;

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

                return(RedirectToAction(nameof(Index)));
            }
            return(View("Index"));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("UserId, Objective, Description, ClosingDate")] TaskViewModel taskViewModel, string returnUrl = null)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    DbTask taskModel = _mapper.Map <DbTask>(taskViewModel);
                    DbContext.Add(taskModel);
                    await DbContext.SaveChangesAsync();

                    return(RedirectToActionOrReturnUrl("Index", returnUrl));
                }
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(taskViewModel));
        }
示例#4
0
        public async Task <IActionResult> Create([Bind("Login, Password, Email")] UserViewModel userViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    userViewModel.Password = HashProfile.GetSaltedHashData(userViewModel.Password, userViewModel.PasswordSalt);
                    DbUser userModel = _mapper.Map <DbUser>(userViewModel);
                    DbContext.Add(userModel);
                    await DbContext.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(userViewModel));
        }