Example #1
0
        public async Task <ActionResult> UserConfirm(string userId, string code, string Nt)
        {
            AppUser user    = UserManager.FindById(userId);
            double  timeInt = Convert.ToDouble(Nt);

            if (timeInt + 3 * 3600 <= TimeHelper.ConvertDateTimeInt(DateTime.UtcNow) || timeInt > TimeHelper.ConvertDateTimeInt(DateTime.UtcNow) || timeInt == 0)
            {
                return(RedirectToAction("Error404", "Account", new { ErrorMessage = "Link Has Expired" }));
            }
            EnsureLoggedOut();
            if (userId == null || code == null || user == null)
            {
                return(RedirectToLocal());
            }
            if (await UserManager.IsEmailConfirmedAsync(userId))
            {
                return(RedirectToLocal());
            }
            UserConfirmModel mode = new UserConfirmModel()
            {
                Code = code,
                Id   = userId
            };

            ViewBag.UserName = user.PayRollUser;
            return(View(mode));
        }
Example #2
0
        public JsonResult TimeOut(TimeSheetLog TSL)
        {
            AppUser user           = LoginUser;
            Company c              = db.Company.Find(user.CompanyId);
            float   DayRuleValue   = c.DayRuleValue * 60;
            bool    DayRule        = c.DayRule;
            float   DoubeRuleValue = c.DoubeRuleValue * 60;
            bool    DoubeRule      = c.DoubeRule;

            var log        = user.TimeSheetLog.Where(t => t.Status == false).LastOrDefault();
            var utcNowTime = DateTime.UtcNow;

            if (user.Company.DaylightSavingTime && log.isDayLightTime)
            {
                utcNowTime = utcNowTime.AddHours(1);
            }
            var       e             = user.Employee.SingleOrDefault();
            Double    TotalWorkTime = Math.Floor(((TimeHelper.ConvertDateTimeInt(utcNowTime) - TimeHelper.ConvertDateTimeInt(log.StartDate)) / 60) / Convert.ToDouble(user.Company.RoundTo)) * Convert.ToDouble(user.Company.RoundTo);
            TimeSheet ts            = new TimeSheet
            {
                Id               = Guid.NewGuid(),
                StartDate        = log.StartDate,
                StopDate         = utcNowTime,
                Note             = log.Note,
                Paid             = false,
                TimeSheetDate    = utcNowTime,
                TimeSheetType    = 2,
                TotalWorkTime    = TotalWorkTime,
                RegulaWorkTime   = 0,
                OverTimeWorkTime = 0,
                DoubleWorkTime   = 0,
                RegularPayrate   = e.F100,
                OvertimePayrate  = e.F101,
                DoublePayrate    = e.F1002,
                Status           = "1",
                EmployeeId       = e.EmployeeId,
                JobId            = log.JobId,
                CompanyId        = user.CompanyId
            };

            if (DoubeRule)
            {
                ts.DoubleWorkTime = MathWorkTime(TotalWorkTime - DoubeRuleValue);
            }
            if (DayRule)
            {
                ts.OverTimeWorkTime = MathWorkTime(TotalWorkTime - ts.DoubleWorkTime - DayRuleValue);
            }
            ts.RegulaWorkTime = MathWorkTime(TotalWorkTime - ts.DoubleWorkTime - ts.OverTimeWorkTime);

            log.StopDate = utcNowTime;
            log.Status   = true;
            db.Entry <TimeSheetLog>(log).State = System.Data.Entity.EntityState.Modified;
            db.TimeSheet.Add(ts);
            db.SaveChanges();
            return(Json(new { code = "1", message = "success!" }, JsonRequestBehavior.AllowGet));
        }
Example #3
0
        public ActionResult EditTime()
        {
            Guid      id             = new Guid(Request["Id"]);
            DateTime  StartDate      = Convert.ToDateTime(Request["StartDate"]);
            DateTime  StopDate       = Convert.ToDateTime(Request["StopDate"]);
            int       Type           = int.Parse(Request["TimeSheetType"]);
            Double    TotalWorkTime  = Math.Floor(((TimeHelper.ConvertDateTimeInt(StopDate) - TimeHelper.ConvertDateTimeInt(StartDate)) / 60) / Convert.ToDouble(LoginUser.Company.RoundTo)) * Convert.ToDouble(LoginUser.Company.RoundTo);
            bool      Paid           = (Request["Paid"] == "true") ? true : false;
            string    Note           = Request["Note"];
            Company   c              = db.Company.Find(LoginUser.CompanyId);
            float     DayRuleValue   = c.DayRuleValue * 60;
            bool      DayRule        = c.DayRule;
            float     DoubeRuleValue = c.DoubeRuleValue * 60;
            bool      DoubeRule      = c.DoubeRule;
            TimeSheet ts             = db.TimeSheet.Find(id);

            ts.StartDate        = TimeHelper.GetUTCTime(StartDate, Convert.ToDouble(LoginUser.TimeZone));
            ts.StopDate         = TimeHelper.GetUTCTime(StopDate, Convert.ToDouble(LoginUser.TimeZone));
            ts.Status           = "2";
            ts.Note             = Note;
            ts.Paid             = Paid;
            ts.TimeSheetType    = Type;
            ts.TotalWorkTime    = TotalWorkTime;
            ts.RegulaWorkTime   = 0;
            ts.OverTimeWorkTime = 0;
            ts.DoubleWorkTime   = 0;
            if (Type == 2)    //如果是普通时间
            {
                if (DoubeRule)
                {
                    ts.DoubleWorkTime = MathWorkTime(TotalWorkTime - DoubeRuleValue);
                }
                if (DayRule)
                {
                    ts.OverTimeWorkTime = MathWorkTime(TotalWorkTime - ts.DoubleWorkTime - DayRuleValue);
                }
                ts.RegulaWorkTime = MathWorkTime(TotalWorkTime - ts.DoubleWorkTime - ts.OverTimeWorkTime);
            }
            else if (Type == 3)    //如果类型是加班时间
            {
                ts.OverTimeWorkTime = TotalWorkTime;
            }
            else if (Type == 4)
            {    //如果类型是双倍时间
                ts.DoubleWorkTime = TotalWorkTime;
            }
            ;
            db.SaveChanges();
            return(Json(new { code = "1", status = "success" }, JsonRequestBehavior.AllowGet));
        }
Example #4
0
        public JsonResult TimeDesc(Guid Id)
        {
            TS_Edit e  = new TS_Edit();
            var     ts = db.TimeSheet.Where <TimeSheet>(t => t.Id == Id).ToList().Single();

            e.Job           = ts.Job.JobName;
            e.Employee      = ts.Employee.FName + " " + ts.Employee.LName;
            e.TimeSheetType = ts.TimeSheetType;
            e.TotalWorkTime = ts.TotalWorkTime;
            e.Note          = ts.Note;
            e.Paid          = ts.Paid;
            e.StartDate     = TimeHelper.ConvertDateTimeInt(TimeHelper.GetLocalTime(ts.StartDate, Convert.ToDouble(LoginUser.TimeZone)));
            e.StopDate      = TimeHelper.ConvertDateTimeInt(TimeHelper.GetLocalTime(ts.StopDate, Convert.ToDouble(LoginUser.TimeZone)));
            return(Json(e, JsonRequestBehavior.AllowGet));
        }
Example #5
0
        public async Task <ActionResult> CompleteRegist(string userId, string code, string Nt)
        {
            double timeInt = Convert.ToDouble(Nt);

            if (timeInt + 3 * 3600 <= TimeHelper.ConvertDateTimeInt(DateTime.UtcNow) || timeInt > TimeHelper.ConvertDateTimeInt(DateTime.UtcNow) || timeInt == 0)
            {
                return(RedirectToAction("Error404", "Account", new { ErrorMessage = "Link Has Expired" }));
            }
            EnsureLoggedOut();
            //EnsureLoggedOut();
            Dictionary <string, string> StaList = EnumHelper.GetEnumItemDesc(typeof(States));

            ViewBag.StatesList = new SelectList(StaList, "key", "value");
            //Dictionary<string, object> StaList = EnumHelper.EnumListDic<States>("", "");
            //ViewBag.StatesList = new SelectList(StaList, "value", "key");
            Dictionary <string, object> RoundTo = EnumHelper.EnumListDic <RoundTo>("", "");

            ViewBag.RoundTo  = new SelectList(RoundTo, "value", "key");
            ViewBag.TimeZone = SelectHelper.TimeZoneToSelect(db);

            if (userId == null || code == null)
            {
                return(RedirectToLocal());
            }
            if (await UserManager.IsEmailConfirmedAsync(userId))
            {
                return(RedirectToLocal());
            }
            AppUser user = await UserManager.FindByIdAsync(userId);

            CompleteRegistModel mode = new CompleteRegistModel()
            {
                code        = code,
                Email       = user.Company.Email,
                CompanyName = user.Company.CompanyName
            };

            return(View(mode));
        }
Example #6
0
        public ActionResult ResetPassword(string userId, string code, string Nt)
        {
            //链接过期
            double timeInt = Convert.ToDouble(Nt);

            if (timeInt + 3 * 3600 <= TimeHelper.ConvertDateTimeInt(DateTime.UtcNow) || timeInt > TimeHelper.ConvertDateTimeInt(DateTime.UtcNow) || timeInt == 0)
            {
                return(RedirectToAction("Error404", "Account", new { ErrorMessage = "Link Has Expired" }));
            }
            EnsureLoggedOut();
            //HttpContext.User = new GenericPrincipal(new GenericIdentity(string.Empty), null);
            if (userId == null || code == null)
            {
                return(RedirectToLocal());
            }
            AccountResetPasswordModel mode = new AccountResetPasswordModel()
            {
                Code = code, UserId = userId
            };
            AppUser user = UserManager.FindById(userId);

            ViewBag.UserInfo = user.Email + "  [ " + user.PayRollUser + " ]";
            return(View(mode));
        }
Example #7
0
        public ActionResult Add(User user)
        {
            user.IsActive = true;
            // MD5加密
            user.Password = SecurityHelper.str2md5(user.Password);
            // 将时间转换为时间戳
            user.CreateTime = TimeHelper.ConvertDateTimeInt(DateTime.Now);
            // 受影响的行数(为1,则表示成功)
            int issuccess = userInfo.Add(user);

            //if (issuccess > 0)
            //{
            //    return Content("ok");
            //}
            //else
            //{
            //    return Content("no");
            //}
            if (issuccess == 1)
            {
                var ret = new
                {
                    message = true
                };
                // 返回json
                return(Json(ret, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var ret = new
                {
                    message = false
                };
                return(Json(ret, JsonRequestBehavior.AllowGet));
            }
        }
Example #8
0
        public ActionResult AddTime()
        {
            Guid     EmployeeId    = new Guid(Request["EmployeeId"]);
            int      JobId         = int.Parse(Request["JobId"]);
            DateTime StartDate     = Convert.ToDateTime(Request["StartDate"]);
            DateTime StopDate      = Convert.ToDateTime(Request["StopDate"]);
            int      Type          = int.Parse(Request["TimeSheetType"]);
            Double   TotalWorkTime = Math.Floor(((TimeHelper.ConvertDateTimeInt(StopDate) - TimeHelper.ConvertDateTimeInt(StartDate)) / 60) / Convert.ToDouble(LoginUser.Company.RoundTo)) * Convert.ToDouble(LoginUser.Company.RoundTo);
            bool     Paid          = (Request["Paid"] == "true") ? true : false;
            string   Note          = Request["Note"];

            AppUser user = LoginUser;

            Company c              = db.Company.Find(user.CompanyId);
            float   DayRuleValue   = c.DayRuleValue * 60;
            bool    DayRule        = c.DayRule;
            float   DoubeRuleValue = c.DoubeRuleValue * 60;
            bool    DoubeRule      = c.DoubeRule;
            //Company c = db.Company.Where(t => t.CompanyId == user.CompanyId).SingleOrDefault();
            //if (c.DaylightSavingTime) {
            //    StartDate = StartDate.AddHours(1);
            //    StopDate = StopDate.AddHours(1);
            //}
            Employee  e  = db.Employee.Find(EmployeeId);
            TimeSheet ts = new TimeSheet
            {
                Id               = Guid.NewGuid(),
                StartDate        = TimeHelper.GetUTCTime(StartDate, Convert.ToDouble(user.TimeZone)),
                StopDate         = TimeHelper.GetUTCTime(StopDate, Convert.ToDouble(user.TimeZone)),
                Note             = Note,
                Paid             = Paid,
                TimeSheetDate    = DateTime.UtcNow,
                TimeSheetType    = Type,
                TotalWorkTime    = TotalWorkTime,
                RegulaWorkTime   = 0,
                OverTimeWorkTime = 0,
                DoubleWorkTime   = 0,
                RegularPayrate   = e.F100,
                OvertimePayrate  = e.F101,
                DoublePayrate    = e.F1002,
                Status           = "2",
                EmployeeId       = EmployeeId,
                JobId            = JobId,
                CompanyId        = user.CompanyId
            };

            if (Type == 2)    //如果是普通时间
            {
                if (DoubeRule)
                {
                    ts.DoubleWorkTime = MathWorkTime(TotalWorkTime - DoubeRuleValue);
                }
                if (DayRule)
                {
                    ts.OverTimeWorkTime = MathWorkTime(TotalWorkTime - ts.DoubleWorkTime - DayRuleValue);
                }
                ts.RegulaWorkTime = MathWorkTime(TotalWorkTime - ts.DoubleWorkTime - ts.OverTimeWorkTime);
            }
            else if (Type == 3)    //如果类型是加班时间
            {
                ts.OverTimeWorkTime = TotalWorkTime;
            }
            else if (Type == 4)      //如果类型是双倍时间
            {
                ts.DoubleWorkTime = TotalWorkTime;
            }
            ;
            db.TimeSheet.Add(ts);
            db.SaveChanges();
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("code", 1);
            dic.Add("status", "success");
            return(Json(dic, JsonRequestBehavior.AllowGet));
        }
Example #9
0
        public async Task <ActionResult> SemdEmail(string Id)
        {
            AppUser user = UserManager.FindById(Id);
            string  code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

            var    callbackUrl = Url.Action("UserConfirm", "Account", new { userId = user.Id, code = code, Nt = TimeHelper.ConvertDateTimeInt(DateTime.UtcNow) }, protocol: Request.Url.Scheme);
            string EmailBody   = "Thank you for creating an PayRoll account. You need to confirm your account and setting your password, you'll have access to PayRoll system.";
            string EmailLink   = "Please confirm your account complete regist by clicking.<a href=\"" + callbackUrl + "\">Click it! &raquo;</a>";
            string strbody     = ReplaceText(EmailBody, EmailLink);
            await UserManager.SendEmailAsync(user.Id, "Confirm Your Account  (" + user.PayRollUser + ")", strbody);

            return(Json(new { code = 1, message = "success" }, JsonRequestBehavior.AllowGet));
        }
Example #10
0
        public async Task <ActionResult> ResendEmail(string Email)
        {
            var user = await UserManager.FindByEmailAsync(Email);

            string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

            string Pcode = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

            //code = HttpUtility.UrlEncode(code);
            if (UserManager.IsInRole(user.Id, "Admin"))
            {
                var    callbackUrl = Url.Action("CompleteRegist", "Account", new { userId = user.Id, code = code, Nt = TimeHelper.ConvertDateTimeInt(DateTime.UtcNow) }, protocol: Request.Url.Scheme);
                string EmailBody   = "Thank you for creating an PayRoll account. You need to complete the registration information and confirm your account, you'll have access to PayRoll system.";
                string EmailLink   = "Please confirm your account complete regist by clicking.<a href=\"" + callbackUrl + "\">Click it! &raquo;</a>";
                string strbody     = ReplaceText(EmailBody, EmailLink);
                await UserManager.SendEmailAsync(user.Id, "Confirm Your Account – Complete Registration Information (" + user.Company.CompanyName + ")", strbody);
            }
            else
            {
                var    callbackUrl = Url.Action("UserConfirm", "Account", new { userId = user.Id, code = code, Nt = TimeHelper.ConvertDateTimeInt(DateTime.UtcNow) }, protocol: Request.Url.Scheme);
                string EmailBody   = "Thank you for creating an PayRoll account. You need to confirm your account and setting your password, you'll have access to PayRoll system.";
                string EmailLink   = "Please confirm your account complete regist by clicking.<a href=\"" + callbackUrl + "\">Click it! &raquo;</a>";
                string strbody     = ReplaceText(EmailBody, EmailLink);
                await UserManager.SendEmailAsync(user.Id, "Confirm Your Account  (" + user.PayRollUser + ")", strbody);
            }


            ViewBag.ReceiveEmail = user.Email;
            return(View("WaitEmail"));
        }
Example #11
0
        public async Task <ActionResult> ForgotPassword(AccountForgotPasswordModel viewModel)
        {
            AppUser user = UserManager.FindByEmail(viewModel.Email);

            if (user == null)
            {
                ModelState.AddModelError("", "The user is not found.");
                return(View(viewModel));
            }
            ;
            if (!await UserManager.IsEmailConfirmedAsync(user.Id))
            {
                return(RedirectToAction("ConfirmedEmail", "Account", new { Email = user.Email }));
            }
            string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

            //code = HttpUtility.UrlEncode(code);
            var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code, Nt = TimeHelper.ConvertDateTimeInt(DateTime.UtcNow) }, protocol: Request.Url.Scheme);

            string EmailBody = "Please resetting your password by clicking.";
            string EmailLink = "Please resetting your password by clicking.<a href=\"" + callbackUrl + "\">Click it! &raquo;</a>";
            string strbody   = ReplaceText(EmailBody, EmailLink);
            await UserManager.SendEmailAsync(user.Id, "Password Reset – Livell PayRoll (" + user.Email + ")", strbody);

            //await UserManager.SendEmailAsync(
            //    user.Id,
            //   "Password Reset – Livell PayRoll (" + user.Email + ")",
            //   "Dear LivellPayRoll Customer:<br><br> Please resetting your password by clicking <a href=\"" + callbackUrl + "\">link</a><br><br> —The LivellPayRoll Team");
            ViewBag.ReceiveEmail = user.Email;
            return(View("WaitEmail"));
        }
Example #12
0
        //[ValidateAntiForgeryToken]
        public async Task <ActionResult> Register(AccountRegistrationModel viewModel)
        {
            Dictionary <string, string> StaList = EnumHelper.GetEnumItemDesc(typeof(States));

            ViewBag.StatesList = new SelectList(StaList, "key", "value");
            ViewBag.TimeZone   = SelectHelper.TimeZoneToSelect(db);;
            // Ensure we have a valid viewModel to work with
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            // Prepare the identity with the provided information
            DateTime dt      = DateTime.UtcNow;
            Company  company = new Company
            {
                CompanyName        = viewModel.CompanyName,
                Address1           = viewModel.Address,
                City               = viewModel.City,
                State              = viewModel.State,
                Telphone           = viewModel.Telphone,
                TimeZone           = viewModel.TimeZone,
                Email              = viewModel.Email,
                Zip                = viewModel.Zip,
                TradeName          = viewModel.TradeName,
                PayFreq            = "Weekly",
                Country            = "United States",
                RoundTo            = "15",
                PayRollRegTime     = dt,
                WeekRule           = true,
                WeekRuleValue      = 40,
                DayRule            = true,
                DayRuleValue       = 8,
                DoubeRule          = true,
                DoubeRuleValue     = 12,
                DaylightSavingTime = true,
                Status             = "3"
            };
            var user = new AppUser
            {
                UserName      = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Millisecond.ToString(),
                Email         = viewModel.Email,
                TimeZone      = viewModel.TimeZone,
                LastLoginDate = DateTime.UtcNow,
                Company       = company
            };


            // Try to create a user with the given identity
            try
            {
                var result = await UserManager.CreateAsync(user, "Pay123456");

                // If the user could not be created
                if (!result.Succeeded)
                {
                    // Add all errors to the page so they can be used to display what went wrong
                    AddErrors(result);
                    return(View(viewModel));
                }

                if (!UserManager.IsInRole(user.Id, "Admin"))
                {
                    UserManager.AddToRole(user.Id, "Admin");
                }
                string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                var callbackUrl = Url.Action("CompleteRegist", "Account", new { userId = user.Id, code = code, Nt = TimeHelper.ConvertDateTimeInt(DateTime.UtcNow) }, protocol: Request.Url.Scheme);

                string EmailBody = "Thank you for creating an PayRoll account. You need to complete the registration information and confirm your account, you'll have access to PayRoll system.";
                string EmailLink = "Please confirm your account complete regist by clicking.<a href=\"" + callbackUrl + "\">Click it! &raquo;</a>";
                string strbody   = ReplaceText(EmailBody, EmailLink);
                await UserManager.SendEmailAsync(user.Id, "Confirm Your Account – Complete Registration Information (" + user.Company.CompanyName + ")", strbody);

                ViewBag.ReceiveEmail = user.Email;
                return(View("WaitEmail"));
                //return RedirectToLocal();
            }
            catch (DbEntityValidationException ex)
            {
                // Add all errors to the page so they can be used to display what went wrong
                AddErrors(ex);

                return(View(viewModel));
            }
        }
Example #13
0
        public async Task <ActionResult> Add(ManagerUserMode viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }
            AppUser Admin = LoginUser;
            AppUser user  = UserManager.FindByEmail(viewModel.Email);

            if (user != null)
            {
                ModelState.AddModelError("", "The email has been registered!");
                return(View(viewModel));
            }
            user = new AppUser
            {
                UserName    = viewModel.Email,
                Email       = viewModel.Email,
                PayRollUser = viewModel.UserName,
                PhoneNumber = viewModel.Phone,
                TimeZone    = Admin.TimeZone,
                CompanyId   = Admin.CompanyId
            };
            var result = await UserManager.CreateAsync(user, "Pay123456");

            if (result.Succeeded)
            {
                if (!UserManager.IsInRole(user.Id, "Manager"))
                {
                    UserManager.AddToRole(user.Id, "Manager");
                }

                string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                var    callbackUrl = Url.Action("UserConfirm", "Account", new { userId = user.Id, code = code, Nt = TimeHelper.ConvertDateTimeInt(DateTime.UtcNow) }, protocol: Request.Url.Scheme);
                string EmailBody   = "Thank you for creating an PayRoll account. You need to confirm your account and setting your password, you'll have access to PayRoll system.";
                string EmailLink   = "Please confirm your account complete regist by clicking.<a href=\"" + callbackUrl + "\">Click it! &raquo;</a>";
                string strbody     = ReplaceText(EmailBody, EmailLink);
                await UserManager.SendEmailAsync(user.Id, "Confirm Your Account  (" + user.PayRollUser + ")", strbody);
            }
            return(RedirectToAction("Mlist"));
        }