public CasesDto Convert(Cases source, CasesDto destination, ResolutionContext context) { if (destination != null) { throw new NotImplementedException(); } var result = new CasesDto(); result.Title = source.Title; result.IsClosed = source.IsClosed; result.IsPrivate = _CRMSecurity.IsPrivate(source); result.Created = _apiDateTimeHelper.Get(source.CreateOn); result.CreateBy = _employeeWraperHelper.Get(source.CreateBy); result.CanEdit = _CRMSecurity.CanEdit(source); if (result.IsPrivate) { result.AccessList = _CRMSecurity.GetAccessSubjectTo(source) .SkipWhile(item => item.Key == Constants.GroupEveryone.ID) .Select(item => _employeeWraperHelper.Get(item.Key)); } result.CustomFields = _daoFactory .GetCustomFieldDao() .GetEnityFields(EntityType.Case, source.ID, false) .ConvertAll(item => context.Mapper.Map <CustomFieldBaseDto>(item)); result.Members = new List <ContactBaseDto>(); var memberIDs = _daoFactory.GetCasesDao().GetMembers(source.ID); var membersList = _daoFactory.GetContactDao().GetContacts(memberIDs); var membersDtoList = new List <ContactBaseDto>(); foreach (var member in membersList) { if (member == null) { continue; } membersDtoList.Add(context.Mapper.Map <ContactBaseDto>(member)); } result.Members = membersDtoList; return(destination); }
public ContactBaseDto Convert(Contact source, ContactBaseDto destination, ResolutionContext context) { ContactBaseDto result; if (source is Company) { result = new CompanyDto(); } else { result = new PersonDto(); } result.Id = source.ID; result.DisplayName = source.GetTitle(); result.IsPrivate = _crmSecurity.IsPrivate(source); result.IsShared = source.ShareType == ShareType.ReadWrite || source.ShareType == ShareType.Read; result.ShareType = source.ShareType; result.Currency = !String.IsNullOrEmpty(source.Currency) ? context.Mapper.Map <CurrencyInfoDto>(_currencyProvider.Get(source.Currency)) : null; result.SmallFotoUrl = String.Format("{0}HttpHandlers/filehandler.ashx?action=contactphotoulr&cid={1}&isc={2}&ps=1", _pathProvider.BaseAbsolutePath, source.ID, source is Company).ToLower(); result.MediumFotoUrl = String.Format("{0}HttpHandlers/filehandler.ashx?action=contactphotoulr&cid={1}&isc={2}&ps=2", _pathProvider.BaseAbsolutePath, source.ID, source is Company).ToLower(); result.IsCompany = source is Company; result.CanEdit = _crmSecurity.CanEdit(source); result.CanDelete = _crmSecurity.CanDelete(source); if (result.IsPrivate) { result.AccessList = _crmSecurity.GetAccessSubjectTo(source) .Select(item => _employeeDtoHelper.Get(item.Key)); } return(result); }
public OpportunityDto Convert(Deal source, OpportunityDto destination, ResolutionContext context) { var dealDto = new OpportunityDto { Id = source.ID, CreateBy = _employeeWraperHelper.Get(source.CreateBy), Created = _apiDateTimeHelper.Get(source.CreateOn), Title = source.Title, Description = source.Description, Responsible = _employeeWraperHelper.Get(source.ResponsibleID), BidType = source.BidType, BidValue = source.BidValue, PerPeriodValue = source.PerPeriodValue, SuccessProbability = source.DealMilestoneProbability, ActualCloseDate = _apiDateTimeHelper.Get(source.ActualCloseDate), ExpectedCloseDate = _apiDateTimeHelper.Get(source.ExpectedCloseDate), CanEdit = _crmSecurity.CanEdit(source) }; if (source.ContactID > 0) { dealDto.Contact = context.Mapper.Map <ContactBaseDto>(_daoFactory.GetContactDao().GetByID(source.ContactID)); } if (source.DealMilestoneID > 0) { var dealMilestone = _daoFactory.GetDealMilestoneDao().GetByID(source.DealMilestoneID); if (dealMilestone == null) { throw new ItemNotFoundException(); } dealDto.Stage = new DealMilestoneBaseDto(dealMilestone); } dealDto.AccessList = _crmSecurity.GetAccessSubjectTo(source) .Select(item => _employeeWraperHelper.Get(item.Key)); dealDto.IsPrivate = _crmSecurity.IsPrivate(source); if (!string.IsNullOrEmpty(source.BidCurrency)) { dealDto.BidCurrency = context.Mapper.Map <CurrencyInfoDto>(_currencyProvider.Get(source.BidCurrency)); } dealDto.CustomFields = _daoFactory.GetCustomFieldDao().GetEnityFields(EntityType.Opportunity, source.ID, false).ConvertAll(item => context.Mapper.Map <CustomFieldBaseDto>(item)); dealDto.Members = new List <ContactBaseDto>(); var memberIDs = _daoFactory.GetDealDao().GetMembers(source.ID); var membersList = _daoFactory.GetContactDao().GetContacts(memberIDs); var membersDtoList = new List <ContactBaseDto>(); foreach (var member in membersList) { if (member == null) { continue; } membersDtoList.Add(context.Mapper.Map <ContactBaseDto>(member)); } dealDto.Members = membersDtoList; return(dealDto); }