Exemplo n.º 1
0
        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 InvoiceDto Convert(Invoice source, InvoiceDto destination, ResolutionContext context)
        {
            var crmSettings     = _settingsManager.Load <CrmSettings>();
            var defaultCurrency = _currencyProvider.Get(crmSettings.DefaultCurrency);

            var result = new InvoiceDto
            {
                Id           = source.ID,
                Status       = context.Mapper.Map <InvoiceStatusDto>(source.Status),
                Number       = source.Number,
                IssueDate    = _apiDateTimeHelper.Get(source.IssueDate),
                TemplateType = source.TemplateType,
                DueDate      = _apiDateTimeHelper.Get(source.DueDate),
                Currency     = !String.IsNullOrEmpty(source.Currency) ?
                               context.Mapper.Map <CurrencyInfoDto>(_currencyProvider.Get(source.Currency)) :
                               context.Mapper.Map <CurrencyInfoDto>(defaultCurrency),
                ExchangeRate        = source.ExchangeRate,
                Language            = source.Language,
                PurchaseOrderNumber = source.PurchaseOrderNumber,
                Terms       = source.Terms,
                Description = source.Description,
                FileID      = source.FileID,
                CreateOn    = _apiDateTimeHelper.Get(source.CreateOn),
                CreateBy    = _employeeWraperHelper.Get(source.CreateBy),
                CanEdit     = _crmSecurity.CanEdit(source),
                CanDelete   = _crmSecurity.CanDelete(source),
            };

            if (source.ContactID > 0)
            {
                result.Contact = context.Mapper.Map <ContactBaseWithEmailDto>(_daoFactory.GetContactDao().GetByID(source.ContactID));
            }

            if (source.ConsigneeID > 0)
            {
                result.Consignee = context.Mapper.Map <ContactBaseWithEmailDto>(_daoFactory.GetContactDao().GetByID(source.ConsigneeID));
            }

            if (source.EntityID > 0)
            {
                result.Entity = _entityDtoHelper.Get(source.EntityType, source.EntityID);
            }

            result.Cost = source.GetInvoiceCost(_daoFactory);

            result.InvoiceLines = source.GetInvoiceLines(_daoFactory).Select(x => context.Mapper.Map <InvoiceLineDto>(x)).ToList();

            return(result);
        }
        public InvoiceItemDto Convert(InvoiceItem source, InvoiceItemDto destination, ResolutionContext context)
        {
            if (destination != null)
            {
                throw new NotImplementedException();
            }

            var crmSettings     = _settingsManager.Load <CrmSettings>();
            var defaultCurrency = _currencyProvider.Get(crmSettings.DefaultCurrency);

            var result = new InvoiceItemDto
            {
                Title            = source.Title,
                StockKeepingUnit = source.StockKeepingUnit,
                Description      = source.Description,
                Price            = source.Price,
                StockQuantity    = source.StockQuantity,
                TrackInvenory    = source.TrackInventory,
                CreateOn         = _apiDateTimeHelper.Get(source.CreateOn),
                CreateBy         = _employeeWraperHelper.Get(source.CreateBy),
                Currency         = !String.IsNullOrEmpty(source.Currency) ?
                                   context.Mapper.Map <CurrencyInfoDto>(_currencyProvider.Get(source.Currency)) :
                                   context.Mapper.Map <CurrencyInfoDto>(defaultCurrency),
                CanEdit   = _crmSecurity.CanEdit(source),
                CanDelete = _crmSecurity.CanDelete(source)
            };

            if (source.InvoiceTax1ID > 0)
            {
                var invoiceTax1ID = _daoFactory.GetInvoiceTaxDao().GetByID(source.InvoiceTax1ID);

                result.InvoiceTax1 = context.Mapper.Map <InvoiceTaxDto>(invoiceTax1ID);
            }

            if (source.InvoiceTax2ID > 0)
            {
                var invoiceTax2ID = _daoFactory.GetInvoiceTaxDao().GetByID(source.InvoiceTax2ID);

                result.InvoiceTax2 = context.Mapper.Map <InvoiceTaxDto>(invoiceTax2ID);
            }

            return(result);
        }
        public InvoiceTaxDto Convert(InvoiceTax source, InvoiceTaxDto destination, ResolutionContext context)
        {
            if (destination != null)
            {
                throw new NotImplementedException();
            }

            var result = new InvoiceTaxDto();

            result.Id          = source.ID;
            result.Name        = source.Name;
            result.Description = source.Description;
            result.Rate        = source.Rate;
            result.CreateOn    = _apiDateTimeHelper.Get(source.CreateOn);
            result.CreateBy    = _employeeWraperHelper.Get(source.CreateBy);
            result.CanEdit     = _crmSecurity.CanEdit(source);
            result.CanDelete   = _crmSecurity.CanDelete(source);

            return(result);
        }
        public RelationshipEventDto Convert(RelationshipEvent source, RelationshipEventDto destination, ResolutionContext context)
        {
            var result = new RelationshipEventDto
            {
                Id       = source.ID,
                CreateBy = _employeeWraperHelper.Get(source.CreateBy),
                Created  = _apiDateTimeHelper.Get(source.CreateOn),
                Content  = source.Content,
                Files    = new List <FileWrapper <int> >(),
                CanEdit  = _crmSecurity.CanEdit(source)
            };


            var historyCategory = _daoFactory.GetListItemDao().GetByID(source.CategoryID);

            if (historyCategory != null)
            {
                result.Category = (HistoryCategoryBaseDto)context.Mapper.Map <HistoryCategoryDto>(historyCategory);
            }

            if (source.EntityID > 0)
            {
                result.Entity = _entityDtoHelper.Get(source.EntityType, source.EntityID);
            }

            result.Files = _daoFactory.GetRelationshipEventDao().GetFiles(source.ID).ConvertAll(file => _fileWrapperHelper.Get <int>(file));

            if (source.ContactID > 0)
            {
                var relativeContact = _daoFactory.GetContactDao().GetByID(source.ContactID);

                if (relativeContact != null)
                {
                    result.Contact = context.Mapper.Map <ContactBaseDto>(relativeContact);
                }
            }

            result.CanEdit = _crmSecurity.CanAccessTo(source);

            return(result);
        }
        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);
        }
Exemplo n.º 7
0
        public TaskDto Convert(Task source, TaskDto destination, ResolutionContext context)
        {
            var result = new TaskDto
            {
                Title       = source.Title,
                Description = source.Description,
                DeadLine    = _apiDateTimeHelper.Get(source.DeadLine),
                Responsible = _employeeWraperHelper.Get(source.ResponsibleID),
                IsClosed    = source.IsClosed,
                AlertValue  = source.AlertValue,
                Created     = _apiDateTimeHelper.Get(source.CreateOn)
            };

            if (source.CategoryID > 0)
            {
                var categoryItem = _daoFactory.GetListItemDao().GetByID(source.CategoryID);

                result.Category = new TaskCategoryDto(categoryItem)
                {
                    RelativeItemsCount = _daoFactory.GetListItemDao().GetRelativeItemsCount(ListType.TaskCategory, categoryItem.ID)
                };
            }

            if (source.ContactID > 0)
            {
                result.Contact = context.Mapper.Map <ContactBaseWithEmailDto>(_daoFactory.GetContactDao().GetByID(source.ContactID));
            }

            if (source.EntityID > 0)
            {
                result.Entity = _entityDtoHelper.Get(source.EntityType, source.EntityID);
            }

            result.CanEdit = _crmSecurity.CanEdit(source);

            return(result);
        }
        public async System.Threading.Tasks.Task Invoke(HttpContext context,
                                                        SetupInfo setupInfo,
                                                        CrmSecurity crmSecurity,
                                                        FileSizeComment fileSizeComment,
                                                        WebItemSecurity webItemSecurity,
                                                        MessageTarget messageTarget,
                                                        MessageService messageService,
                                                        DaoFactory daoFactory,
                                                        ContactPhotoManager contactPhotoManager)
        {
            if (!webItemSecurity.IsAvailableForMe(ProductEntryPoint.ID))
            {
                throw crmSecurity.CreateSecurityException();
            }

            context.Request.EnableBuffering();

            var contactId = Convert.ToInt32(context.Request.Form["contactID"]);

            Contact contact = null;

            if (contactId != 0)
            {
                contact = daoFactory.GetContactDao().GetByID(contactId);

                if (!crmSecurity.CanEdit(contact))
                {
                    throw crmSecurity.CreateSecurityException();
                }
            }

            var fileUploadResult = new FileUploadResult();

            if (context.Request.Form.Files.Count == 0)
            {
                await context.Response.WriteAsync(JsonSerializer.Serialize(fileUploadResult));
            }

            var fileName      = context.Request.Form.Files[0].FileName;
            var contentLength = context.Request.Form.Files[0].Length;

            if (String.IsNullOrEmpty(fileName) || contentLength == 0)
            {
                throw new InvalidOperationException(CRMErrorsResource.InvalidFile);
            }

            if (0 < setupInfo.MaxImageUploadSize && setupInfo.MaxImageUploadSize < contentLength)
            {
                fileUploadResult.Success = false;
                fileUploadResult.Message = fileSizeComment.GetFileImageSizeNote(CRMCommonResource.ErrorMessage_UploadFileSize, false).HtmlEncode();

                await context.Response.WriteAsync(JsonSerializer.Serialize(fileUploadResult));
            }

            if (FileUtility.GetFileTypeByFileName(fileName) != FileType.Image)
            {
                fileUploadResult.Success = false;
                fileUploadResult.Message = CRMJSResource.ErrorMessage_NotImageSupportFormat.HtmlEncode();

                await context.Response.WriteAsync(JsonSerializer.Serialize(fileUploadResult));
            }

            var uploadOnly = Convert.ToBoolean(context.Request.Form["uploadOnly"]);
            var tmpDirName = Convert.ToString(context.Request.Form["tmpDirName"]);

            try
            {
                ContactPhotoManager.PhotoData photoData;
                if (contactId != 0)
                {
                    photoData = contactPhotoManager.UploadPhoto(context.Request.Form.Files[0].OpenReadStream(), contactId, uploadOnly);
                }
                else
                {
                    if (String.IsNullOrEmpty(tmpDirName) || tmpDirName == "null")
                    {
                        tmpDirName = Guid.NewGuid().ToString();
                    }
                    photoData = contactPhotoManager.UploadPhotoToTemp(context.Request.Form.Files[0].OpenReadStream(), tmpDirName);
                }

                fileUploadResult.Success = true;
                fileUploadResult.Data    = photoData;
            }
            catch (Exception e)
            {
                fileUploadResult.Success = false;
                fileUploadResult.Message = e.Message.HtmlEncode();

                await context.Response.WriteAsync(JsonSerializer.Serialize(fileUploadResult));
            }

            if (contact != null)
            {
                var messageAction = contact is Company ? MessageAction.CompanyUpdatedPhoto : MessageAction.PersonUpdatedPhoto;

                messageService.Send(messageAction, messageTarget.Create(contact.ID), contact.GetTitle());
            }

            await context.Response.WriteAsync(JsonSerializer.Serialize(fileUploadResult));
        }
Exemplo n.º 9
0
        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);
        }