Exemplo n.º 1
0
        // GET: TimeSheet
        public async Task <ActionResult> Index(int message = 0)
        {
            ViewBag.Manager = UserRoleSetting.GetManagerItems();
            int year   = DateTime.Now.Year;
            int period = (int)(DateTime.Now - PayPeriod.FirstPayDayOfYear(year)).Days / 14 + 2;
            TimeSheetContainer model = await GetTimeSheetModel(year, period);

            model.YearList = PayPeriod.GetYearItems();
            switch (message)
            {
            case 0:
                ViewBag.Message = "";
                break;

            case 1:
                ViewBag.Message = "Please save timesheet before submit";
                break;

            case 2:
                ViewBag.Message = "Timesheet approval email has been sent successfully";
                break;

            case 3:
                ViewBag.Message = "Timesheet has been saved successfully";
                break;

            default:
                ViewBag.Message = "no message";
                break;
            }
            return(View(model));
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Create a tab page for user to apply casual work hours.
        /// </summary>
        /// <returns>A partial view with details of an application of casual work hours.</returns>
        public ActionResult Casual()
        {
            TimeSheetContainer model = new TimeSheetContainer();

            //get droplists of year and managers
            model.YearList  = PayPeriod.GetYearItems();
            ViewBag.Manager = UserRoleSetting.GetManagerItems();

            return(PartialView("_Casual", model));
        }
Exemplo n.º 3
0
        public ActionResult EditUserRole(int id)
        {
            UserRoleSetting model = adminDb.UserRoleSettings.Find(id);

            if (model == null)
            {
                return(HttpNotFound());
            }
            return(View(model));
        }
Exemplo n.º 4
0
        public static UserRoleSetting GetUserRole(String email)
        {
            UserRoleSetting userRole = null;

            using (AdminDb context = new AdminDb())
            {
                userRole = (from m in context.UserRoleSettings
                            where m.UserID == email
                            select m).FirstOrDefault();
            }
            return(userRole);
        }
Exemplo n.º 5
0
        public ActionResult DeleteUserRole(int id)
        {
            UserRoleSetting model = adminDb.UserRoleSettings.Find(id);

            if (model == null)
            {
                return(HttpNotFound());
            }
            adminDb.UserRoleSettings.Remove(model);
            adminDb.SaveChanges();
            return(RedirectToAction("UserRoleSetting"));
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Create a tab page for user to fill and submit a HR application.
        /// </summary>
        /// <returns>A partial view with details of an application.</returns>
        public ActionResult Leave()
        {
            LeaveApplicationViewModel model         = new LeaveApplicationViewModel();
            List <LeaveBalance>       LeaveBalances = new List <LeaveBalance>();

            //get manager dropdown list
            ViewBag.Manager = UserRoleSetting.GetManagerItems();

            for (int i = 0; i < 3; i++)
            {
                var availableLeave = contextDb.LeaveBalances.Find(User.Identity.Name, (_leaveType)i);
                LeaveBalances.Add(availableLeave == null ? new LeaveBalance() : availableLeave);
            }
            model.LeaveBalances = LeaveBalances;

            return(PartialView("_Leave", model));
        }
Exemplo n.º 7
0
 public ActionResult EditUserRole(UserRoleSetting model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             adminDb.UserRoleSettings.Attach(model);
             adminDb.Entry(model).State = EntityState.Modified;
             adminDb.SaveChanges();
         }
         return(RedirectToAction("UserRoleSetting"));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 8
0
 public ActionResult CreateUserRole(UserRoleSetting model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (model != null)
             {
                 adminDb.UserRoleSettings.Add(model);
                 adminDb.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(RedirectToAction("UserRoleSetting"));
 }
Exemplo n.º 9
0
        public void ConfigureAuth(IAppBuilder app)
        {
            ApplicationDb db = new ApplicationDb();

            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
            app.UseKentorOwinCookieSaver();
            app.UseCookieAuthentication(new CookieAuthenticationOptions());

            app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
            {
                ClientId              = clientId,
                Authority             = Authority,
                PostLogoutRedirectUri = postLogoutRedirectUri,

                TokenValidationParameters = new System.IdentityModel.Tokens.TokenValidationParameters
                {
                    // map the claimsPrincipal's roles to the roles claim
                    RoleClaimType = "roles",
                },

                Notifications = new OpenIdConnectAuthenticationNotifications()
                {
                    // If there is a code in the OpenID Connect response, redeem it for an access token and refresh token, and store those away.

                    RedirectToIdentityProvider = ctx =>
                    {
                        bool isAjaxRequest = (ctx.Request.Headers != null && ctx.Request.Headers["X-Requested-With"] == "XMLHttpRequest");

                        if (isAjaxRequest)
                        {
                            ctx.Response.Headers.Remove("Set-Cookie");
                            ctx.State = NotificationResultState.HandledResponse;
                        }

                        return(Task.FromResult(0));
                    },
                    AuthorizationCodeReceived = (context) =>
                    {
                        var code = context.Code;
                        ClientCredential credential       = new ClientCredential(clientId, appKey);
                        string signedInUserID             = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value;
                        AuthenticationContext authContext = new AuthenticationContext(Authority, new ADALTokenCache(signedInUserID));
                        AuthenticationResult result       = authContext.AcquireTokenByAuthorizationCode(
                            code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, graphResourceId);

                        // Set up user roles
                        UserRoleSetting userRole = AADHelper.GetUserRole(context.AuthenticationTicket.Identity.Name);
                        if (userRole != null)
                        {
                            if (userRole.IsAdmin)
                            {
                                context.AuthenticationTicket.Identity.AddClaim(new Claim("roles", "Admin"));
                                context.AuthenticationTicket.Identity.AddClaim(new Claim("roles", "Manager"));
                            }
                            else
                            {
                                if (userRole.IsManager)
                                {
                                    context.AuthenticationTicket.Identity.AddClaim(new Claim("roles", "Manager"));
                                }
                                if (userRole.IsAccountant)
                                {
                                    context.AuthenticationTicket.Identity.AddClaim(new Claim("roles", "Accountant"));
                                }
                            }
                            switch (userRole.WorkType)
                            {
                            case UserRoleSetting._worktype.fulltime:
                                context.AuthenticationTicket.Identity.AddClaim(new Claim("roles", "FullTimeWorker"));
                                break;

                            case UserRoleSetting._worktype.parttime:
                                context.AuthenticationTicket.Identity.AddClaim(new Claim("roles", "PartTimeWorker"));
                                break;

                            case UserRoleSetting._worktype.casual:
                                context.AuthenticationTicket.Identity.AddClaim(new Claim("roles", "CasualWorker"));
                                break;

                            default:
                                context.AuthenticationTicket.Identity.AddClaim(new Claim("roles", "FullTimeWorker"));
                                break;
                            }
                        }
                        else
                        {
                            context.AuthenticationTicket.Identity.AddClaim(new Claim("roles", "FullTimeWorker"));
                        }

                        return(Task.FromResult(0));
                    }
                }
            });
        }