Ejemplo n.º 1
0
        public async Task <IActionResult> PostOrganizationAsync([FromBody] OrganizationRequest request)
        {
            var existingEntity = await OrganizationService.GetOrganizationByNameAsync(request.OrganizationName);

            if (existingEntity.Model != null)
            {
                ModelState.AddModelError("OrganizationName", "Organization name already exists");
            }

            if (!ModelState.IsValid)
            {
                throw new Exception();
            }

            var entity = request;//.ToEntity();

            if (request.OrganizationParentId != null)
            {
                entity.OrganizationTypeId = (int)OrganizationTypeEnum.SecondaryOrganization;
            }

            var response = await OrganizationService.CreateOrganizationAsync(entity);


            Docs docs = new Docs();

            docs.EntityId     = response.Model.OrganizationId;
            docs.EntityTypeId = (int)EntityTypeEnum.Organization;

            var DOCSResponse = await OrganizationService.CreateDocsAsync(docs, typeof(Organization), request.OrganizationName, request.fileRequest, (int)DocumentType.Logo);

            if (DOCSResponse.DIdError)
            {
                throw new Exception("Error in create Document Organization" + response.Message);
            }


            entity.OrganizationFaceGroup = "facegroup" + response.Model.OrganizationId;
            var response2 = await OrganizationService.UpdateOrganizationAsync(entity);

            return(response.ToHttpResponse());
        }