protected void MapEmailNotificationObject(CostNotificationObject obj, Cost cost, CostUser costOwner, CostUser costApprover = null)
        {
            var users = new CostNotificationUsers
            {
                CostOwner = costOwner,
                Approver  = costApprover
            };

            MapEmailNotificationObject(obj, cost, users);
        }
        private void AssignApproverType(EmailNotificationMessage <CostNotificationObject> message, CostUser approvalCostUser = null)
        {
            CostNotificationObject obj = message.Object;

            if (message.Type == core.Constants.EmailNotificationActionType.TechnicalApproverAssigned)
            {
                //IPM should be default
                obj.Approver.Type = (approvalCostUser?.UserBusinessRoles == null ||
                                     approvalCostUser.UserBusinessRoles.Any(br => br.BusinessRole != null && br.BusinessRole.Key == Constants.BusinessRole.Ipm))
                        ? core.Constants.EmailApprovalType.IPM
                        : core.Constants.EmailApprovalType.CC;
            }
            if (message.Type == core.Constants.EmailNotificationActionType.BrandApproverAssigned)
            {
                obj.Approver.Type = core.Constants.EmailApprovalType.Brand;
            }
        }
        protected void MapEmailNotificationObject(CostNotificationObject obj, Cost cost, CostNotificationUsers users)
        {
            dataAccess.Entity.Project project = cost.Project;

            obj.Agency = Mapper.Map <core.Models.Notifications.Agency>(users.CostOwner.Agency);
            Mapper.Map(users.CostOwner.Agency.Country, obj.Agency);

            obj.Brand = Mapper.Map <core.Models.Notifications.Brand>(project.Brand);

            obj.Cost = Mapper.Map <core.Models.Notifications.Cost>(cost);
            Mapper.Map(cost.LatestCostStageRevision.CostStage, obj.Cost);
            Mapper.Map(users.CostOwner, obj.Cost);

            obj.Project = Mapper.Map <core.Models.Notifications.Project>(project);

            if (users.Approver != null)
            {
                obj.Approver = Mapper.Map <Approver>(users.Approver);
            }
        }
        protected void PopulateOtherFields(EmailNotificationMessage <CostNotificationObject> message, string parent, DateTime timestamp, Guid costId, Guid costStageRevisionId, CostUser approvalCostUser = null)
        {
            message.Timestamp = timestamp;

            CostNotificationObject obj = message.Object;

            core.Models.Notifications.Cost cost = obj.Cost;

            PgStageDetailsForm stageForm = CostStageRevisionService.GetStageDetails <PgStageDetailsForm>(costStageRevisionId).Result;

            cost.Title = stageForm.Title;
            switch (cost.CostType)
            {
            case core.Models.CostTemplate.CostType.Production:
                cost.ProductionType = stageForm.ProductionType?.Key;
                cost.ContentType    = stageForm.ContentType.Key;
                break;

            case core.Models.CostTemplate.CostType.Buyout:
                cost.ProductionType = stageForm.UsageBuyoutType.Key;
                cost.ContentType    = stageForm.UsageType?.Key;
                break;
            }

            cost.Url = _uriHelper.GetLink(ApplicationUriName.CostRevisionReview, costStageRevisionId.ToString(), costId.ToString());

            AssignApproverType(message, approvalCostUser);

            if (!string.IsNullOrEmpty(parent))
            {
                obj.Parents.Add(parent);
            }
            if (!string.IsNullOrEmpty(AppSettings.EnvironmentEmailSubjectPrefix))
            {
                obj.EnvironmentEmailSubjectPrefix = AppSettings.EnvironmentEmailSubjectPrefix;
            }
        }
        protected async Task PopulateMetadata(CostNotificationObject obj, Guid costId)
        {
            var metadataItems = await MetadataProviderService.Provide(costId);

            metadataItems?.ForEach(item => obj.Metadata.Add(item));
        }