Example #1
0
        //public IEnumerable<EntitledayModel> GetById(int id)
        //{
        //    var model = _entitleDayRepositoty.GetById(id);
        //    return model;
        //}
        //public IEnumerable<Entitleday_AppUser> GetAll()
        //{
        //    return _entitleDayAppUserRepository.GetAll();
        //}

        public List <EntitledayModel> GetAllOTFilter(string userID, string groupID, string column, bool isDesc, FilterEntitleDay filter)
        {
            var model = GetAllWithUser(userID, groupID, filter);

            if (filter != null)
            {
                if (filter.FullName.Count() != 0)
                {
                    model = model.Where(x => filter.FullName.Contains(x.IDUser));
                }
                if (filter.HolidayType.Count() != 0)
                {
                    model = model.Where(x => filter.HolidayType.Contains(x.IDEntitleday.ToString()));
                }
            }
            return(model.OrderByField(column, isDesc).ToList());
        }
Example #2
0
        public async Task <HttpResponseMessage> GetAllEntitle(HttpRequestMessage request, string userID, string groupID, string column, bool isDesc, int page, int pageSize, [FromBody] FilterEntitleDay filter)
        {
            Func <HttpResponseMessage> func = () =>
            {
                if (string.IsNullOrEmpty(userID) || string.IsNullOrEmpty(groupID))
                {
                    return(request.CreateErrorResponse(HttpStatusCode.BadRequest, nameof(userID) + MessageSystem.NoValues + nameof(groupID) + MessageSystem.NoValues));
                }
                var model         = _entitleDayService.GetAllOTFilter(userID, groupID, column, isDesc, filter);
                var data          = model.Skip((page - 1) * pageSize).Take(pageSize);
                var paginationSet = new PaginationSet <EntitledayModel>()
                {
                    Items     = data,
                    PageIndex = page,
                    TotalRows = model.Count(),
                    PageSize  = pageSize
                };
                return(request.CreateResponse(HttpStatusCode.OK, paginationSet));
            };

            return(await CreateHttpResponse(request, func));
        }
Example #3
0
        /// <summary>
        /// Function Get All List Entitle Day
        /// Paging & Sort
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="groupId"></param>
        /// <returns></returns>
        ///

        public IEnumerable <EntitledayModel> GetAllWithUser(string userID, string groupID, FilterEntitleDay filter)
        {
            if (_entitleDayRepositoty.IsReadAll(userID, CommonConstants.FunctionEntitleDay))
            {
                return(_entitleDayRepositoty.GetAllEntitleDay(userID, groupID, true).ToList());
            }
            return(_entitleDayRepositoty.GetAllEntitleDay(userID, groupID, false));
        }
Example #4
0
        public async Task <HttpResponseMessage> ExportToExcel(HttpRequestMessage request, string userID, string groupID, string column, bool isDesc, int page, int pageSize, [FromBody] FilterEntitleDay filter)
        {
            string fileName     = string.Concat(CommonConstants.EntitleDay + DateTime.Now.ToString(CommonConstants.dateExport) + CommonConstants.fileExport);
            var    folderReport = ConfigHelper.GetByKey(CommonConstants.reportFolder);
            string fileTemplate = folderReport + CommonConstants.Link + fileName;
            string filePath     = HttpContext.Current.Server.MapPath(folderReport);

            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }
            string fullPath = Path.Combine(filePath, fileName);

            try
            {
                var model        = _entitleDayService.GetAllOTFilter(userID, groupID, column, isDesc, filter);
                var responseData = Mapper.Map <List <EntitledayModel>, List <EntitleDayViewModel> >(model);
                for (int i = 0; i < model.Count; i++)
                {
                    responseData[i].FullName       = model[i].FullName;
                    responseData[i].Account        = model[i].UserName;
                    responseData[i].DayOffType     = model[i].HolidayType;
                    responseData[i].Unit           = model[i].UnitType;
                    responseData[i].MaximumAllowed = model[i].MaxEntitleDay;
                    responseData[i].Approved       = model[i].NumberDayOff;
                    responseData[i].Remain         = model[i].RemainDayOff;
                }
                await ReportHelper.GenerateXls(responseData, fullPath);

                return(request.CreateResponse(HttpStatusCode.OK, fileTemplate));
            }
            catch (Exception ex)
            {
                return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
            }
        }