Beispiel #1
0
        public async Task <ActionResult> PostUser(string tenantId, [FromBody] UserDTO userDTO)
        {
            if (await _tenantRepository.GetById(Guid.Parse(tenantId)) == null)
            {
                return(BadRequest("Tenant id is not valid"));
            }

            if (ModelState.IsValid)
            {
                User userToBeAdded = await _userRepository.FirstOrDefault(user => user.Email == userDTO.Email);

                if (userToBeAdded == null)
                {
                    await _userRepository.Add(new User {
                        Id       = new Guid(),
                        Username = userDTO.Username,
                        Email    = userDTO.Email,
                        Role     = userDTO.UserRole,
                        Password = _encryptorDecryptor.Encrypt(userDTO.Password),
                        TenantId = Guid.Parse(tenantId)
                    });

                    return(Ok("User added successfully"));
                }
                else
                {
                    return(Ok("User account already exists"));
                }
            }
            else
            {
                return(BadRequest("Please check if all the field values are provided"));
            }
        }
        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"));
            }
        }
        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"));
            }
        }
Beispiel #4
0
        public async Task <ActionResult> AddTenant([FromBody] TenantDTO tenantDTO)
        {
            if (ModelState.IsValid)
            {
                await _tenantRepository.Add(new Tenant { CompanyName = tenantDTO.CompanyName, CompanyStrength = tenantDTO.CompanyStrength });

                return(Ok("Tenant added successfully"));
            }
            else
            {
                return(BadRequest("Please check if all the field values are provided"));
            }
        }
        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"));
            }
        }