Ejemplo n.º 1
0
        public async Task <IEnumerable <TrackModel> > AddCollectionAsync(IEnumerable <TrackModel> model)
        {
            if (model == null)
            {
                return(null);
            }

            var dataModelList = new List <Track>();

            foreach (TrackModel trackModel in model)
            {
                var dataModel = await _trackRepository.AddAsync(_trackMapper.ConvertToDataModel(trackModel));

                dataModelList.Add(dataModel);
            }

            var modelList = new List <TrackModel>();

            foreach (Track track in dataModelList)
            {
                var trackModel = _trackMapper.ConvertToModel(track);
                modelList.Add(trackModel);
            }
            return(modelList);
        }
Ejemplo n.º 2
0
        public async Task <AttendanceModel> CheckInAsync(int employeeId, string remarks = null)
        {
            if (employeeId == 0)
            {
                throw new ArgumentException();
            }
            var isExists = await _attendanceRepository.GetAttendanceForTodayAsync(employeeId, null);

            if (isExists != null)
            {
                throw new COHHttpException(System.Net.HttpStatusCode.Found, false, "Already exists.");
            }

            AttendanceModel model = new AttendanceModel();

            model.EmployeeId     = employeeId;
            model.Remarks        = remarks;
            model.CheckInTime    = DateTime.UtcNow;
            model.AttendanceDate = DateTime.UtcNow;
            model.IsPresent      = true;
            model.Remarks        = string.Format("IN: {0}", remarks);

            var dataModel = await _attendanceRepository.CheckInAsync(_attendanceMapper.ConvertToDataModel(model));

            return(_attendanceMapper.ConvertToModel(dataModel));
        }
Ejemplo n.º 3
0
        public async Task <IEnumerable <UserModel> > GetUsersAsync(int clientId, int userId)
        {
            if (!await _permissionManager.HasPermission(clientId, userId, Permission.CanViewUser))
            {
                throw new Exception("User has not permission to perform this operation");
            }

            var users = await _usersRepository.GetUsersAsync(clientId);

            return(users.ToList().Select(u => _usersMapper.ConvertToModel(u)));
        }
Ejemplo n.º 4
0
        public async Task <ClientModel> AddAsync(ClientModel model, int userId)
        {
            if (model == null)
            {
                throw new ArgumentNullException();
            }

            var client = _clientMapper.ConvertToDataModel(model);

            client.IsActive  = true;
            client.CreatedOn = DateTime.UtcNow;
            client.UpdatedOn = DateTime.UtcNow;

            client.Application = new Application()
            {
                Name         = client.OrganizationName + "Mobile App",
                ClientId     = Guid.NewGuid(),
                ClientSecret = Guid.NewGuid(),
                Scope        = "mobile",
                CreatedOn    = DateTime.UtcNow,
                UpdatedOn    = DateTime.UtcNow
            };

            var clientAdmin = new User()
            {
                FirstName = "Client",
                LastName  = "Admin",
                Email     = client.Email,
                Role      = (int)UserRoles.ClientAdmin,
                IsActive  = true,
                CreatedOn = DateTime.UtcNow,
                UpdatedOn = DateTime.UtcNow
            };

            var password = Guid.NewGuid().ToString().Substring(1, 6);

            string salt;
            string passwordHash;

            PasswordHelpers.GenerateSaltAndHash(password, out salt, out passwordHash);

            clientAdmin.Salt         = salt;
            clientAdmin.PasswordHash = passwordHash;

            client.Users.Add(clientAdmin);

            client = await _clientRepository.AddAsync(client);

            return(_clientMapper.ConvertToModel(client));
        }
Ejemplo n.º 5
0
        public async Task <EmployeeUpdateModel> UpdateAsync(EmployeeUpdateModel model, int clientId, int userId)
        {
            if (!await _permissionManager.HasPermission(clientId, userId, Permission.CanAddEmployee))
            {
                throw new Exception("User has not permission to perform this operation");
            }

            if (model == null)
            {
                throw new ArgumentNullException();
            }

            //check the employee shift extis or not
            var updateEmployeeShift = await _shiftHistroyManager.GetByEmployeeIdAsync(model.Id, clientId, userId);

            //This is used for update employee shift
            if (updateEmployeeShift == null || (updateEmployeeShift != null && updateEmployeeShift.ShiftId != model.ShiftId))
            {
                if (updateEmployeeShift != null)
                {
                    updateEmployeeShift.EndDate = DateTime.UtcNow;
                    await _shiftHistroyManager.UpdateAsync(updateEmployeeShift, clientId, userId);
                }
                //then afte update employee new shift timing
                var addNewEmployeeShift = new ShiftHistoryModel();
                addNewEmployeeShift.EmployeeId = model.Id;
                addNewEmployeeShift.ShiftId    = model.ShiftId;
                addNewEmployeeShift.StartDate  = DateTime.UtcNow;

                await _shiftHistroyManager.AddAsync(addNewEmployeeShift, clientId, userId);
            }

            var existingDataModel = await _employeeRepository.GetAsync(model.Id);

            if (existingDataModel == null)
            {
                throw new Exception("Employee does not exist which you trying to update");
            }

            var employee = _employeeUpdateMapper.ConvertToDataModel(model);

            employee.UpdatedOn = DateTime.UtcNow;

            employee = await _employeeRepository.UpdateAsync(employee);

            return(_employeeUpdateMapper.ConvertToModel(employee));
        }
Ejemplo n.º 6
0
        public async Task <ShiftHistoryModel> AddAsync(ShiftHistoryModel model, int clientId, int userId)
        {
            if (!await _permissionManager.HasUserClientAccessAsync(clientId, userId))
            {
                throw new Exception("User has not permission to perform this operation");
            }

            if (model == null)
            {
                throw new ArgumentNullException();
            }

            var shifthistory = _shiftHistoryMapper.ConvertToDataModel(model);

            shifthistory = await _shiftHistroryRepository.AddAsync(shifthistory);

            return(_shiftHistoryMapper.ConvertToModel(shifthistory));
        }
Ejemplo n.º 7
0
        public async Task <EmployeeRegisterModel> RegisterAsync(EmployeeRegisterModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException();
            }

            if (string.IsNullOrEmpty(model.DeviceId))
            {
                throw new Exception("Device id is required");
            }
            if (string.IsNullOrEmpty(model.Email))
            {
                throw new Exception("Email id is required");
            }
            if (string.IsNullOrEmpty(model.FirstName))
            {
                throw new Exception("First name id is required");
            }

            var existingDataModel = _employeeRepository.GetEmployeeByEmail(model.Email);

            if (existingDataModel != null)
            {
                throw new COHHttpException(HttpStatusCode.Found, false, "You are already register with this email id");
            }

            var app = await _applicationRepository.GetApplicationByClientId(model.ApplicationClientId);

            if (app == null)
            {
                throw new Exception("Application is not registered");
            }

            var client = app.Clients.FirstOrDefault();

            if (client == null || !client.IsActive)
            {
                throw new Exception("Client is not registered or not active");
            }

            var employee = _employeeRegisterMapper.ConvertToDataModel(model);

            employee.CreatedOn = DateTime.UtcNow;
            employee.UpdatedOn = DateTime.UtcNow;
            employee.ClientId  = client.Id;
            employee.Status    = (int)EmployeeStatus.Pending;

            employee = await _employeeRepository.RegisterAsync(employee);

            return(_employeeRegisterMapper.ConvertToModel(employee));
        }
Ejemplo n.º 8
0
        public EmployeeListModel ConvertToListModel(Employee dataModel)
        {
            if (dataModel == null)
            {
                return(null);
            }

            var model = new EmployeeListModel();

            model.Id           = dataModel.Id;
            model.EmployeeCode = dataModel.EmployeeCode;
            model.FirstName    = dataModel.FirstName;
            model.LastName     = dataModel.LastName;
            model.Email        = dataModel.Email;
            model.Contact      = dataModel.PhoneNumber;
            //model.WorkingHours = dataModel.WorkingHours.HasValue ? dataModel.WorkingHours.Value : 0;
            //model.BreakHours = dataModel.BreakHours.HasValue ? dataModel.BreakHours.Value : 0;
            model.Status = (EmployeeStatus)dataModel.Status;

            model.PlaceId   = dataModel.PlaceId.HasValue ? dataModel.PlaceId : null;
            model.PlaceName = dataModel.Place != null ? dataModel.Place.Name : "";

            model.DepartmentId   = dataModel.DepartmentId.HasValue ? dataModel.DepartmentId : null;
            model.DepartmentName = dataModel.Department != null ? dataModel.Department.Name : "";

            model.ImagePath = !string.IsNullOrEmpty(dataModel.ImagePath) ? Utilities.GetImageBasePath() + dataModel.ImagePath : "";

            if (dataModel.ShiftEmployeeHistories != null && dataModel.ShiftEmployeeHistories.Count != 0)
            {
                var shiftHistory = dataModel.ShiftEmployeeHistories.Where(s => s.EndDate == null).FirstOrDefault();
                if (shiftHistory != null)
                {
                    model.Shift = _shiftMapper.ConvertToModel(shiftHistory.Shift);
                    //var workingHours = model.Shift.ShiftDetails
                }
            }

            return(model);
        }
Ejemplo n.º 9
0
        public async Task <DeviceChangeRequestModel> AddAsync(DeviceChangeRequestModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException();
            }

            if (string.IsNullOrEmpty(model.DeviceId))
            {
                throw new Exception("Device id is required");
            }
            if (string.IsNullOrEmpty(model.Email))
            {
                throw new Exception("Email id is required");
            }

            var existingDataModel = _employeeRepository.GetEmployeeByEmail(model.Email);

            if (existingDataModel == null || existingDataModel.Status != (int)EmployeeStatus.Active)
            {
                throw new COHHttpException(HttpStatusCode.NotFound, false, "You are not our registered employee");
            }

            var exist = _changeRequestRepository.IsChangeRequestExist(model.Email, model.DeviceId);

            if (exist)
            {
                throw new COHHttpException(HttpStatusCode.Found, false, "You have already created device change request with this email id");
            }

            var changeRequest = _deviceChangeRequestMapper.ConvertToDataModel(model);

            changeRequest.Status        = (int)ChangeRequestStatus.Pending;
            changeRequest.RequestedDate = DateTime.UtcNow;

            changeRequest = await _changeRequestRepository.AddAsync(changeRequest);

            return(_deviceChangeRequestMapper.ConvertToModel(changeRequest));
        }
Ejemplo n.º 10
0
        public async Task <PlaceModel> AddAsync(PlaceModel model, int clientId, int userId)
        {
            if (model == null)
            {
                throw new ArgumentNullException();
            }

            if (!await _permissionManager.HasPermission(clientId, userId, Permission.CanAddPlace))
            {
                throw new Exception("User has not permission to perform this operation");
            }

            var place = _placeMapper.ConvertToDataModel(model);

            place.ClientId  = clientId;
            place.IsActive  = true;
            place.CreatedOn = DateTime.UtcNow;
            place.UpdatedOn = DateTime.UtcNow;

            place = await _placeRepository.AddAsync(place);

            return(_placeMapper.ConvertToModel(place));
        }
Ejemplo n.º 11
0
        public async Task <DepartmentModel> AddAsync(DepartmentModel model, int clientId, int userId)
        {
            if (model == null)
            {
                throw new ArgumentNullException();
            }

            if (!await _permissionManager.HasPermission(clientId, userId, Permission.CanAddDepartment))
            {
                throw new Exception("User has not permission to perform this operation");
            }

            var department = _departmentMapper.ConvertToDataModel(model);

            department.IsActive  = true;
            department.CreatedOn = DateTime.UtcNow;
            department.UpdatedOn = DateTime.UtcNow;
            department.ClientId  = clientId;

            department = await _departmentRepository.AddAsync(department);

            return(_departmentMapper.ConvertToModel(department));
        }
Ejemplo n.º 12
0
        public async Task <LeaveModel> AddMeAsync(LeaveModel model, int employeeId)
        {
            if (model == null)
            {
                throw new ArgumentNullException();
            }

            var leave = _leaveMapper.ConvertToDataModel(model);

            leave.EmployeeId = employeeId;
            leave.Status     = (int)LeaveStatus.Pending;

            leave = await _leaveRepository.AddAsync(leave);

            return(_leaveMapper.ConvertToModel(leave));
        }
Ejemplo n.º 13
0
        public async Task <IEnumerable <HolidayModel> > QueryMeAsync(int employeeId)
        {
            var holidays = await _holidayRepository.QueryByEmployeeAsync(employeeId);

            return(holidays.ToList().Select(p => _holidayMapper.ConvertToModel(p)));
        }
Ejemplo n.º 14
0
        public async Task <EmployeeModel> Login(string deviceId, string emailId)
        {
            var employee = await _employeeRepository.Login(deviceId, emailId);

            return(_employeeMapper.ConvertToModel(employee));
        }
Ejemplo n.º 15
0
        public async Task <IEnumerable <BeaconModel> > QueryAsyncForMobile(int clientId)
        {
            var beacons = await _beaconRepository.QueryAsync(clientId);

            return(beacons.ToList().Select(u => _beaconMapper.ConvertToModel(u)));
        }
Ejemplo n.º 16
0
        public async Task <UserMeModel> GetMeAsync(int id)
        {
            var user = await _usersRepository.GetUserByIdAsync(id);

            return(_userMeMapper.ConvertToModel(user));
        }