Example #1
0
        public IActionResult AddWithLegalEntity([FromBody] CreateEditViewModel model)
        {
            var orgUnit = new OrgUnit();

            _mapper.Map(model, orgUnit);
            var legalEntity = new LegalEntityInformation();

            model.SuperiorID = EncryptionHelper.DecryptUrlParam(model.SuperiorID);
            var legalEntityMapper = _mapper.Map(model, legalEntity);

            legalEntity.ManagingDirectorId = Convert.ToInt32(EncryptionHelper.DecryptUrlParam(model.ManagingDirectorID));
            _organizationUnitProvider.AddLegalEntity(legalEntityMapper);

            orgUnit.LegalEntityInformation = legalEntity;
            //if (model.AttachmentFile != null)
            //{
            //    var theObject = new OrgUnit();
            //    var tableName = GetTableName(theObject);

            //    var attachment = new Attachment
            //    {
            //        TableOriginID = orgUnit.ID,
            //        TableOriginName = tableName,
            //        AttachmentFile = model.AttachmentFile
            //    };

            //model.SuperiorID = !string.IsNullOrEmpty(model.SuperiorID) ? EncryptionHelper.DecryptUrlParam(model.SuperiorID) : null;

            var orgUnitMapper = _mapper.Map(model, orgUnit);

            _organizationUnitProvider.Add(orgUnitMapper);

            return(Ok(orgUnitMapper));
        }