public string Delegate(DelegateHeadViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return("fail");
            }

            else
            {
                string userId                 = User.Identity.GetUserId();
                var    selectedEmployee       = model.SelectedUser;
                DelegationOfAuthority doaInDb = new DelegationOfAuthority
                {
                    DelegatedBy  = userId,          //"b36a58f3-51f9-47eb-8601-bcc757a8cadb";//selected Employee ID;
                    DelegatedTo  = selectedEmployee,
                    StartDate    = model.StartDate, //new DateTime(2017,3,5);
                    EndDate      = model.EndDate,   //new DateTime(2017, 5, 5);
                    DepartmentId = model.DepartmentID
                };

                //model.CurrentUser = userId;

                ApplicationUserManager userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();

                userManager.RemoveFromRole(doaInDb.DelegatedTo, RoleName.Employee);
                userManager.AddToRole(doaInDb.DelegatedTo, RoleName.ActingDepartmentHead);
                _context.DelegationOfAuthority.Add(doaInDb);
                _context.SaveChanges();
                return("success");
            }
        }
Esempio n. 2
0
        public ActionResult Delegate(DelegateHeadViewModel model)
        {
            string userId = User.Identity.GetUserId();

            if (!gmService.IsAllRequestsApproved(userId))
            {
                return(RedirectToAction("Index", new { id = 3 }));
            }

            ApplicationUserManager manager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
            ApplicationDbContext   context = new ApplicationDbContext();

            manager.AddToRole(model.SelectedUser, "Acting Department Head");
            manager.RemoveFromRole(model.SelectedUser, "Employee");

            model.DeptHeadId = userId;

            gmService.AssignDelegateHead(userId, model.SelectedUser, model.DepartmentId, model.StartDate, model.EndDate);
            string email   = gmService.GetUserEmail(userId);
            string subject = "You have been delegated as Acting Department Head";
            string content = string.Format("Your appointment will start on {0} and end on {1}", model.StartDate.ToShortDateString(), model.EndDate.ToShortDateString());

            Email.Send(email, subject, content);

            return(RedirectToAction("Index", new { id = 1 }));
        }
Esempio n. 3
0
        public ActionResult Index(int id = 0)
        {
            if (id == 1)
            {
                ViewBag.successHandler = 1;
            }
            else if (id == 2)
            {
                ViewBag.successHandler = 2;
            }
            else if (id == 3)
            {
                ViewBag.successHandler = 3;
            }
            string userId = User.Identity.GetUserId();
            DelegateHeadViewModel viewModel = new DelegateHeadViewModel(userId);

            ViewBag.DepName = viewModel.DepartmentName;

            ApplicationUserManager manager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
            ApplicationDbContext   context = new ApplicationDbContext();

            string[] delHead = gmService.GetDelegatedHead(userId);

            if (delHead != null)
            {
                ApplicationUser user = manager.FindById(delHead[0]);
                if (manager.IsInRole(user.Id, "Acting Department Head"))
                {
                    ViewBag.DelHead = delHead;
                }
            }
            return(View(viewModel));
        }
        public ActionResult Index()
        {
            string userId = User.Identity.GetUserId();
            DelegateHeadViewModel viewModel = new DelegateHeadViewModel(userId);

            ViewBag.DepName = viewModel.DepartmentName;
            return(View(viewModel));
        }