Пример #1
0
        public ActionResult CreateAccount(Account account)
        {
            try
            {
                //this will set the next pickup day so that you can use this for the employee when they pickup customeres trash
                //when the employee picks up trash, the next pickup will be set to the next week
                DateTime nextPickup = DateTime.Now;
                while (!nextPickup.DayOfWeek.Equals(account.PickupDay))
                {
                    nextPickup = nextPickup.AddDays(1);
                }
                account.NextPickupDate = nextPickup;
                _repo.Account.Create(account);
                _repo.Save();

                var userId   = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
                var customer = _repo.Customer.FindByCondition(c => c.IdentityUserId == userId).FirstOrDefault();
                customer.AccountId = _repo.Account.FindByCondition(a => a.Equals(account)).FirstOrDefault().Id;
                _repo.Customer.Update(customer);
                _repo.Save();
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Пример #2
0
        public ActionResult EditWeeklyPickup(Account accountFromForm)
        {
            try
            {
                var userId        = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
                var customer      = _repo.Customer.FindByCondition(c => c.IdentityUserId == userId).FirstOrDefault();
                var accountFromDb = _repo.Account.GetAccount(customer.AccountId ?? default);
                accountFromDb.PickupDay = accountFromForm.PickupDay;
                DateTime nextPickup = DateTime.Now;
                while (!nextPickup.DayOfWeek.Equals(accountFromForm.PickupDay))
                {
                    nextPickup = nextPickup.AddDays(1);
                }
                accountFromDb.NextPickupDate = nextPickup;
                _repo.Account.Update(accountFromDb);
                _repo.Save();

                //customer.AccountId = accountFromDb.Id;
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Edit(ViewModel viewModel)
        {
            try
            {
                var userId   = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
                var customer = _repo.Customer.FindByCondition(b => b.UserId == userId).FirstOrDefault();
                if (customer.AccountId == null)
                {
                    Account account = new Account();
                    account.IsSuspended   = viewModel.Account.IsSuspended;
                    account.OneTimePickup = viewModel.Account.OneTimePickup;
                    account.PickupDay     = viewModel.Account.PickupDay;
                    DateTime NextPickup = DateTime.Now;
                    while (!NextPickup.DayOfWeek.Equals(account.PickupDay))
                    {
                        NextPickup = NextPickup.AddDays(1);
                    }
                    account.NextPickup = NextPickup;
                    account.StartDate  = viewModel.Account.StartDate;
                    account.EndDate    = viewModel.Account.EndDate;
                    _repo.Account.Create(account);
                    _repo.Save();

                    customer.AccountId = _repo.Account.FindByCondition(a => a.Equals(account)).FirstOrDefault().Id;
                    _repo.Customer.Update(customer);
                    _repo.Save();
                }
                else
                {
                    var account = _repo.Account.GetAccount(customer.AccountId ?? default);
                    account.IsSuspended   = viewModel.Account.IsSuspended;
                    account.OneTimePickup = viewModel.Account.OneTimePickup;
                    account.PickupDay     = viewModel.Account.PickupDay;
                    DateTime NextPickup = DateTime.Now;
                    while (!NextPickup.DayOfWeek.Equals(account.PickupDay))
                    {
                        NextPickup = NextPickup.AddDays(1);
                    }
                    account.NextPickup = NextPickup;
                    account.StartDate  = viewModel.Account.StartDate;
                    account.EndDate    = viewModel.Account.EndDate;
                    _repo.Account.Update(account);
                    _repo.Save();
                }
                return(RedirectToAction(nameof(Details)));
            }
            catch
            {
                return(View(viewModel));
            }
        }
Пример #4
0
        public ActionResult EditOneTimePickup(Account accountFromForm)
        {
            try
            {
                var userId        = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
                var customer      = _repo.Customer.FindByCondition(c => c.IdentityUserId == userId).FirstOrDefault();
                var accountFromDb = _repo.Account.GetAccount(customer.AccountId ?? default);
                accountFromDb.OneTimePickup = accountFromForm.OneTimePickup;
                _repo.Account.Update(accountFromDb);
                _repo.Save();

                //customer.AccountId = accountFromDb.Id;
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Пример #5
0
        // GET: Account/Create
        public ActionResult CreateAccount()
        {
            Account account = new Account();

            return(View(account));
        }