Exemplo n.º 1
0
        public int Register(UserAdditional user)
        {
            var encounter = unitOfWork.EncounterRepository.GetEncounterByUniqueCodeId(user.UniqueCodeId);

            if (encounter == null)
            {
                throw new Exception($"No encounter found for uniqueId {user.UniqueCodeId}");
            }
            var userCheck = unitOfWork.UserInfoRepository.GetUserByUnicodeId(user.UniqueCodeId);

            if (userCheck != null)
            {
                throw new Exception($"An account for unicodeId {user.UniqueCodeId} already exists");
            }
            var patientId = encounter.PatientId;
            var patient   = unitOfWork.PatientRepository.Details(patientId);

            patient.Email = user.Email;
            patient.Phone = user.Phone;
            unitOfWork.PatientRepository.Edit(patient);
            var userCreated = user.UserInfoDetails(encounter.Id);

            userCreated.Password = BCrypt.Net.BCrypt.HashPassword(user.Password);
            unitOfWork.UserInfoRepository.Create((userCreated));
            unitOfWork.Commit();

            return(encounter.Id);
        }
Exemplo n.º 2
0
        public async Task <ResultDTO> changeUserRole([FromBody] UserAdditional model, [FromRoute] string role)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(new ResultDTO
                    {
                        Status = 404,
                        Message = "model not valid"
                    });
                }
                var currentUserAditional = _eFContext.UserAdditional.FirstOrDefault(x => x.FullName == model.FullName);

                var user = _eFContext.Users.FirstOrDefault(x => x.Id == currentUserAditional.Id);
                if (role == "Manager")
                {
                    await _userManager.RemoveFromRoleAsync(user, "User");

                    var managerNews = _eFContext.News.Where(x => x.ManagerId == user.Id).ToArray();
                    foreach (var item in managerNews)
                    {
                        item.IsBlocked = false;
                        _newsService.Update(item);
                    }
                }
                else
                {
                    await _userManager.RemoveFromRoleAsync(user, "Manager");

                    var managerNews = _eFContext.News.Where(x => x.ManagerId == user.Id).ToArray();
                    foreach (var item in managerNews)
                    {
                        item.IsBlocked = true;
                        _newsService.Update(item);
                    }
                }

                await _userManager.AddToRoleAsync(user, role);

                currentUserAditional.UserRole = role;
                _userService.editUser(currentUserAditional);
                return(new ResultDTO
                {
                    Status = 200,
                    Message = "ok"
                });
            }
            catch (Exception e)
            {
                return(new ResultDTO
                {
                    Status = 400,
                    Message = e.Message
                });
            }
        }
 public IActionResult Register([FromBody] UserAdditional user)
 {
     try
     {
         var encounterId = registerService.Register(user);
         return(Ok(new EncounterIdResponse
         {
             EncounterId = encounterId
         }));
     }
     catch (Exception e)
     {
         return(Ok(e.Message.ToString()));
     }
 }
Exemplo n.º 4
0
        public async Task <ResultDTO> Register([FromBody] UserRegisterDTO model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(new ResultErrorDTO
                    {
                        Status = 403,
                        Message = "error",
                        Errors = CustomValidator.GetErrorsByModel(ModelState)
                    });
                }
                var user = new User()
                {
                    UserName    = model.Email,
                    Email       = model.Email,
                    PhoneNumber = model.Phone
                };

                var userProFile = new UserAdditional()
                {
                    Address      = model.Address,
                    Image        = "default.jpg",
                    DataRegister = DateTime.Now.ToShortDateString(),
                    PublishCount = "0",
                    FullName     = model.FullName,
                    Id           = user.Id
                };

                IdentityResult result = await _userManager.CreateAsync(user, model.Password);

                if (!result.Succeeded)
                {
                    return(new ResultErrorDTO
                    {
                        Message = "error",
                        Status = 500,
                        Errors = CustomValidator.GetErrorByIdentityResult(result)
                    });
                }
                else
                {
                    result = _userManager.AddToRoleAsync(user, "User").Result;
                    userProFile.UserRole = "User";
                    _eFContext.UserAdditional.Add(userProFile);

                    _eFContext.SaveChanges();
                }


                return(new ResultDTO
                {
                    Status = 200,
                    Message = "OK"
                });
            }
            catch (Exception e)
            {
                return(new ResultDTO
                {
                    Status = 500,
                    Message = e.Message
                });
            }
        }
Exemplo n.º 5
0
        private void SaveAgentAdditional(FrayteAgent frayteAgentUser)
        {
            UserAdditional customerDetail = dbContext.UserAdditionals.Where(p => p.UserId == frayteAgentUser.UserId).FirstOrDefault();

            if (customerDetail != null)
            {
                customerDetail.UserId    = frayteAgentUser.UserId;
                customerDetail.AccountNo = "000000000";

                if (frayteAgentUser.AccountUser != null)
                {
                    customerDetail.AccountUserId = frayteAgentUser.AccountUser.UserId;
                }

                if (frayteAgentUser.DocumentUser != null)
                {
                    customerDetail.DocumentUserId = frayteAgentUser.DocumentUser.UserId;
                }

                if (frayteAgentUser.ManagerUser != null)
                {
                    customerDetail.ManagerUserId = frayteAgentUser.ManagerUser.UserId;
                }

                if (frayteAgentUser.OperationUser != null)
                {
                    customerDetail.OperationUserId = frayteAgentUser.OperationUser.UserId;
                }
            }
            else
            {
                if (frayteAgentUser.AccountUser != null ||
                    frayteAgentUser.DocumentUser != null ||
                    frayteAgentUser.ManagerUser != null ||
                    frayteAgentUser.OperationUser != null)
                {
                    customerDetail           = new UserAdditional();
                    customerDetail.UserId    = frayteAgentUser.UserId;
                    customerDetail.AccountNo = "000000000";

                    if (frayteAgentUser.AccountUser != null)
                    {
                        customerDetail.AccountUserId = frayteAgentUser.AccountUser.UserId;
                    }

                    if (frayteAgentUser.DocumentUser != null)
                    {
                        customerDetail.DocumentUserId = frayteAgentUser.DocumentUser.UserId;
                    }

                    if (frayteAgentUser.ManagerUser != null)
                    {
                        customerDetail.ManagerUserId = frayteAgentUser.ManagerUser.UserId;
                    }

                    if (frayteAgentUser.OperationUser != null)
                    {
                        customerDetail.OperationUserId = frayteAgentUser.OperationUser.UserId;
                    }

                    dbContext.UserAdditionals.Add(customerDetail);
                }
            }

            if (customerDetail != null)
            {
                dbContext.SaveChanges();
            }
        }
Exemplo n.º 6
0
 public void editUser(UserAdditional user)
 {
     _userRepo.Update(user);
 }
Exemplo n.º 7
0
 public void deleteUser(UserAdditional user)
 {
     _userRepo.Delete(user);
 }