Exemplo n.º 1
0
        public ActionResult Create(AutoApproval autoApproval, bool showAll = false)
        {
            autoApproval.Equal = !autoApproval.LessThan; //only one can be true, the other must be false
            autoApproval.User  = _userRepository.GetNullableById(CurrentUser.Identity.Name);
            ModelState.Clear();
            autoApproval.TransferValidationMessagesTo(ModelState);
            if (autoApproval.Expiration.HasValue && autoApproval.Expiration.Value.Date <= DateTime.UtcNow.ToPacificTime().Date)
            {
                ModelState.AddModelError("AutoApproval.Expiration", "Expiration date has already passed");
            }
            autoApproval.IsActive = true;

            if (ModelState.IsValid)
            {
                _autoApprovalRepository.EnsurePersistent(autoApproval);

                Message = "AutoApproval Created Successfully";
                if (autoApproval.Expiration.HasValue && autoApproval.Expiration.Value.Date <= DateTime.UtcNow.ToPacificTime().Date.AddDays(5))
                {
                    Message = Message + " Warning, will expire in 5 days or less";
                }
                return(this.RedirectToAction(a => a.Index(showAll)));
            }
            else
            {
                var viewModel = AutoApprovalViewModel.Create(Repository, CurrentUser.Identity.Name);
                viewModel.AutoApproval = autoApproval;
                ViewBag.ShowAll        = showAll;
                ViewBag.IsCreate       = true;

                return(View(viewModel));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// #3
        /// GET: /AutoApproval/Create
        /// </summary>
        /// <param name="showAll"></param>
        /// <returns></returns>
        public ActionResult Create(bool showAll = false)
        {
            var viewModel = AutoApprovalViewModel.Create(Repository, CurrentUser.Identity.Name);

            ViewBag.ShowAll  = showAll;
            ViewBag.IsCreate = true;

            return(View(viewModel));
        }
Exemplo n.º 3
0
        public ActionResult Edit(int id, AutoApproval autoApproval, bool showAll = false)
        {
            var autoApprovalToEdit = _autoApprovalRepository.GetNullableById(id);

            if (autoApprovalToEdit == null)
            {
                return(this.RedirectToAction(a => a.Index(showAll)));
            }

            if (autoApprovalToEdit.User.Id != CurrentUser.Identity.Name)
            {
                ErrorMessage = "No Access";
                return(this.RedirectToAction <ErrorController>(a => a.Index()));
            }

            TransferValues(autoApproval, autoApprovalToEdit);
            autoApprovalToEdit.Equal = !autoApprovalToEdit.LessThan;

            ModelState.Clear();
            autoApprovalToEdit.TransferValidationMessagesTo(ModelState);

            if (ModelState.IsValid)
            {
                _autoApprovalRepository.EnsurePersistent(autoApprovalToEdit);

                Message = "AutoApproval Edited Successfully";

                return(this.RedirectToAction(a => a.Index(showAll)));
            }
            else
            {
                var viewModel = AutoApprovalViewModel.Create(Repository, CurrentUser.Identity.Name);
                viewModel.AutoApproval = autoApprovalToEdit;
                ViewBag.ShowAll        = showAll;
                ViewBag.IsCreate       = false;

                return(View(viewModel));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// #5
        /// GET: /AutoApproval/Edit/5
        /// </summary>
        /// <param name="id">AutoApproval Id</param>
        /// <param name="showAll">show inactive and expired too(Used to pass along to index)</param>
        /// <returns></returns>
        public ActionResult Edit(int id, bool showAll = false)
        {
            var autoApproval = _autoApprovalRepository.GetNullableById(id);

            if (autoApproval == null)
            {
                return(this.RedirectToAction(a => a.Index(showAll)));
            }

            if (autoApproval.User.Id != CurrentUser.Identity.Name)
            {
                ErrorMessage = "No Access";
                return(this.RedirectToAction <ErrorController>(a => a.Index()));
            }

            var viewModel = AutoApprovalViewModel.Create(Repository, CurrentUser.Identity.Name);

            viewModel.AutoApproval = autoApproval;
            ViewBag.ShowAll        = showAll;
            ViewBag.IsCreate       = false;

            return(View(viewModel));
        }