コード例 #1
0
        public ActionResult Create([FromBody] PayrollPeriodBasic request)
        {
            try
            {
                #region check model
                if (!ModelState.IsValid)
                {
                    var modelState = ModelState.FirstOrDefault();
                    var error      = modelState.Value.Errors.FirstOrDefault().ErrorMessage;
                    throw ApiException.Get(false, error, ResultEnum.ModelError, HttpStatusCode.BadRequest);
                }
                #endregion

                payrollperiodService.CreatePeriod(request);
                response = BaseResponse <dynamic> .Get(true, ConstantManager.SUCCESS, null, ResultEnum.Success);
            }
            catch (ApiException e)
            {
                result.StatusCode = e.StatusCode;
                response          = BaseResponse <dynamic> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus);

                result = new JsonResult(response);
            }
            catch (Exception e)
            {
                result.StatusCode = (int)HttpStatusCode.InternalServerError;
                response          = BaseResponse <dynamic> .Get(false, ConstantManager.Fail(e.ToString()), null, ResultEnum.InternalError);
            }
            result = new JsonResult(response);
            return(result);

            //var a = ResponseMessage(httpResponseMessage);
            //return result;
        }
コード例 #2
0
        public ActionResult <List <DayModeBasic> > Get()
        {
            try
            {
                #region check model
                //if (!ModelState.IsValid)
                //{
                //    var modelState = ModelState.FirstOrDefault();
                //    var error = modelState.Value.Errors.FirstOrDefault().ErrorMessage;
                //    throw ApiException.Get(false, error, ResultEnum.ModelError, HttpStatusCode.BadRequest);
                //}
                #endregion

                var data = dayModeService.Get();
                response = BaseResponse <dynamic> .Get(true, ConstantManager.SUCCESS, data, ResultEnum.Success);
            }
            catch (ApiException e)
            {
                result.StatusCode = e.StatusCode;
                response          = BaseResponse <dynamic> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus);

                result = new JsonResult(response);
            }
            catch (Exception e)
            {
                result.StatusCode = (int)HttpStatusCode.InternalServerError;
                response          = BaseResponse <dynamic> .Get(false, ConstantManager.Fail("Day Mode : ") + e.ToString(), null, ResultEnum.InternalError);
            }
            result = new JsonResult(response);
            return(result);
        }
コード例 #3
0
        public ActionResult Accept(AttentdenceAcceptRequest request)
        {
            try
            {
                #region check model
                //if (!ModelState.IsValid)
                //{
                //    var modelState = ModelState.FirstOrDefault();
                //    var error = modelState.Value.Errors.FirstOrDefault().ErrorMessage;
                //    throw ApiException.Get(false, error, ResultEnum.ModelError, HttpStatusCode.BadRequest);
                //}
                #endregion

                attendanceService.Accept(request);
                response = BaseResponse <dynamic> .Get(true, ConstantManager.CreateSuccess("Attendance :"), null, ResultEnum.Success);
            }
            catch (ApiException e)
            {
                result.StatusCode = e.StatusCode;
                response          = BaseResponse <dynamic> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus);

                result = new JsonResult(response);
            }
            catch (Exception e)
            {
                result.StatusCode = (int)HttpStatusCode.InternalServerError;
                response          = BaseResponse <dynamic> .Get(false, ConstantManager.Fail("Attendance : ") + e.ToString(), null, ResultEnum.InternalError);
            }
            result = new JsonResult(response);
            return(result);
        }
コード例 #4
0
        public ActionResult Register(UserBasic request)
        {
            try
            {
                #region check model
                if (!ModelState.IsValid)
                {
                    var modelState = ModelState.FirstOrDefault();
                    var error      = modelState.Value.Errors.FirstOrDefault().ErrorMessage;
                    throw ApiException.Get(false, error, ResultEnum.ModelError, HttpStatusCode.BadRequest);
                }
                #endregion
                var task = userService.Register(brandToken, request);
                task.Wait();

                response = BaseResponse <dynamic> .Get(true, ConstantManager.Success("Register"), null, ResultEnum.Success);
            }
            catch (ApiException e)
            {
                result.StatusCode = e.StatusCode;
                response          = BaseResponse <dynamic> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus);

                result = new JsonResult(response);
            }
            catch (Exception e)
            {
                result.StatusCode = (int)HttpStatusCode.InternalServerError;
                response          = BaseResponse <dynamic> .Get(false, ConstantManager.Fail("Register : ") + e.ToString(), null, ResultEnum.InternalError);
            }
            result = new JsonResult(response);
            return(result);

            // create asp user , employee , membership , account
        }
コード例 #5
0
        public ActionResult <List <PayrollPeriodResponse> > Get([FromQuery] int?empId)
        {
            try
            {
                #region check model
                if (!ModelState.IsValid)
                {
                    var modelState = ModelState.FirstOrDefault();
                    var error      = modelState.Value.Errors.FirstOrDefault().ErrorMessage;
                    throw ApiException.Get(false, error, ResultEnum.ModelError, HttpStatusCode.BadRequest);
                }
                #endregion

                var data = payrollperiodService.Get(empId);
                if (data.Count <= 0)
                {
                    throw ApiException.Get(true, ConstantManager.NotFound(" Payroll Period "), ResultEnum.PeriodNotFound, HttpStatusCode.NotFound);
                }
                response = BaseResponse <dynamic> .Get(true, ConstantManager.SUCCESS, data, ResultEnum.Success);
            }
            catch (ApiException e)
            {
                result.StatusCode = e.StatusCode;
                response          = BaseResponse <dynamic> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus);

                result = new JsonResult(response);
            }
            catch (Exception e)
            {
                result.StatusCode = (int)HttpStatusCode.InternalServerError;
                response          = BaseResponse <dynamic> .Get(false, ConstantManager.Fail(e.ToString()), null, ResultEnum.InternalError);
            }
            result = new JsonResult(response);
            return(result);
        }
コード例 #6
0
        public async Task <ActionResult> Login(UserLoginRequest request)
        {
            try
            {
                #region check model
                //if (!ModelState.IsValid)
                //{
                //    var modelState = ModelState.FirstOrDefault();
                //    var error = modelState.Value.Errors.FirstOrDefault().ErrorMessage;
                //    throw ApiException.Get(false, error, ResultEnum.ModelError, HttpStatusCode.BadRequest);
                //}
                #endregion
                var data = await userService.Login(brandToken, request);

                response = BaseResponse <dynamic> .Get(true, ConstantManager.Success("Login"), data, ResultEnum.Success);
            }
            catch (ApiException e)
            {
                result.StatusCode = e.StatusCode;
                response          = BaseResponse <dynamic> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus);

                result = new JsonResult(response);
            }
            catch (Exception e)
            {
                result.StatusCode = (int)HttpStatusCode.InternalServerError;
                response          = BaseResponse <dynamic> .Get(false, ConstantManager.Fail("Login : ") + e.ToString(), null, ResultEnum.InternalError);
            }
            result = new JsonResult(response);
            return(result);
        }
コード例 #7
0
        public ActionResult Get()
        {
            try
            {
                #region check model
                //if (!ModelState.IsValid)
                //{
                //    var modelState = ModelState.FirstOrDefault();
                //    var error = modelState.Value.Errors.FirstOrDefault().ErrorMessage;
                //    throw ApiException.Get(false, error, ResultEnum.ModelError, HttpStatusCode.BadRequest);
                //}
                #endregion

                var data    = shiftRegisterService.Get();
                var groupby = data.GroupBy(p => p.EmpName, p => p, (key, shift) => new { Name = key, Shift = shift.ToList() });
                response = BaseResponse <dynamic> .Get(false, ConstantManager.SUCCESS, groupby, ResultEnum.Success);
            }
            catch (ApiException e)
            {
                result.StatusCode = e.StatusCode;
                response          = BaseResponse <dynamic> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus);

                result = new JsonResult(response);
            }
            catch (Exception e)
            {
                result.StatusCode = (int)HttpStatusCode.InternalServerError;
                response          = BaseResponse <dynamic> .Get(false, ConstantManager.Fail("Shift Register : ") + e.ToString(), null, ResultEnum.InternalError);
            }
            result = new JsonResult(response);
            return(result);
        }
コード例 #8
0
        public ActionResult Add(List <ShiftRegisterBasic> request)
        {
            try
            {
                #region check model
                if (!ModelState.IsValid)
                {
                    var modelState = ModelState.FirstOrDefault();
                    var error      = modelState.Value.Errors.FirstOrDefault().ErrorMessage;
                    throw ApiException.Get(false, error, ResultEnum.ModelError, HttpStatusCode.BadRequest);
                }
                #endregion

                shiftRegisterService.RegistShift(request);
                response = BaseResponse <dynamic> .Get(false, ConstantManager.CreateSuccess("Shift Register :"), null, ResultEnum.Success);
            }
            catch (ApiException e)
            {
                result.StatusCode = e.StatusCode;
                response          = BaseResponse <dynamic> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus);

                result = new JsonResult(response);
            }
            catch (Exception e)
            {
                result.StatusCode = (int)HttpStatusCode.InternalServerError;
                response          = BaseResponse <dynamic> .Get(false, ConstantManager.Fail("Shift Register : ") + e.ToString(), null, ResultEnum.InternalError);
            }
            result = new JsonResult(response);
            return(result);
        }
コード例 #9
0
        public ActionResult Get()
        {
            HttpResponseMessage httpResponseMessage = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK
            };
            BaseResponse <dynamic> response = new BaseResponse <dynamic>();
            JsonResult             result   = new JsonResult(response)
            {
                StatusCode = (int)HttpStatusCode.OK
            };

            try
            {
                #region check model
                //if (!ModelState.IsValid)
                //{
                //    var modelState = ModelState.FirstOrDefault();
                //    var error = modelState.Value.Errors.FirstOrDefault().ErrorMessage;
                //    throw ApiException.Get(false, error, ResultEnum.ModelError, HttpStatusCode.BadRequest);
                //}
                #endregion

                var data = timeFrameService.Get();
                response = BaseResponse <dynamic> .Get(true, ConstantManager.Success("Time frame :"), data, ResultEnum.Success);
            }
            catch (ApiException e)
            {
                result.StatusCode = e.StatusCode;
                response          = BaseResponse <dynamic> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus);

                result = new JsonResult(response);
            }
            catch (Exception e)
            {
                result.StatusCode = (int)HttpStatusCode.InternalServerError;
                response          = BaseResponse <dynamic> .Get(false, ConstantManager.Fail("Time frame : ") + e.ToString(), null, ResultEnum.InternalError);
            }
            result = new JsonResult(response);
            return(result);
        }
コード例 #10
0
        //[BlockEmployee(Block = "ActiveUser",Except = "Administrator")]
        public ActionResult Get([FromQuery(Name = "id")] int?EmployeeId)
        {
            try
            {
                #region check model
                //if (!ModelState.IsValid)
                //{
                //    var modelState = ModelState.FirstOrDefault();
                //    var error = modelState.Value.Errors.FirstOrDefault().ErrorMessage;
                //    throw ApiException.Get(false, error, ResultEnum.ModelError, HttpStatusCode.BadRequest);
                //}
                #endregion
                if (EmployeeId.HasValue)
                {
                    var data = employeeService.Get(EmployeeId.Value);
                    response = BaseResponse <dynamic> .Get(true, ConstantManager.SUCCESS, data, ResultEnum.Success);
                }
                else
                {
                    var data = employeeService.Get().ToList();

                    response = BaseResponse <dynamic> .Get(true, ConstantManager.SUCCESS, data, ResultEnum.Success);
                }
            }
            catch (ApiException e)
            {
                result.StatusCode = e.StatusCode;
                response          = BaseResponse <dynamic> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus);

                result = new JsonResult(response);
            }
            catch (Exception e)
            {
                result.StatusCode = (int)HttpStatusCode.InternalServerError;
                response          = BaseResponse <dynamic> .Get(false, ConstantManager.Fail("Employee  : ") + e.ToString(), null, ResultEnum.InternalError);
            }
            result = new JsonResult(response);
            return(result);
        }
コード例 #11
0
        public void OnActionExecuting(ActionExecutingContext context)
        {
            try
            {
                employeeService = context.HttpContext.RequestServices.GetService <IEmployeeService>();
                var blockList  = new List <string>();
                var exceptList = new List <string>();
                if (!string.IsNullOrEmpty(Block))
                {
                    blockList = Block.Trim().Split(',').ToList();
                }
                if (!string.IsNullOrEmpty(Except))
                {
                    exceptList = Except.Trim().Split(',').ToList();
                }
                _request = context.HttpContext.Request;
                var query = _request.Query;

                _authorization = _request.Headers.FirstOrDefault(p => p.Key.Equals("Authorization")).Value.ToString();
                if (_authorization == null || string.IsNullOrEmpty(_authorization))
                {
                    throw ApiException.Get(false, ConstantManager.MES_AUTHORIZATION_NOT_FOUND, ResultEnum.AuthorizationNotFound, HttpStatusCode.BadRequest);
                }
                else
                {
                    var tokenJWT = Utils.DecodeJwtToken(_authorization);
                    // get List role
                    var role   = tokenJWT.Claims.Where(c => c.Type == "role").Select(c => c.Value).ToList();
                    var unique = tokenJWT.Claims.Where(c => c.Type == "unique_name").FirstOrDefault().Value.ToString();
                    var email  = unique.Split('-')[0];
                    var emp    = employeeService.Get(email).FirstOrDefault();
                    if (!role.Contains(RoleTypeEnum.ActiveUser.ToString()))
                    {
                        throw ApiException.Get(false, ConstantManager.MES_NOT_ACTIVE, ResultEnum.NotActive, HttpStatusCode.NotAcceptable);
                    }
                    if (!role.Contains(RoleTypeEnum.Administrator.ToString()))
                    {
                        if (query.Count() == 0)
                        {
                            throw ApiException.Get(false, ConstantManager.MES_REQUEST_DENY, ResultEnum.NotAcceptable, HttpStatusCode.NotAcceptable);
                        }
                        else
                        {
                            var id = query.FirstOrDefault(p => p.Key.Equals("id")).Value;
                            if (id != emp.Id)
                            {
                                throw ApiException.Get(false, ConstantManager.MES_REQUEST_DENY, ResultEnum.NotAcceptable, HttpStatusCode.NotAcceptable);
                            }
                        }
                    }
                    //foreach (var e in exceptList)
                    //{
                    //    if (role.Contains(e.ToString()))
                    //    {
                    //        return;
                    //    }
                    //}

                    //foreach (var item in blockList)
                    //{
                    //    var a = (RoleTypeEnum[])Enum.GetValues(typeof(RoleTypeEnum));
                    //    var check = a.FirstOrDefault(e => e.ToString().Contains(item)).ToString();
                    //    if (check == null)
                    //    {
                    //        throw ApiException.Get(false, ConstantManager.MES_ROLE_WRONG, ResultEnum.AttributeWrong, HttpStatusCode.BadRequest);

                    //    }
                    //    if (role.Contains(item))
                    //    {
                    //        throw ApiException.Get(false, ConstantManager.MES_REQUEST_DENY, ResultEnum.RoleNotSupport, HttpStatusCode.NotAcceptable);
                    //    }
                    //}
                    return;
                }
            }
            catch (ApiException e)
            {
                result.StatusCode = e.StatusCode;
                result.Value      = BaseResponse <dynamic> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus);
            }
            catch (Exception e)
            {
                result.StatusCode = (int)HttpStatusCode.InternalServerError;
                result.Value      = BaseResponse <dynamic> .Get(false, ConstantManager.Fail(" Authentication   : ") + e.ToString(), null, ResultEnum.InternalError);
            }
            context.Result = result;
        }