Exemplo n.º 1
0
 public static string VerifyUserAccount(string encodedId, VerifyUser verifyEmp)
 {
     using (PsiogEntities PE = new PsiogEntities())
     {
         var id   = Hasher.DecodeId(encodedId);
         var user = PE.Users.Where(u => u.EmployeeId == id).FirstOrDefault();
         if (user.VerificationCode == null)
         {
             return("Unauthorised!");
         }
         user.Password         = Hasher.HashString(verifyEmp.password);
         user.SecurityQuestion = verifyEmp.securityQuestion;
         user.Answer           = verifyEmp.answer;
         user.VerificationCode = null;
         try
         {
             PE.SaveChanges();
             return("Verified Successfully!");
         }
         catch (Exception E)
         {
             ExceptionLog.Logger(E);
             return("Unable to verify user");
         }
     }
 }
Exemplo n.º 2
0
        public static bool AddEmployee(Employee e, out string msg)
        {
            msg = "";

            try
            {
                using (PsiogEntities PE = new PsiogEntities())
                {
                    var check = PE.Employees.Where(c => c.Email == e.Email).FirstOrDefault();
                    if (check != null)
                    {
                        msg = "Email ID already exists!";
                        return(false);
                    }
                    var max = PE.Employees.Max(m => m.Id) + 1;
                    e.EmployeeId = "P" + max.ToString();
                    PE.Employees.Add(e);

                    PE.SaveChanges();
                }
            }
            catch (Exception E)
            {
                ExceptionLog.Logger(E);
                msg = "Failed to add employee";
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        public static string ApplyLeave(LeaveApplication leave, string id)
        {
            using (PsiogEntities PE = new PsiogEntities())
            {
                try
                {
                    var leaveBalance = PE.EmployeeLeaveAvaliabilities.Where(emp => emp.EmployeeId == id && emp.LeaveTypeId == leave.LeaveId).FirstOrDefault();


                    decimal availedDays = (leave.ToDate.Subtract(leave.FromDate)).Days;
                    if (leave.FromSession == leave.ToSession)
                    {
                        availedDays = availedDays + 0.5M;
                    }
                    decimal balance = leaveBalance.AllocatedDays - leaveBalance.AvailedDays;
                    if (availedDays <= balance)
                    {
                        try
                        {
                            var l = new LeaveApplication();
                            leave.Status  = "Applied";
                            l.Status      = leave.Status;
                            l.FromDate    = leave.FromDate;
                            l.ToDate      = leave.ToDate;
                            l.FromSession = leave.FromSession;
                            l.ToSession   = leave.ToSession;
                            l.Reason      = leave.Reason;
                            l.LeaveId     = leave.LeaveId;
                            l.SendTo      = leave.SendTo;
                            l.EmployeeId  = id;


                            PE.LeaveApplications.Add(l);
                            leaveBalance.AvailedDays = availedDays;
                            PE.SaveChanges();
                            return("Leave Application Submitted! Waiting For Approval");
                        }
                        catch (Exception E)
                        {
                            ExceptionLog.Logger(E);
                            return("Unable to apply leave");
                        }
                    }

                    else
                    {
                        return("You do not have enough leave balance");
                    }
                }
                catch (Exception E)
                {
                    ExceptionLog.Logger(E);
                    return("Unable to apply leave. Please try again");
                }
            }
        }
Exemplo n.º 4
0
        public IHttpActionResult GetResetLink(ForgotPassword resetter)
        {
            using (PsiogEntities PE = new PsiogEntities())
            {
                string VerificationCode = Guid.NewGuid().ToString();
                string encodedId        = Hasher.EncodeId(resetter.employeeId);
                var    link             = "http://localhost:4200/verify-employee/" + Hasher.EncodeId(resetter.employeeId);

                var result = PE.Users.Where(u => u.EmployeeId == resetter.employeeId).FirstOrDefault();

                if (result != null)
                {
                    if (string.Compare(result.Answer, resetter.answer) == 0)
                    {
                        var employee = PE.Employees.Where(u => u.EmployeeId == resetter.employeeId).FirstOrDefault();
                        result.VerificationCode = VerificationCode;
                        try
                        {
                            PE.SaveChanges();
                        }
                        catch (Exception E)
                        {
                            ExceptionLog.Logger(E);
                            return(Ok("Unable to get reset link"));
                        }
                        var mail = ComposeMail.SendResetLink(employee.Email, out SmtpClient messenger);

                        mail.Body += link + ">Click here to reset password</a>";
                        messenger.Send(mail);
                        messenger.Dispose();
                        return(Ok("Reset link has been sent to your registered email ID"));
                    }

                    else
                    {
                        return(Ok("Incorrect answer for security question"));
                    }
                }

                else
                {
                    return(Ok("Employee Id does not exist!"));
                }
            }
        }
Exemplo n.º 5
0
        public static string ResetPassword(string password, string id)
        {
            using (PsiogEntities PE = new PsiogEntities())
            {
                var user = PE.Users.Where(u => u.EmployeeId == id).FirstOrDefault();
                user.Password = Hasher.HashString(password);

                try
                {
                    PE.SaveChanges();
                    return("Updated password successfully");
                }
                catch (Exception E)
                {
                    ExceptionLog.Logger(E);
                    return("Unable to update password. Please try again");
                }
            }
        }
Exemplo n.º 6
0
        public static bool AddReportingAuthorities(string empId, string authName)
        {
            if (authName != null)
            {
                try
                {
                    using (PsiogEntities PE = new PsiogEntities())
                    {
                        string authorityId = (from emp in PE.Employees
                                              where emp.Name == authName
                                              select emp.EmployeeId).FirstOrDefault();
                        if (authorityId != null)
                        {
                            ReportingAuthority RA = new ReportingAuthority
                            {
                                EmployeeId = empId,
                                ManagerId  = authorityId
                            };

                            PE.ReportingAuthorities.Add(RA);
                            PE.SaveChanges();
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                catch (Exception E)
                {
                    ExceptionLog.Logger(E);

                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 7
0
        public static bool AddUser(Employee e)
        {
            try
            {
                using (PsiogEntities PE = new PsiogEntities())
                {
                    User newUser = new User
                    {
                        EmployeeId       = e.EmployeeId,
                        Password         = Hasher.HashString(Guid.NewGuid().ToString()),
                        Role             = "User",
                        VerificationCode = Guid.NewGuid().ToString(),
                    };

                    PE.Users.Add(newUser);
                    PE.SaveChanges();
                    return(true);
                }
            } catch (Exception E)
            {
                ExceptionLog.Logger(E);
                return(false);
            }
        }
Exemplo n.º 8
0
        public HttpResponseMessage ChangeStatus(Approveleaves l)
        {
            using (PsiogEntities PE = new PsiogEntities())
            {
                var appl = PE.LeaveApplications.Where(u => u.LeaveApplicationId == l.id).FirstOrDefault();
                appl.Status = l.status;
                string msg = "";

                if (l.status == "Rejected")
                {
                    var rollback = (from avail in PE.EmployeeLeaveAvaliabilities
                                    join leaveapp in PE.LeaveApplications
                                    on avail.LeaveTypeId equals leaveapp.LeaveId
                                    where leaveapp.LeaveApplicationId == l.id
                                    select new
                    {
                        avail.AllocatedDays,
                        leaveapp.FromDate,
                        leaveapp.ToDate,
                        leaveapp.FromSession,
                        leaveapp.ToSession,
                        avail.Id
                    }).FirstOrDefault();
                    int     rollbackdays    = (rollback.ToDate - rollback.FromDate).Days;
                    decimal rollbacksession = 0M;
                    if (rollback.FromSession == rollback.ToSession)
                    {
                        rollbacksession = 0.5M;
                    }

                    else if (rollback.FromSession > rollback.ToSession)
                    {
                        rollbacksession = 0M;
                    }
                    else
                    {
                        rollbacksession = 1M;
                    }

                    decimal updatedRollback         = rollbackdays + rollbacksession;
                    var     updateLeaveAvailability = PE.EmployeeLeaveAvaliabilities.Where(e => e.Id == rollback.Id).FirstOrDefault();
                    updateLeaveAvailability.AvailedDays = updatedRollback;
                }
                else if (l.status == "Approved")
                {
                    appl.Status = "Approved";
                }
                try
                {
                    PE.SaveChanges();
                    msg = "Done!";
                }
                catch (Exception E)
                {
                    ExceptionLog.Logger(E);
                    msg = "Unable to process request";
                }
                HttpResponseMessage response;
                response = Request.CreateResponse(HttpStatusCode.OK, msg);
                return(response);
            }
        }