public ActionResult AddRecipient(AddRecipientViewModel vm)
        {
            using (
                var unitOfWork =
                    new UnitOfWork.UnitOfWorkScope <BankingDbContext>(UnitOfWork.UnitOfWorkScopePurpose.Writing))
            {
                AuthenticationService authenticate = new AuthenticationService();
                var userEmail = (string)HttpContext.Session["User"];
                var user      = authenticate.GetUser(userEmail);
                vm.UserName = user.Name;
                if (ModelState.IsValid)
                {
                    try
                    {
                        var users = _efrUser.GetDbSet()
                                    .Where(m => m.Id == user.Id)
                                    .Include(m => m.RecipientList)
                                    .First();

                        Recipient recipient = new Recipient(vm.Name, vm.Amount);
                        users.RecipientList.Add(recipient);
                        vm.Message = "Recipient Successfully Added";
                        unitOfWork.SaveChanges();
                        return(RedirectToAction("Recipient", "User"));
                    }
                    catch (Exception) { }
                }
            }
            return(View(vm));
        }
Ejemplo n.º 2
0
        public async Task Create(AddRecipientViewModel model)
        {
            var recipient = new Recipient();

            recipient.Email = model.Email;
            await _repo.Create(recipient);
        }
        public ActionResult AddRecipient()
        {
            AddRecipientViewModel vm = new AddRecipientViewModel();

            using (
                var unitOfWork =
                    new UnitOfWork.UnitOfWorkScope <BankingDbContext>(UnitOfWork.UnitOfWorkScopePurpose.Writing))
            {
                AuthenticationService authenticate = new AuthenticationService();
                var userEmail = (string)HttpContext.Session["User"];
                var user      = authenticate.GetUser(userEmail);
                vm.UserName = user.Name;
            }
            return(View(vm));
        }
Ejemplo n.º 4
0
 public async Task Create([FromBody] AddRecipientViewModel model)
 {
     await _service.Create(model);
 }