Exemple #1
0
        public async Task <IActionResult> CreateOrganization([FromBody] OrganizationRegister organizationToRegister)
        {
            if (organizationToRegister == null)
            {
                return(BadRequest());
            }

            Organization organization = _dbContext.Organizations.FirstOrDefault(cus => cus.Name == organizationToRegister.Name);

            if (organization == null)
            {
                organization = Mapper.Map <Organization>(organizationToRegister);
                _dbContext.Add(organization);
                await _dbContext.SaveChangesAsync();

                return(Ok());
            }
            else
            {
                return(Conflict("Organization with this Name already exists."));
            }
        }
Exemple #2
0
        public async Task <IActionResult> RegisterSeal([FromBody] SealRegister sealToRegister)
        {
            if (sealToRegister == null)
            {
                BadRequest();
            }

            string userName = HttpContext.User.Identity.Name;
            User   user     = await _userManager.FindByNameAsync(userName);

            if (user.Organization == null)
            {
                return(BadRequest("User is not subscribied to any Organization"));
            }

            var seal = Mapper.Map <Seal>(sealToRegister);

            seal.Organization = user.Organization;

            _dbContext.Add(seal);
            await _dbContext.SaveChangesAsync();

            return(Ok());
        }