Пример #1
0
        public async Task <IActionResult> Index()
        {
            var user  = _userManager.GetUserAsync(HttpContext.User).Result;
            var roles = _userManager.GetRolesAsync(user).Result;

            List <UserLeaveRequest> entities = new List <UserLeaveRequest>();

            if (roles.Any(x => x.Equals("Admin")))
            {
                entities = await _myService.GetAllAsync(null, x => x.RequestUser,
                                                        x => x.UserLeaveType, x => x.ApprovedUser);
            }
            else
            {
                entities = await _myService.GetAllAsync(x => x.RequestUserId == user.Id, x => x.RequestUser,
                                                        x => x.UserLeaveType, x => x.ApprovedUser);
            }


            entities = entities.OrderByDescending(x => x.RequestDate).ToList();

            var map = _mapper.Map <List <UserLeaveRequestDto> >(entities);

            map.ForEach(item =>
            {
                item.StatusText = EnumExtension <UserLeaveReqeustEnum> .GetDisplayValue(item.Status);
            });

            ViewBag.ShowEdit = roles.Any(x => x.Equals("Admin"));


            return(View(map));
        }
        public IActionResult Index()
        {
            var user  = _userManager.GetUserAsync(HttpContext.User).Result;
            var roles = _userManager.GetRolesAsync(user).Result;

            List <WorkOrder> entities = new List <WorkOrder>();

            if (roles.Any(x => x.Equals("Admin")))
            {
                entities =
                    _myService.GetAllAsync(null, x => x.AssignUser, x => x.CreatedUser, x => x.ComplatedUser).Result;
            }
            else
            {
                entities =
                    _myService.GetAllAsync(x => x.AssignUserId == user.Id, x => x.AssignUser, x => x.CreatedUser, x => x.ComplatedUser).Result;
            }

            var map = _mapper.Map <List <WorkOrderDto> >(entities);

            map.ForEach(item =>
            {
                item.StatusText = EnumExtension <WorkOrderStatusEnum> .GetDisplayValue(item.WorkOrderStatus);
            });

            ViewBag.AllowCreate = roles.Any(x => x.Equals("Admin"));
            return(View(map));
        }
        public Result <WorkOrderVM> GetWorkOrder(int id)
        {
            if (id > 0)
            {
                var workOrder = _unitOfWork.workOrderRepository.GetFirstOrDefault(u => u.Id == id, includeProperties: "AssignEmployee");
                if (workOrder != null)
                {
                    WorkOrderVM wOrder = new WorkOrderVM();
                    wOrder.AssignEmployeeId   = workOrder.AssignEmployeeId;
                    wOrder.AssignEmployeeName = workOrder.AssignEmployee != null ? workOrder.AssignEmployee.FirstName : string.Empty;
                    wOrder.CreateDate         = workOrder.CreateDate;
                    wOrder.Id                   = workOrder.Id;
                    wOrder.ModifiedDate         = workOrder.ModifiedDate;
                    wOrder.WorkOrderDescription = workOrder.WorkOrderDescription;
                    wOrder.WorkOrderNumber      = workOrder.WorkOrderNumber;
                    wOrder.WorkOrderPoint       = workOrder.WorkOrderPoint;
                    wOrder.WorkOrderStatus      = (EnumWorkOrderStatus)workOrder.WorkOrderStatus;
                    wOrder.WorkOrderStatusText  = EnumExtension <EnumWorkOrderStatus> .GetDisplayValue((EnumWorkOrderStatus)workOrder.WorkOrderStatus);

                    wOrder.PhotoPathText = workOrder.PhotoPath;
                    return(new Result <WorkOrderVM>(true, ResultConstant.RecordFound, wOrder));
                }
                else
                {
                    return(new Result <WorkOrderVM>(false, ResultConstant.RecordNotFound));
                }
            }
            else
            {
                return(new Result <WorkOrderVM>(false, ResultConstant.RecordNotFound));
            }
        }
        public Result <List <WorkOrderVM> > GetAllWorkOrders()
        {
            var data = _unitOfWork.workOrderRepository.GetAll(includeProperties: "AssignEmployee").ToList();

            #region 1.Yontem
            if (data != null)
            {
                List <WorkOrderVM> returnData = new List <WorkOrderVM>();
                foreach (var item in data)
                {
                    returnData.Add(new WorkOrderVM()
                    {
                        Id = item.Id,
                        AssignEmployeeId     = item.AssignEmployeeId,
                        AssignEmployeeName   = item.AssignEmployee != null ? item.AssignEmployee.Email : string.Empty,
                        CreateDate           = item.CreateDate,
                        ModifiedDate         = item.ModifiedDate,
                        WorkOrderDescription = item.WorkOrderDescription,
                        WorkOrderNumber      = item.WorkOrderNumber,
                        WorkOrderPoint       = item.WorkOrderPoint,
                        WorkOrderStatus      = (EnumWorkOrderStatus)item.WorkOrderStatus,
                        WorkOrderStatusText  = EnumExtension <EnumWorkOrderStatus> .GetDisplayValue((EnumWorkOrderStatus)item.WorkOrderStatus)
                    });
                }
                return(new Result <List <WorkOrderVM> >(true, ResultConstant.RecordFound, returnData.OrderByDescending(x => x.CreateDate).ToList()));
            }
            else
            {
                return(new Result <List <WorkOrderVM> >(false, ResultConstant.RecordNotFound));
            }
            #endregion
        }
        public Result <List <WorkOrderVM> > GetWorkOrderByEmployeeId(string employeeId)
        {
            var data = _unitOfWork.workOrderRepository.GetAll(w => w.AssignEmployeeId == employeeId).ToList();

            if (data != null)
            {
                List <WorkOrderVM> returnData = new List <WorkOrderVM>();
                //var mappingData = _mapper.Map<List<WorkOrder>, List<WorkOrderVM>>(data);
                foreach (var item in data)
                {
                    returnData.Add(new WorkOrderVM()
                    {
                        Id = item.Id,
                        AssignEmployeeId     = item.AssignEmployeeId,
                        AssignEmployeeName   = item.AssignEmployee != null ? item.AssignEmployee.Email : string.Empty,
                        CreateDate           = item.CreateDate,
                        ModifiedDate         = item.ModifiedDate,
                        WorkOrderDescription = item.WorkOrderDescription,
                        WorkOrderNumber      = item.WorkOrderNumber,
                        WorkOrderPoint       = item.WorkOrderPoint,
                        WorkOrderStatus      = (EnumWorkOrderStatus)item.WorkOrderStatus,
                        WorkOrderStatusText  = EnumExtension <EnumWorkOrderStatus> .GetDisplayValue((EnumWorkOrderStatus)item.WorkOrderStatus)
                    });
                }
                return(new Result <List <WorkOrderVM> >(true, ResultConstant.RecordFound, returnData));
            }
            else
            {
                return(new Result <List <WorkOrderVM> >(false, ResultConstant.RecordNotFound));
            }
        }
        public Result <List <EmployeeLeaveRequestVM> > GetAllLeaveRequestByUserId(string userId)
        {
            var data = _unitOfWork.employeeLeaveRequestRepository.GetAll(
                u => u.RequestingEmployeeId == userId &&
                u.Cancelled == false,
                includeProperties: "RequestingEmployee,EmployeeLeaveType").ToList();

            if (data != null)
            {
                List <EmployeeLeaveRequestVM> returnData = new List <EmployeeLeaveRequestVM>();
                foreach (var item in data)
                {
                    returnData.Add(new EmployeeLeaveRequestVM()
                    {
                        Id                   = item.Id,
                        ApprovedStatus       = (EnumEmployeeLeaveRequestStatus)item.Approved,
                        ApprovedText         = EnumExtension <EnumEmployeeLeaveRequestStatus> .GetDisplayValue((EnumEmployeeLeaveRequestStatus)item.Approved),
                        ApprovedEmployeeId   = item.ApprovedEmployeeId,
                        Cancelled            = item.Cancelled,
                        DateRequested        = item.DateRequested,
                        EmployeeLeaveTypeId  = item.EmployeeLeaveTypeId,
                        LeaveTypeText        = item.EmployeeLeaveType.Name,
                        EndDate              = item.EndDate,
                        StartDate            = item.StartDate,
                        RequestComments      = item.RequestComments,
                        RequestingEmployeeId = item.RequestingEmployeeId
                    });
                }
                return(new Result <List <EmployeeLeaveRequestVM> >(true, ResultConstant.RecordFound, returnData));
            }
            else
            {
                return(new Result <List <EmployeeLeaveRequestVM> >(false, ResultConstant.RecordNotFound));
            }
        }
        public Result <EmployeeLeaveRequestVM> GetAllLeaveRequestById(int id)
        {
            var data = _unitOfWork.employeeLeaveRequestRepository.Get(id);

            if (data != null)
            {
                var leaveRequest = _mapper.Map <EmployeeLeaveRequest, EmployeeLeaveRequestVM>(data);
                leaveRequest.ApprovedStatus = (EnumEmployeeLeaveRequestStatus)data.Approved;
                leaveRequest.ApprovedText   = EnumExtension <EnumEmployeeLeaveRequestStatus> .GetDisplayValue((EnumEmployeeLeaveRequestStatus)data.Approved);

                return(new Result <EmployeeLeaveRequestVM>(true, ResultConstant.RecordFound, leaveRequest));
            }
            else
            {
                return(new Result <EmployeeLeaveRequestVM>(false, ResultConstant.RecordNotFound));
            }
        }