public async Task <ActionResult> PostRegisterUser([FromBody] RegistrationDTO registrationDTO)
        {
            await _tenantRepository.Add(new Tenant()
            {
                CompanyName = registrationDTO.CompanyName, CompanyStrength = registrationDTO.CompanyStrength
            });

            if (await _tenantRepository.FirstOrDefault(tenant => tenant.CompanyName == registrationDTO.CompanyName) != null)
            {
                Tenant tenantAcc = await _tenantRepository.FirstOrDefault(tenant => tenant.CompanyName == registrationDTO.CompanyName);

                await _userRepository.Add(new User()
                {
                    Id       = new Guid(),
                    Username = registrationDTO.Username,
                    Password = _encryptorDecryptor.Encrypt(registrationDTO.Password),
                    Email    = registrationDTO.CompanyEmail,
                    Role     = "Admin",
                    TenantId = tenantAcc.Id,
                });

                if (await _userRepository.FirstOrDefault(user => user.Email == registrationDTO.CompanyEmail) != null)
                {
                    return(Ok("User added successfully"));
                }
                else
                {
                    return(BadRequest("Cannot add user"));
                }
            }
            else
            {
                return(BadRequest("Cannot Register User"));
            }
        }
示例#2
0
 public async Task <ActionResult> PostEmailValidation(string tenantId, string email)
 {
     if (await _tenantRepository.GetById(Guid.Parse(tenantId)) == null)
     {
         return(BadRequest("Tenant id is not valid"));
     }
     if (await _userRepository.FirstOrDefault(user => user.Email == email) != null)
     {
         return(BadRequest("Email id is not available"));
     }
     else
     {
         return(Ok("Email is available"));
     }
 }
示例#3
0
        public async Task <ActionResult> AddUserContact(string tenantId, string userId, [FromBody] ContactDTO contactDTO)
        {
            if (_tenantRepository.GetById(Guid.Parse(tenantId)) == null)
            {
                return(BadRequest("Tenant id is not valid"));
            }
            if (_userRepository.GetById(Guid.Parse(userId)) == null)
            {
                return(BadRequest("User id is not valid"));
            }

            if (ModelState.IsValid)
            {
                Contact contact = await _contactRepository.FirstOrDefault(con => con.PhoneNumber == contactDTO.PhoneNumber);

                if (contact == null)

                {
                    await _contactRepository.Add(new Contact { FirstName = contactDTO.FirstName, LastName = contactDTO.LastName, PhoneNumber = contactDTO.PhoneNumber, UserId = Guid.Parse(userId) });

                    return(Ok("contact added successfully"));
                }
                else
                {
                    return(BadRequest("Cannot add contact"));
                }
            }
            else
            {
                return(BadRequest("Please check if all the field values are provided"));
            }
        }
        public async Task <ActionResult> PostLoginUser([FromBody] UserDTO userDTO)
        {
            if (ModelState.IsValid)
            {
                var userAccount = await _userRepository.FirstOrDefault(user => user.Username == userDTO.Username && user.Password == _encryptorDecryptor.Encrypt(userDTO.Password));

                if (userAccount == null)
                {
                    return(BadRequest("User account does not exist"));
                }

                return(Ok(userAccount));
            }
            else
            {
                return(BadRequest("Please make sure credentials are correct"));
            }
        }
示例#5
0
        public async Task <IActionResult> PostAddress(string tenantId, string userId, string contactId, [FromBody] AddressDTO addressDTO)
        {
            if (await _tenantRepository.GetById(Guid.Parse(tenantId)) == null)
            {
                return(BadRequest("Tenant id is not valid"));
            }
            if (await _userRepository.GetById(Guid.Parse(userId)) == null)
            {
                return(BadRequest("User id is not valid"));
            }
            if (await _contactRepository.GetById(Guid.Parse(contactId)) == null)
            {
                return(BadRequest("contact id is not valid"));
            }


            if (ModelState.IsValid)
            {
                Address address = await _addressRepository.FirstOrDefault(address => address.ContactID == Guid.Parse(contactId) && address.City == addressDTO.City);

                if (address == null)
                {
                    await _addressRepository.Add(new Address {
                        Id        = new Guid(),
                        City      = addressDTO.City,
                        ContactID = Guid.Parse(contactId),
                        State     = addressDTO.State,
                        Country   = addressDTO.Country
                    });

                    return(Ok("Address added successfully"));
                }
                else
                {
                    return(BadRequest("Cannot add address"));
                }
            }
            else
            {
                return(BadRequest("Please check if all the field values are provided"));
            }
        }
示例#6
0
        public async Task <ActionResult <TokenDTO> > GetTenantIdByCompanyName(string companyName)

        {
            if (companyName != null && companyName != "" && companyName != " ")
            {
                var tenant = await _tenantRepository.FirstOrDefault(tenant => tenant.CompanyName == companyName);

                if (tenant == null)
                {
                    return(BadRequest("cannot fetch tenant id"));
                }

                return(Ok(new TokenDTO {
                    Token = tenant.Id, CompanyName = tenant.CompanyName
                }));
            }
            else
            {
                return(BadRequest("please provide company name"));
            }
        }
        public async Task <ActionResult> PostLoginSuperAdmin([FromBody] SuperAdminLoginDTO superAdminLoginDTO)
        {
            if (ModelState.IsValid)
            {
                SuperAdmin userData = await _superAdmin.FirstOrDefault(user => user.Email == superAdminLoginDTO.Email && user.Password == superAdminLoginDTO.Password);

                if (userData != null)
                {
                    string token = _customTokenManager.CreateSuperAdminToken(userData);
                    return(Ok(new { Token = token }));
                }
                else
                {
                    return(BadRequest("SuperAdmin credentials not valid"));
                }
            }
            else
            {
                return(BadRequest("Please provide value for all fields"));
            }
        }