Ejemplo n.º 1
0
        internal static LeaveTypesResponse getLeaveTypes(string fb_id, HttpRequestMessage request)
        {
            LeaveTypesResponse response = new LeaveTypesResponse();

            try
            {
                var sessionDetails = AuthDAL.getSession(fb_id);
                var leaveDataTable = new UserDAL().GenerateLeaveTypes_ByUserGUID(sessionDetails["CompanyGUID"] as string, sessionDetails["UserGUID"] as string, new DateTime().Year);
                var leaveTypes     = new List <LeaveTypeModel>();
                foreach (DataRow row in leaveDataTable.Rows)
                {
                    leaveTypes.Add(new LeaveTypeModel
                    {
                        LeaveType     = (row["LeaveType"] ?? row[0]) as string,
                        LeaveName     = (row["LeaveName"] ?? row[1]) as string,
                        IfPerIncident = row[2] as string,
                    });
                }
                response.Success     = true;
                response.Leave_Types = leaveTypes.ToArray();
                return(response);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error   = new Error
                {
                    Id      = ErrorCode.INTERNAL_ERROR,
                    Message = ex.Message
                };
                throw new HttpResponseException(request.CreateResponse(HttpStatusCode.InternalServerError, response));
            }
        }
Ejemplo n.º 2
0
        internal static bool checkAutherization(HttpRequestMessage request)
        {
            var Fb_Id = request.GetQueryNameValuePairs().First((param) => param.Key == "Fb_Id").Value;

            if (AuthDAL.checkIfSessionExists(Fb_Id))
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        internal static GetWorkingDaysResponse getWorkingDays(GetWorkingDaysRequest getLeaveDaysRequest, HttpRequestMessage request)
        {
            GetWorkingDaysResponse response = new GetWorkingDaysResponse();

            try
            {
                LeaveDAL leaveDAL         = new LeaveDAL();
                var      sessionDetails   = AuthDAL.getSession(getLeaveDaysRequest.Fb_id);
                var      leaveDaysDataSet = leaveDAL.Employee_GetLeaveDay(
                    getLeaveDaysRequest.From_Date,
                    getLeaveDaysRequest.To_Date,
                    getLeaveDaysRequest.From_Time,
                    getLeaveDaysRequest.To_Time,
                    sessionDetails["UserGUID"] as string,
                    sessionDetails["CompanyGUID"] as string
                    );
                // ToDo: Calculate the current balance and check if the required leaves is within the range
                //leaveDAL.Get_CurrentBalance(
                //    sessionDetails["UserGUID"] as string,
                //    getLeaveDaysRequest.LeaveTypeId,
                //    new DateTime().Year,
                //    );
                response.Success = true;
                response.Days    = leaveDaysDataSet.Tables[0].Rows[0]["LeaveDays"] as int?;
                return(response);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error   = new Error
                {
                    Id      = ErrorCode.INTERNAL_ERROR,
                    Message = ex.Message
                };
                throw new HttpResponseException(request.CreateResponse(HttpStatusCode.InternalServerError, response));
            }
        }
Ejemplo n.º 4
0
        internal static AuthenticationResponse checkAuthentication(AuthenticationRequest authenticationRequest, HttpRequestMessage request)
        {
            AuthenticationResponse authenticationResponse = new AuthenticationResponse();

            try
            {
                string CompanyGuid = leaveDaoHelper.GetCompanyGUIDByUserID(authenticationRequest.Username);
                if (CompanyGuid != null &&
                    CompanyGuid != String.Empty &&
                    Apiv2.ELeave.Util.Common.getInstance().EscapeSql(CompanyGuid) == authenticationRequest.Company_Id)
                {
                    AuthDAL.createAuthCode(authenticationRequest.Username, authenticationRequest.Company_Id, CompanyGuid);
                    authenticationResponse.Success = true;
                }
                else
                {
                    authenticationResponse.Success = false;
                    authenticationResponse.Error   = new Error
                    {
                        Id      = ErrorCode.COMPANY_NOT_MATCHED,
                        Message = ErrorMessage.COMPANY_NOT_MATCHED
                    };
                    throw new HttpResponseException(request.CreateResponse(HttpStatusCode.Unauthorized, authenticationResponse));
                }
            }
            catch (Exception ex)
            {
                authenticationResponse.Success = false;
                authenticationResponse.Error   = new Error
                {
                    Id      = ErrorCode.INTERNAL_ERROR,
                    Message = ex.Message
                };
                throw new HttpResponseException(request.CreateResponse(HttpStatusCode.InternalServerError, authenticationResponse));
            }
            return(authenticationResponse);
        }
Ejemplo n.º 5
0
        internal static AuthorizationResponse authorize(AuthorizationRequest authorizationRequest, HttpRequestMessage request)
        {
            AuthorizationResponse authorizationResponse = new AuthorizationResponse();

            try
            {
                if (AuthDAL.checkIfAuthCodeIsValid(authorizationRequest.Company_Id, authorizationRequest.Username, authorizationRequest.Auth_Code))
                {
                    string CompanyGuid = leaveDaoHelper.GetCompanyGUIDByUserID(authorizationRequest.Username);
                    AuthDAL.createSession(CompanyGuid, authorizationRequest.Username, authorizationRequest.Fb_Id);
                    authorizationResponse.Success     = true;
                    authorizationResponse.Leave_Types = LeaveHelper.getLeaveTypes(authorizationRequest.Fb_Id, request).Leave_Types;
                    return(authorizationResponse);
                }
                else
                {
                    authorizationResponse.Success = false;
                    authorizationResponse.Error   = new Error
                    {
                        Id      = ErrorCode.INVALID_AUTH_CODE,
                        Message = ErrorMessage.INVALID_AUTH_CODE
                    };
                    throw new HttpResponseException(request.CreateResponse(HttpStatusCode.Unauthorized, authorizationResponse));
                }
            }
            catch (Exception ex)
            {
                authorizationResponse.Success = false;
                authorizationResponse.Error   = new Error
                {
                    Id      = ErrorCode.INTERNAL_ERROR,
                    Message = ex.Message
                };
                throw new HttpResponseException(request.CreateResponse(HttpStatusCode.InternalServerError, authorizationResponse));
            }
        }