Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void Add(List<AttentdenceRequest> requests)
        {
            var trans = UnitOfWork.CreateTransac();
            try
            {

                foreach (var item in requests)
                {
                    var emp = employeeService.FindById(item.EmployeeId);
                    if (emp == null)
                    {
                        throw ApiException.Get(false, ConstantManager.NotFound("Employee "), ResultEnum.EmpNotFound, HttpStatusCode.NotFound);
                    }
                    var entity = Mapper.Map<AttentdenceRequest, Attendance>(item);
                    //item.ToEntity();
                    for (int i = 0; i < item.Dates.Count; i++)
                    {
                        entity.ShiftMax = item.Dates[i].GetStartOfDate().Add(item.ShiftMaxTime[i]);
                        entity.ShiftMin = item.Dates[i].GetStartOfDate().Add(item.ShiftMaxTime[i]);
                        entity.ExpandTime = new TimeSpan();
                        entity.CheckInExpandTime = new TimeSpan(1, 0, 0);
                        entity.CheckOutExpandTime = new TimeSpan(1, 0, 0);
                        entity.ComeLateExpandTime = new TimeSpan(1, 0, 0);
                        entity.LeaveEarlyExpandTime = new TimeSpan(1, 0, 0);
                        entity.ProcessingStatus = (int)ProcessingStatusAttendenceEnum.Assign;
                        var timeFrameId = item.TimeFramId[i];
                        var tf = timeFrameService.FindById(timeFrameId);
                        if (tf == null)
                        {
                            throw ApiException.Get(false, ConstantManager.NotFound("Time Frame "), ResultEnum.TimeFrameNotFound, HttpStatusCode.NotFound);
                        }
                        entity.TimeFramId = tf.Id;
                        entity.Active = true;
                        entity.Status = (int)StatusAttendanceEnum.Processing;
                        Create(entity);
                    }
                }
                trans.Commit();
            }
            catch (Exception e)
            {
                trans.Dispose();

                if (e is ApiException)
                {
                    throw e;
                }
                else
                {
                    ApiException.Get(false, ConstantManager.FAIL, ResultEnum.InternalError, HttpStatusCode.InternalServerError);
                }
            }

        }