Ejemplo n.º 1
0
        public async Task <ActionResult> CreateManagerOrEmployee(AddManagerOrEmployee clerk)
        {
            var response = await service.CreateManagerOrEmployee(clerk);

            if (response.status == true)
            {
                return(Ok(response));
            }
            return(BadRequest(response));
        }
Ejemplo n.º 2
0
        public async Task <IResponse> CreateManagerOrEmployee(AddManagerOrEmployee clerk)
        {
            AppUser newAppUser = new AppUser
            {
                UserName       = clerk.UserName,
                Email          = clerk.Email,
                EmailConfirmed = true,
            };
            var result = await userManager.CreateAsync(newAppUser, clerk.Password);

            if (result.Succeeded)
            {
                await userManager.AddToRoleAsync(newAppUser, clerk.RoleName);

                if (clerk.RoleName == "MANAGER")
                {
                    UOW.Managers.Add(new AppUserManager()
                    {
                        UserId = newAppUser.Id, BranchId = clerk.BranchId
                    });
                }
                else
                {
                    var selectedBranchDepartement = UOW.BranchDepartement.SingleOrDefault(bd => bd.BranchId == clerk.BranchId && bd.DepartementId == clerk.DepartementId);
                    if (selectedBranchDepartement != null)
                    {
                        UOW.Employees.Add(new AppUserEmployee()
                        {
                            UserId = newAppUser.Id, BranchDepartementId = selectedBranchDepartement.Id
                        });
                    }
                }
                UOW.Compelete();
            }
            else
            {
                response.error_EN = result.Errors.Select(e => e.Description).FirstOrDefault();
                response.status   = false;
            }
            return(response);
        }