Exemple #1
0
        public void RunNotificationsAlgorithm(string ConnectionString, SendFormPageVM model, string Culture)
        {
            HrUnitOfWork unitofwork = new HrUnitOfWork(new HrContextFactory(ConnectionString));

            try
            {
                DateTime            Today = DateTime.Now.Date;
                List <int>          EmployeesToNotificate = GetEmpIdList(ConnectionString, model, Culture);
                string              FormName  = unitofwork.Repository <FlexForm>().Where(a => a.Id == model.FormId).SingleOrDefault().Name;
                List <FormDropDown> EmpsLangs = unitofwork.MeetingRepository.GetUsersLang((EmployeesToNotificate.Any()) ? EmployeesToNotificate.Select(a => a.ToString()).Aggregate <string>((x1, x2) => x1 + "," + x2).ToString() : "");
                foreach (var e in EmployeesToNotificate.Distinct())
                {
                    string Lang;
                    if (EmpsLangs.Select(a => a.id).Contains(e))
                    {
                        Lang = EmpsLangs.Where(a => a.id == e).FirstOrDefault().name;
                    }
                    else
                    {
                        Lang = Culture;
                    }
                    NotifyLetter NL = new NotifyLetter()
                    {
                        CompanyId    = model.CompanyId,
                        EmpId        = e,
                        NotifyDate   = Today,
                        NotifySource = MsgUtils.Instance.Trls(Lang, "Questionnaire") + " " + MsgUtils.Instance.Trls(Lang, FormName),
                        SourceId     = model.FormId.ToString(),
                        Sent         = true,
                        EventDate    = model.ExpiryDate,
                        Description  = MsgUtils.Instance.Trls(Lang, "Please fill") + " " + MsgUtils.Instance.Trls(Lang, FormName) + " " + MsgUtils.Instance.Trls(Lang, "Before") + " " + model.ExpiryDate.ToShortDateString()
                    };
                    unitofwork.NotifyLetterRepository.Add(NL);
                }


                unitofwork.SaveChanges();
            }

            catch (Exception ex)
            {
                unitofwork.HandleDbExceptions(ex);
            }
            finally
            {
            }
        }
Exemple #2
0
        public async Task <IHttpActionResult> ForgotPassword(ForgotPasswordMobileViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var user = db.Users.FirstOrDefault(u => u.UserName == model.Username && u.Email == model.Email);

            if (user == null)
            {
                return(NotFound());
            }

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

            if (code == null)
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }
            if (model.WithEmail == true)
            {
                var          callbackUrl = Url.Link("LogPattern", new { Controller = "Account", Action = "ResetPassword", userId = user.Id, UserName = user.UserName, code = code });
                EmailAccount emailAcc    = HrUnitOfWork.Repository <EmailAccount>().FirstOrDefault();
                emailAcc.EnableSsl = false;
                string Send = Db.Persistence.Services.EmailService.SendEmail(emailAcc, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>", user.Email, user.UserName, null, null);
                if (Send == "Error")
                {
                    return(BadRequest());
                }
                return(Ok(new ForgetDataViewModel()
                {
                    UserName = user.UserName, UserId = user.Id, Code = null
                }));
            }
            else
            {
                return(Ok(new ForgetDataViewModel()
                {
                    UserName = user.UserName, UserId = user.Id, Code = code
                }));
            }
        }
Exemple #3
0
        public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                //var user = await UserManager.FindByEmailAsync(model.Email);
                var user    = dbc.Users.FirstOrDefault(u => u.UserName == model.Username && u.Email == model.Email);
                var val     = Request.Cookies["culture"];
                var culture = (HttpContext.Request.Cookies["culture"] != null) ? Request.Cookies["culture"].Value : "en-GB";

                //|| !(await UserManager.IsEmailConfirmedAsync(user.Id))
                if (user == null)
                {
                    ModelState.AddModelError("Email", MsgUtils.Instance.Trls("incorrectuser", culture));
                    return(PartialView("ForgotPassword", model));
                    // Don't reveal that the user does not exist or is not confirmed
                }
                string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                var          callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, UserName = user.UserName, code = code }, protocol: Request.Url.Scheme);
                EmailAccount emailAcc    = HrUnitOfWork.Repository <EmailAccount>().FirstOrDefault();
                emailAcc.EnableSsl = false;
                string Send = Db.Persistence.Services.EmailService.SendEmail(emailAcc, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>", user.Email, user.UserName, null, null);
                if (Send == "Error")
                {
                    return(PartialView("Error"));
                }

                return(RedirectToAction("ForgotPasswordConfirmation", "Account"));
            }
            else
            {
                foreach (var item in ModelState)
                {
                    if (ModelState["Username"].Errors.Count > 0)
                    {
                        var req0 = item.Value.Errors.SingleOrDefault(a => a.ErrorMessage == "The Username field is required.");
                        item.Value.Errors.Remove(req0);
                        ModelState.AddModelError("Username", MsgUtils.Instance.Trls("userNameRequired", model.Culture));
                    }
                    else if (ModelState["Email"].Errors.Count > 0)
                    {
                        var req  = item.Value.Errors.SingleOrDefault(a => a.ErrorMessage == "The Email field is required.");
                        var req1 = item.Value.Errors.SingleOrDefault(a => a.ErrorMessage == "The Email field is not a valid e-mail address.");
                        if (req != null)
                        {
                            item.Value.Errors.Remove(req);
                            ModelState.AddModelError("Email", MsgUtils.Instance.Trls("emailRequired", model.Culture));
                        }
                        else if (req1 != null)
                        {
                            item.Value.Errors.Remove(req1);
                            ModelState.AddModelError("Email", MsgUtils.Instance.Trls("emailNotValid", model.Culture));
                        }
                    }
                }
                return(PartialView(model));
            }


            // If we got this far, something failed, redisplay form
        }
        /// <summary>
        /// shift business days + or - to specific no of days
        /// </summary>
        /// <param name="businessdate"></param>
        /// <param name="days"></param>
        /// <param name="sign"></param>
        /// <returns>new business date</returns>
        private static DateTime GetNotificationDate(HrUnitOfWork unitofwork, int company, Events e, string value)
        {
            DateTime businessdate = DateTime.Today;

            if (e == Events.IsDueIn)
            {
                return(businessdate);
            }

            int temp = 0;
            int sign = e == Events.WasDueThisAmountofTimeAgo ? -1 : 1;

            if (!string.IsNullOrEmpty(value))
            {
                int.TryParse(value, out temp);
            }
            NotifyDays days = (NotifyDays)temp;

            if (days == 0 || e == Events.IsDueIn)
            {
                return(businessdate);
            }
            var setup = unitofwork.CompanyRepository.GetPersonSetup(company);

            if (holidays == null)
            {
                holidays = unitofwork.Repository <Model.Domain.Holiday>()
                           .Where(a => a.CompanyId == company || !a.IsLocal)
                           .Select(a => new Holidays {
                    HoliDate = a.HoliDate, SDays = a.SDay, SMonth = a.SMonth, Standard = a.Standard
                })
                           .ToList();
            }


            if (days <= NotifyDays._13CalendarDays)
            {
                int i = 1;
                while (i <= (int)days)
                {
                    businessdate = businessdate.AddDays(i * sign);
                    if (!IsHoliday(setup, businessdate))
                    {
                        i++;
                    }
                }
            }
            else if (days == NotifyDays._2Weeks)
            {
                businessdate = businessdate.AddDays(14 * sign);
            }
            else if (days == NotifyDays._3Weeks)
            {
                businessdate = businessdate.AddDays(21 * sign);
            }
            else if (days == NotifyDays._1Month)
            {
                businessdate = businessdate.AddMonths(sign);
            }
            else if (days == NotifyDays._2Months)
            {
                businessdate = businessdate.AddMonths(2 * sign);
            }
            else if (days == NotifyDays._3Months)
            {
                businessdate = businessdate.AddMonths(3 * sign);
            }
            else if (days == NotifyDays._4Months)
            {
                businessdate = businessdate.AddMonths(4 * sign);
            }

            return(businessdate);
        }