public async Task <HolidayModel> AddAsync(HolidayModel model, int clientId, int userId) { if (model == null) { throw new ArgumentNullException(); } if (!await _permissionManager.HasPermission(clientId, userId, Permission.CanAddHoliday)) { throw new Exception("User has not permission to perform this operation"); } var result = await _holidayRepository.IsHolidayExistsAsync(clientId, model.Id, model.StartDate, model.EndDate); if (result) { throw new Exception("Already inserted holiday"); } var holiday = _holidayMapper.ConvertToDataModel(model); holiday.ClientId = clientId; holiday = await _holidayRepository.AddAsync(holiday); return(_holidayMapper.ConvertToModel(holiday)); }
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)); }
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); }
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)); }
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)); }
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)); }
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)); }
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)); }
public async Task <EmployeeModel> UpdateMeAsync(EmployeeModel model) { if (model == null) { throw new ArgumentNullException(); } var existingDataModel = await _employeeRepository.GetAsync(model.Id); if (existingDataModel == null) { throw new Exception("Employee does not exist which you trying to update"); } var employee = _employeeMapper.ConvertToDataModel(model); employee.UpdatedOn = DateTime.UtcNow; employee = await _employeeRepository.UpdateMeAsync(employee); return(_employeeMapper.ConvertToModel(employee)); }
public async Task <BeaconModel> AddAsync(BeaconModel model, int clientId, int userId) { if (!await _permissionManager.HasPermission(clientId, userId, Permission.CanAddBeacon)) { throw new Exception("User has not permission to perform this operation"); } if (model == null) { throw new ArgumentNullException(); } var beacon = _beaconMapper.ConvertToDataModel(model); beacon.IsActive = true; beacon.CreatedOn = DateTime.UtcNow; beacon.UpdatedOn = DateTime.UtcNow; beacon = await _beaconRepository.AddAsync(beacon); return(_beaconMapper.ConvertToModel(beacon)); }
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)); }
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)); }
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)); }
public async Task <UserModel> UpdateAsync(UserModel model, int clientId, int userId) { if (!await _permissionManager.HasPermission(clientId, userId, Permission.CanEditUser)) { throw new Exception("User has not permission to perform this operation"); } var existing = _usersRepository.GetUserByEmail(model.Email); if (existing != null && existing.Id != model.Id) { throw new Exception("Email already exists"); } var user = _usersMapper.ConvertToDataModel(model); user.UpdatedOn = DateTime.UtcNow; user = await _usersRepository.UpdateAsync(user); return(_usersMapper.ConvertToModel(user)); }