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 HttpResponseMessage ApproveLeave()
        {
            var       identity = (ClaimsIdentity)User.Identity;
            Requestor r        = new Requestor(identity);

            using (PsiogEntities PE = new PsiogEntities())
            {
                var approval = (from la in PE.LeaveApplications
                                join emp in PE.Employees
                                on la.EmployeeId equals emp.EmployeeId
                                join type in PE.LeaveTypes
                                on la.LeaveId equals type.LeaveTypeId
                                where la.SendTo == r.name && la.Status == "Applied"
                                select new
                {
                    emp.Name,
                    type.Type,
                    la.FromDate,
                    la.ToDate,
                    la.FromSession,
                    la.ToSession,
                    la.Reason,
                    la.LeaveApplicationId
                }
                                ).ToList();
                HttpResponseMessage response;
                response = Request.CreateResponse(HttpStatusCode.OK, approval);
                return(response);
            }
        }
Exemplo n.º 4
0
 public static string ValidateLogin(string username, string password, out User user)
 {
     try
     {
         using (PsiogEntities PE = new PsiogEntities())
         {
             user = PE.Users.Where(u => u.EmployeeId == username).FirstOrDefault();
             if (user != null)
             {
                 if (string.Compare(Hasher.HashString(password), user.Password) == 0)
                 {
                     return("Login Successful!");
                 }
                 else
                 {
                     user = null;
                     return("Incorrect Password");
                 }
             }
             else
             {
                 user = null;
                 return("Invalid Credentials");
             }
         }
     }
     catch (Exception E)
     {
         ExceptionLog.Logger(E);
         user = null;
         return("Unable to connect to server!");
     }
 }
Exemplo n.º 5
0
        public HttpResponseMessage TrackLeave()
        {
            var       identity = (ClaimsIdentity)User.Identity;
            Requestor r        = new Requestor(identity);

            using (PsiogEntities PE = new PsiogEntities())
            {
                var myLeaves = (from la in PE.LeaveApplications
                                join l in PE.LeaveTypes
                                on la.LeaveId equals l.LeaveTypeId
                                where la.EmployeeId == r.employeeId
                                select new
                {
                    l.Type,
                    la.FromDate,
                    la.ToDate,
                    la.FromSession,
                    la.ToSession,
                    la.Reason,
                    la.Status
                }
                                ).ToList();
                HttpResponseMessage response;
                response = Request.CreateResponse(HttpStatusCode.OK, myLeaves);
                return(response);
            }
        }
Exemplo n.º 6
0
        public static bool AddManagers(string employeeid)
        {
            PsiogEntities PE = new PsiogEntities();

            var result = PE.ManagersSetUpProcess(employeeid);

            return(Convert.ToBoolean(result));
        }
Exemplo n.º 7
0
        public static bool AllocateLeave(string employeeid, int month)
        {
            PsiogEntities PE = new PsiogEntities();

            var result = PE.SetUpEmployeeLeaveAvailability(month, employeeid);

            return(Convert.ToBoolean(result));
        }
Exemplo n.º 8
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.º 9
0
        public HttpResponseMessage SecurityQuestion()
        {
            using (PsiogEntities PE = new PsiogEntities())
            {
                var questions = (from q in PE.SecurityQuestions select q.Question).ToList();

                HttpResponseMessage response;
                response = Request.CreateResponse(HttpStatusCode.OK, questions);
                return(response);
            }
        }
Exemplo n.º 10
0
        public HttpResponseMessage getMySecurityQuestion(string id)
        {
            string question;

            using (PsiogEntities PE = new PsiogEntities())
            {
                question = (from q in PE.Users where q.EmployeeId == id select q.SecurityQuestion).FirstOrDefault();
                HttpResponseMessage response;
                response = Request.CreateResponse(HttpStatusCode.OK, question);
                return(response);
            }
        }
Exemplo n.º 11
0
 public HttpResponseMessage GetCCToList()
 {
     using (PsiogEntities PE = new PsiogEntities())
     {
         var employeesList = (from emp in PE.Employees
                              select new
         {
             emp.Name,
         }).ToList();
         HttpResponseMessage response;
         response = Request.CreateResponse(HttpStatusCode.OK, employeesList);
         return(response);
     }
 }
Exemplo n.º 12
0
        public HttpResponseMessage GetHolidaysList()
        {
            using (PsiogEntities PE = new PsiogEntities())
            {
                var holidaysList = (from hols in PE.Holidays
                                    orderby hols.Date
                                    select hols).ToList();

                //var json = new JavaScriptSerializer().Serialize(holidaysList);
                HttpResponseMessage response;
                response = Request.CreateResponse(HttpStatusCode.OK, holidaysList);
                return(response);
            }
        }
Exemplo n.º 13
0
        public HttpResponseMessage GetSearchedEmployees(Searcher search)
        {
            List <string> employeesList;

            using (PsiogEntities PE = new PsiogEntities())
            {
                string name = search.employeeName;
                employeesList = (from emp in PE.Employees
                                 where emp.Name.Contains(search.employeeName)
                                 select emp.Name).ToList();
            }
            HttpResponseMessage response;

            response = Request.CreateResponse(HttpStatusCode.OK, employeesList);
            return(response);
        }
Exemplo n.º 14
0
        public HttpResponseMessage GetReportingAuthorities()
        {
            List <string> authoritiesList;

            using (PsiogEntities PE = new PsiogEntities())
            {
                authoritiesList = (from emp in PE.Employees
                                   join rep in PE.ReportingAuthorities
                                   on emp.EmployeeId equals rep.ManagerId
                                   select emp.Name).ToList();
            }

            HttpResponseMessage response;

            response = Request.CreateResponse(HttpStatusCode.OK, authoritiesList);
            return(response);
        }
Exemplo n.º 15
0
 public HttpResponseMessage GetManagersList()
 {
     using (PsiogEntities PE = new PsiogEntities())
     {
         var managersList = (from emp in PE.Employees
                             join managers in PE.Managers
                             on emp.EmployeeId equals managers.ManagerId
                             select emp.Name).ToList();
         if (managersList.Count == 0)
         {
             managersList = null;
         }
         HttpResponseMessage response;
         response = Request.CreateResponse(HttpStatusCode.OK, managersList);
         return(response);
     }
 }
Exemplo n.º 16
0
        public void  CompleteRegistration(Employee newEmp)
        {
            using (PsiogEntities PE = new PsiogEntities())
            {
                string VerificationCode = Guid.NewGuid().ToString();
                //var link = HttpContext.Current.Request.Url.AbsoluteUri + "/VerifyAccount?id=" + newEmp.EmployeeId;
                string encodedId = Hasher.EncodeId(newEmp.EmployeeId);
                var    link      = "http://*****:*****@gmail.com", VerificationCode, out SmtpClient messenger);
                var    account   = PE.Users.Where(a => a.EmployeeId == newEmp.EmployeeId).FirstOrDefault();


                mail.Body += link + ">Click here to complete registration</a>";
                messenger.Send(mail);
                messenger.Dispose();
            }
        }
Exemplo n.º 17
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.º 18
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.º 19
0
        public HttpResponseMessage GetAttendance()
        {
            var       identity = (ClaimsIdentity)User.Identity;
            Requestor r        = new Requestor(identity);

            using (PsiogEntities PE = new PsiogEntities())
            {
                var attendance = (from emp in PE.AttendanceTransactions
                                  where emp.EmployeeId == r.employeeId
                                  select emp).ToList();
                if (attendance.Count == 0)
                {
                    attendance = null;
                }
                HttpResponseMessage response;
                response = Request.CreateResponse(HttpStatusCode.OK, attendance);
                return(response);
            }
        }
Exemplo n.º 20
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var    identity = new ClaimsIdentity(context.Options.AuthenticationType);
            string message  = DBOperations.ValidateLogin(context.UserName, context.Password, out User user);


            using (PsiogEntities PE = new PsiogEntities())
            {
                if (user != null)
                {
                    identity.AddClaim(new Claim(ClaimTypes.Role, user.Role));

                    var result = from logger in PE.Users
                                 join employee in PE.Employees on logger.EmployeeId equals employee.EmployeeId
                                 select new
                    {
                        username   = employee.Name,
                        employeeid = employee.EmployeeId
                    };

                    foreach (var l in result)
                    {
                        if (l.employeeid == user.EmployeeId)
                        {
                            identity.AddClaim(new Claim("username", l.username));
                            identity.AddClaim(new Claim(ClaimTypes.Name, l.username));
                            identity.AddClaim(new Claim(ClaimTypes.Sid, l.employeeid));
                            context.Validated(identity);
                            break;
                        }
                        else
                        {
                            context.SetError(message);
                        }
                    }
                }
                else
                {
                    context.SetError(message);
                }
            }
        }
Exemplo n.º 21
0
        public HttpResponseMessage Leavebalance()
        {
            var       identity = (ClaimsIdentity)User.Identity;
            Requestor r        = new Requestor(identity);

            using (PsiogEntities PE = new PsiogEntities())
            {
                var balance = (from l in PE.LeaveTypes
                               join bal in PE.EmployeeLeaveAvaliabilities on
                               l.LeaveTypeId equals bal.LeaveTypeId
                               where bal.EmployeeId == r.employeeId
                               select new { l.Type, bal.AllocatedDays, bal.AvailedDays }).ToList();



                //var json = new JavaScriptSerializer().Serialize(holidaysList);
                HttpResponseMessage response;
                response = Request.CreateResponse(HttpStatusCode.OK, balance);
                return(response);
            }
        }
Exemplo n.º 22
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.º 23
0
 public HttpResponseMessage GetEmployees()
 {
     using (PsiogEntities PE = new PsiogEntities())
     {
         var employeesList = (from emp in PE.Employees
                              select new
         {
             emp.Name,
             emp.Mobile,
             emp.Email,
             emp.DOB,
             emp.DOJ,
             emp.Address,
             emp.managerName,
             emp.Department,
             emp.Designation,
             emp.Image
         }).ToList();
         HttpResponseMessage response;
         response = Request.CreateResponse(HttpStatusCode.OK, employeesList);
         return(response);
     }
 }
Exemplo n.º 24
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.º 25
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);
            }
        }