Ejemplo n.º 1
0
        public IActionResult EditWithLegalEntity([FromBody] CreateEditViewModel model)
        {
            var orgUnit = _organizationUnitProvider.Get(Convert.ToInt32(model.ID));

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

            if (model.LegalEntityInformationID.HasValue)
            {
                legalEntity = _organizationUnitProvider.GetLegalEntityInformation(model.LegalEntityInformationID.GetValueOrDefault());
                var legalEntityMapper = _mapper.Map(model, legalEntity);

                _organizationUnitProvider.EditLegalEntity(legalEntityMapper);
            }
            else
            {
                var legalEntityMapper = _mapper.Map(model, legalEntity);

                _organizationUnitProvider.AddLegalEntity(legalEntityMapper);
            }
            #region Attachment
            //if (model.AttachmentFile != null)
            //{
            //    var theObject = new OrgUnit();
            //    var tableName = GetTableName(theObject);

            //    if (legalEntity.AttachmentID.HasValue)
            //    {
            //        var attachment = GetAttachment(legalEntity.AttachmentID.GetValueOrDefault());
            //        attachment.TableOriginID = orgUnit.ID;
            //        attachment.TableOriginName = tableName;
            //        attachment.AttachmentFile = model.AttachmentFile;

            //        SetAuditFields(attachment);

            //        legalEntity.Attachment = attachment;
            //    }
            //    else
            //    {
            //        var attachment = new Attachment();
            //        attachment.TableOriginID = orgUnit.ID;
            //        attachment.TableOriginName = tableName;
            //        attachment.AttachmentFile = model.AttachmentFile;

            //        context.Attachment.Add(attachment);
            //        SetAuditFields(attachment);

            //        legalEntity.Attachment = attachment;
            //    }

            //}
            #endregion
            orgUnit.LegalEntityInformation = legalEntity;
            var orgUnitMapper = _mapper.Map(model, orgUnit);
            _organizationUnitProvider.Edit(orgUnitMapper);

            return(Ok(orgUnitMapper));
        }