Ejemplo n.º 1
0
 /// <summary>
 ///  删除
 /// </summary>
 /// <param name="id">员工id</param>
 /// <returns></returns>
 public async Task RemoveEmp(Guid id)
 {
     using IEmployeesService employeesService = new EmployeesService();
     if (await employeesService.GetAllAsync().AnyAsync(i => i.Id == id))
     {
         var emp = employeesService.GetAllAsync().FirstOrDefault(i => i.Id == id);
         if (emp != null)
         {
             await employeesService.RemoveAsync(id);
         }
     }
 }
Ejemplo n.º 2
0
        public async Task GetByUsernameAsyncReturnsCorrect()
        {
            var id   = Guid.NewGuid().ToString();
            var user = new CarpetUser
            {
                Id          = id,
                FirstName   = "Иван",
                LastName    = "Иванов",
                PhoneNumber = "0888777444",
                Email       = "*****@*****.**",
                UserName    = "******",
            };
            var roleAdminId = Guid.NewGuid().ToString();
            var role        = new CarpetRole {
                Id = roleAdminId, Name = GlobalConstants.AdministratorRoleName
            };
            var roleOperatorId = Guid.NewGuid().ToString();
            var roleOperator   = new CarpetRole {
                Id = roleOperatorId, Name = GlobalConstants.OperatorRoleName
            };

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetByUsernameAsyncReturnsCorrect")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            dbContext.Users.Add(user);
            dbContext.Roles.Add(role);
            dbContext.Roles.Add(roleOperator);
            await dbContext.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <Employee>(dbContext);
            var service    = new EmployeesService(repository, dbContext);

            var employee = new EmployeeCreateInputModel
            {
                Id          = id,
                FirstName   = "Иван",
                LastName    = "Иванов",
                PhoneNumber = "0888777444",
                Salary      = 1000m,
                RoleName    = GlobalConstants.OperatorRoleName,
            };

            var result = await service.CreateAsync(employee, string.Empty);

            var username = await dbContext.Employees.FirstOrDefaultAsync(x => x.Id == result.Id);

            var actual = await service.GetIdByUserNameAsync(username.User.UserName);

            var employees = await service.GetAllAsync <EmployeeIndexViewModel>().ToListAsync();

            Assert.Equal(result.Id, actual);
            Assert.Single(employees);
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> Get(int id)
        {
            var obj = await _service.GetAllAsync(id);

            if (obj == null)
            {
                return(NotFound());
            }

            return(Ok(obj));
        }
Ejemplo n.º 4
0
 /// <summary>
 ///  修改
 /// </summary>
 /// <param name="id">id</param>
 /// <param name="password">密码</param>
 /// <param name="uName">名称</param>
 /// <param name="sex">性别</param>
 /// <param name="age">年龄</param>
 /// <param name="phone">手机号</param>
 /// <param name="email">邮箱</param>
 /// <param name="address">地址</param>
 /// <param name="image">头像</param>
 /// <param name="remarks">备注</param>
 /// <param name="status">状态</param>
 /// <param name="branchId">部门</param>
 /// <returns></returns>
 public async Task EditEmp(Guid id, string password, string uName, bool sex, int age, string phone, string email, string address,
                           string image, string remarks, bool status, Guid branchId)
 {
     using IEmployeesService employeesService = new EmployeesService();
     if (await employeesService.GetAllAsync().AnyAsync(i => i.Id == id))
     {
         var emp = employeesService.GetAllAsync().FirstOrDefault(i => i.Id == id);
         if (emp != null)
         {
             emp.Password = password;
             emp.Name     = uName;
             emp.Sex      = sex;
             emp.Age      = age;
             emp.Phone    = phone;
             emp.Email    = email;
             emp.Address  = address;
             emp.Image    = image;
             emp.Remarks  = remarks;
             emp.Status   = status;
             emp.BranchId = branchId;
         }
         await employeesService.EditAsync(emp);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        ///  登录
        /// </summary>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public bool Login(string email, string password, out Guid userId)
        {
            using IEmployeesService employeesService = new EmployeesService();
            var use = employeesService.GetAllAsync().FirstOrDefault(s => s.Email == email && s.Password == password);

            if (use != null)
            {
                userId = use.Id;
                return(true);
            }
            else
            {
                userId = new Guid();
                return(false);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 ///  获取所有员工信息
 /// </summary>
 /// <returns></returns>
 public async Task <List <EmployeesDto> > GetAllEmployees()
 {
     using IEmployeesService employeesService = new EmployeesService();
     return(await employeesService.GetAllAsync().Select(i => new EmployeesDto()
     {
         Id = i.Id,
         TheWorkNumber = i.TheWorkNumber,
         Password = i.Password,
         UName = i.Name,
         Sex = i.Sex,
         Age = i.Age,
         Phone = i.Phone,
         Email = i.Email,
         Address = i.Address,
         Image = i.Image,
         Remarks = i.Remarks,
         Status = i.Status,
         BranchId = i.BranchId,
     }).ToListAsync());
 }
Ejemplo n.º 7
0
        public async Task ShouldReturnAllEmployeesOfAdminsCompany()
        {
            var tenantId   = Guid.NewGuid();
            var employeeId = Guid.NewGuid();
            var isActive   = true;

            var employees = new List <Employee>
            {
                new Employee
                {
                    Id             = employeeId,
                    FirstName      = "FirstName",
                    LastName       = "LastName",
                    PatronymicName = "PatronymicName",
                    TenantId       = tenantId,
                    SecurityUser   = new SecurityUser
                    {
                        User = new User
                        {
                            Roles = new List <UserRole>()
                        },
                        IsActive = isActive
                    }
                },
                new Employee
                {
                    Id             = Guid.NewGuid(),
                    FirstName      = "FirstName",
                    LastName       = "LastName",
                    PatronymicName = "PatronymicName",
                    TenantId       = Guid.NewGuid(),
                    SecurityUser   = new SecurityUser
                    {
                        User = new User
                        {
                            Roles = new List <UserRole>()
                        },
                        IsActive = isActive
                    }
                },
            };

            var expected = new List <EmployeeDTO>
            {
                new EmployeeDTO
                {
                    Id             = employeeId,
                    IsActive       = isActive,
                    FirstName      = "FirstName",
                    LastName       = "LastName",
                    PatronymicName = "PatronymicName",
                    FullName       = "FirstName LastName PatronymicName",
                }
            };

            _mock.Mock <IInventContext>()
            .Setup(context => context.Employees)
            .ReturnsAsDbSet(employees);

            var actual = await _service.GetAllAsync(tenantId);

            ContentAssert.AreEqual(expected, actual);
        }