예제 #1
0
        public async Task DeleteEmployee(string loggedUserId, EmployeeTypeEnum loggedUserType, string employeeId, string employeeConcurrencyToken)
        {
            if (loggedUserId == employeeId)
            {
                throw new ArgumentException("Cannot delete logged user.");
            }
            if (loggedUserType == EmployeeTypeEnum.User)
            {
                throw new AdminRoleRequiredException();
            }

            var employee = await _context.Users.FindAsync(employeeId);

            if (employee == null)
            {
                return;
            }
            if (employee.EmployeeType == EmployeeTypeEnum.MasterAdmin)
            {
                throw new ArgumentException("Master admin cannot be deleted.");
            }
            if (employee.ConcurrencyStamp != employeeConcurrencyToken)
            {
                throw new ValuesChangedByAnotherUserException();
            }

            _context.Users.Remove(employee);
            await _context.SaveChangesAsync();
        }
예제 #2
0
        public async Task <CalendarEntryDTO> AddUpdateCalendarEntry(string loggedUserId, EmployeeTypeEnum loggedUserType, CalendarEntryDTO entryDTO)
        {
            if (entryDTO.EmployeeId != loggedUserId && loggedUserType == EmployeeTypeEnum.User)
            {
                throw new AdminRoleRequiredException();
            }
            if (entryDTO.StartDate >= entryDTO.EndDate)
            {
                throw new ArgumentException("End Date must be after Start Date");
            }

            CalendarEntry entry = entryDTO.IsNew ? await addCalendarEntry(loggedUserType, entryDTO) : await updateCalendarEntry(loggedUserId, loggedUserType, entryDTO);

            await _context.SaveChangesAsync();

            return(DtoMapper.MapCalendarEntryToDTO(entry));
        }