예제 #1
0
        public IHttpActionResult CreateCorrespondent(CorrespondentDO corr)
        {
            var result = this.correspondentRepository.CreateCorrespondent(corr, this.userContext);

            return Ok(new
                {
                    err = "",
                    correspondentId = result.CorrespondentId,
                    obj = result
                });
        }
예제 #2
0
        public IHttpActionResult GetCorrespondent(int id)
        {
            Correspondent correspondent = this.correspondentRepository.GetCorrespondent(id);

            if (correspondent == null)
            {
                return NotFound();
            }

            CorrespondentDO returnValue = new CorrespondentDO(correspondent);

            foreach (CorrespondentContact cc in correspondent.CorrespondentContacts.ToList())
            {
                returnValue.CorrespondentContacts.Add(new CorrespondentContactDO(cc));
            }

            returnValue.SetupFlags();

            return Ok(returnValue);
        }
예제 #3
0
        public IHttpActionResult UpdateCorrespondent(int id, CorrespondentDO corr)
        {
            var oldCorr = this.correspondentRepository.GetCorrespondent(id);

            oldCorr.EnsureForProperVersion(corr.Version);

            oldCorr.BgCitizenFirstName = null;
            oldCorr.BgCitizenLastName = null;
            oldCorr.BgCitizenUIN = null;

            oldCorr.ForeignerFirstName = null;
            oldCorr.ForeignerLastName = null;
            oldCorr.ForeignerCountry = null;
            oldCorr.ForeignerCountryId = null;
            oldCorr.ForeignerSettlement = null;
            oldCorr.ForeignerBirthDate = null;

            oldCorr.LegalEntityName = null;
            oldCorr.LegalEntityBulstat = null;

            oldCorr.FLegalEntityName = null;
            oldCorr.FLegalEntityCountry = null;
            oldCorr.FLegalEntityCountryId = null;
            oldCorr.FLegalEntityRegisterName = null;
            oldCorr.FLegalEntityRegisterNumber = null;
            oldCorr.FLegalEntityOtherData = null;

            CorrespondentType correspondentType = this.unitOfWork.DbContext.Set<CorrespondentType>()
                .SingleOrDefault(e => e.CorrespondentTypeId == corr.CorrespondentTypeId);

            switch (correspondentType.Alias)
            {
                case "BulgarianCitizen":
                    oldCorr.BgCitizenFirstName = corr.BgCitizenFirstName;
                    oldCorr.BgCitizenLastName = corr.BgCitizenLastName;
                    oldCorr.BgCitizenUIN = corr.BgCitizenUIN;
                    break;
                case "Foreigner":
                    oldCorr.ForeignerFirstName = corr.ForeignerFirstName;
                    oldCorr.ForeignerLastName = corr.ForeignerLastName;
                    oldCorr.ForeignerCountryId = corr.ForeignerCountryId;
                    oldCorr.ForeignerSettlement = corr.ForeignerSettlement;
                    oldCorr.ForeignerBirthDate = corr.ForeignerBirthDate;
                    break;
                case "LegalEntity":
                    oldCorr.LegalEntityName = corr.LegalEntityName;
                    oldCorr.LegalEntityBulstat = corr.LegalEntityBulstat;
                    break;
                case "ForeignLegalEntity":
                    oldCorr.FLegalEntityName = corr.FLegalEntityName;
                    oldCorr.FLegalEntityCountryId = corr.FLegalEntityCountryId;
                    oldCorr.FLegalEntityRegisterName = corr.FLegalEntityRegisterName;
                    oldCorr.FLegalEntityRegisterNumber = corr.FLegalEntityRegisterNumber;
                    oldCorr.FLegalEntityOtherData = corr.FLegalEntityOtherData;
                    break;
            };

            oldCorr.CorrespondentGroupId = corr.CorrespondentGroupId.Value;
            oldCorr.RegisterIndexId = corr.RegisterIndexId;
            oldCorr.Email = corr.Email;
            oldCorr.CorrespondentTypeId = corr.CorrespondentTypeId.Value;
            oldCorr.ContactDistrictId = corr.ContactDistrictId;
            oldCorr.ContactMunicipalityId = corr.ContactMunicipalityId;
            oldCorr.ContactSettlementId = corr.ContactSettlementId;
            oldCorr.ContactPostCode = corr.ContactPostCode;
            oldCorr.ContactAddress = corr.ContactAddress;
            oldCorr.ContactPostOfficeBox = corr.ContactPostOfficeBox;
            oldCorr.ContactPhone = corr.ContactPhone;
            oldCorr.ContactFax = corr.ContactFax;
            oldCorr.Alias = corr.Alias;
            oldCorr.IsActive = corr.IsActive;

            oldCorr.ModifyDate = DateTime.Now;
            oldCorr.ModifyUserId = this.userContext.UserId;

            foreach (CorrespondentContactDO cc in corr.CorrespondentContacts.Where(e => !e.IsNew && e.IsDeleted && e.CorrespondentContactId.HasValue))
            {
                oldCorr.DeleteCorrespondentContact(cc.CorrespondentContactId.Value, this.userContext);
            }

            foreach (var cc in corr.CorrespondentContacts.Where(e => e.IsDirty && !e.IsNew && !e.IsDeleted && e.CorrespondentContactId.HasValue))
            {
                oldCorr.UpdateCorrespondentContact(
                    cc.CorrespondentContactId.Value,
                    cc.Name,
                    cc.UIN,
                    cc.Note,
                    cc.IsActive,
                    this.userContext);
            }

            foreach (var cc in corr.CorrespondentContacts.Where(e => e.IsNew && !e.IsDeleted))
            {
                oldCorr.CreateCorrespondentContact(cc.Name, cc.UIN, cc.Note, cc.IsActive, this.userContext);
            }

            this.unitOfWork.Save();

            return Ok(new
                {
                    err = "",
                    correspondentId = oldCorr.CorrespondentId
                });
        }