Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="proposal"></param>
        /// <param name="audienceChannel">Si se le pasa un audienceChannel este se usara para setear price and productName, sino se consultara uno a la BD</param>
        /// <param name=""></param>
        /// <returns></returns>
        private ProposalReviewListItemViewModel MapToProposalReviewListItemViewModel(ProposalDocument proposal, AudienceChannelDocument audienceChannel = null)
        {
            if (audienceChannel == null)
            {
                audienceChannel = _audienceChannelManager.GetAudienceChannelById(proposal.AudienceChannelId);
            }


            AdvertiserProfileDocument advertiserProfile = _advertiserProfileManager.FindProfileByProfileId(proposal.AdvertiserProfileId);
            ApplicationUser           user    = _identityManager.FindUserByUserId(advertiserProfile.UserId);
            CountryDocument           country = _catalogManager.FindCountryById(advertiserProfile.CountryBusinessInId);


            DateTime registerProposal = Convert.ToDateTime(proposal.RegisterDate);

            string messageDaysAgo = DateUtils.GetTextDaysAgo(registerProposal);


            return(new ProposalReviewListItemViewModel()
            {
                TimeAgoReceived = messageDaysAgo,
                AdvertiserImageSrc = advertiserProfile.IconUrl,
                AdvertiserName = user.Name,
                IdProposal = proposal.Id,
                Location = country != null?country.Name:"",
                Price = audienceChannel.Price.ToString() + " kind",
                ProductName = audienceChannel.Name
            });
        }
Exemple #2
0
        public ProposalDocument FindProposalById(string proposalId)
        {
            string           query    = $"SELECT * FROM {CosmosCollections.Proposal.ToString()} WHERE {CosmosCollections.Proposal.ToString()}.id='{proposalId}'";
            ProposalDocument proposal = context.ExecuteQuery <ProposalDocument>(databaseName, CosmosCollections.Proposal.ToString(), query).SingleOrDefault();

            return(proposal);
        }
 public ProposalViewModel()
 {
     audience           = new AudienceDocument();
     audienceChannel    = new AudienceChannelDocument();
     providerImageClass = string.Empty;
     proposal           = new ProposalDocument();
     listQuestion       = new List <ProposalQuestionViewModel>();
 }
        public virtual void DeleteDocument(string proposalId, string docId)
        {
            Proposal         proposal   = proposalService.GetById(proposalId);
            ProposalDocument currentDoc = proposal.ProposalDocuments.FirstOrDefault(d => d.Id == docId);

            proposal.ProposalDocuments.Remove(currentDoc);
            proposalService.Save();
        }
Exemple #5
0
        public ProposalDocument AcceptProposal(string proposalId, double price)
        {
            ProposalDocument vproposal = FindProposalById(proposalId);

            vproposal.AcceptedByPublisher = true;
            vproposal.Price = price;
            context.UpsertDocument <ProposalDocument>(databaseName, CosmosCollections.Proposal.ToString(), vproposal);
            return(vproposal);
        }
Exemple #6
0
        public PublisherProposalDetailViewModel RejectProposal(PublisherProposalDetailViewModel proposal)
        {
            ProposalDocument proposalInBD = FindProposalById(proposal.ProposalId);

            proposalInBD.RegisterDate        = proposalInBD.GetMexicanTime();
            proposalInBD.RejectDetail        = proposal.RejectDetail;
            proposalInBD.AcceptedByPublisher = false;
            context.UpsertDocument <ProposalDocument>(databaseName, CosmosCollections.Proposal.ToString(), proposalInBD);
            return(FindPublisherProposalDetailVMById(proposal.ProposalId));
        }
Exemple #7
0
        private void ProposalConfig(ReportHelper.ReportConfig config, string projectUId, string proposalUId)
        {
            var proposal = proposalService.GetProjectProposal(projectUId, proposalUId);

            if (proposal.ProposalStatus != (short)ProposalStatus.PROPOSAL_WAITING)
            {
                ProposalDocument document = proposalService.GetProposalDocument(projectUId, proposalUId);
                config.StaticXAMLReport = document.ProposalXAML;
                return;
            }

            // proposta
            config.ReportObjects.Add(proposal);

            // calcs the work days
            int dayCount = calendar.CalcWorkDayCount(proposal.EstimatedStartDate, proposal.EstimatedEndDate);

            config.ReportVars.Add("workDaysCount", dayCount.ToString());

            // currency rate
            if (proposal.CurrencyRate == null)
            {
                proposal.CurrencyRate = 1;
            }

            // hourscosts
            var hourCosts = proposalService.GetHourCosts(projectUId);

            config.ReportObjects.Add(hourCosts);

            // creates proposal items with price
            List <ProposalItemWithPrice> itemsWithValue = new List <ProposalItemWithPrice>();
            ICollection <BacklogItem>    items          = backlogService.GetCurrentBacklog(projectUId, (short)ScrumFactory.Services.BacklogFiltersMode.ALL);

            foreach (var item in proposal.Items)
            {
                var itemB = items.SingleOrDefault(i => i.BacklogItemUId == item.BacklogItemUId);
                if (itemB != null)
                {
                    var price = proposal.CalcItemPrice(itemB, hourCosts);
                    itemsWithValue.Add(new ProposalItemWithPrice(proposal.ProposalUId, itemB, price));
                }
            }
            config.ReportObjects.Add(itemsWithValue);


            // proposal length
            config.ReportVars.Add("ProposalMonthLength", MonthDiff(proposal.EstimatedStartDate, proposal.EstimatedEndDate).ToString());
        }
        private void RunRules(DbEntityEntry ent)
        {
            ProposalDocument pDoc = (ProposalDocument)ent.Entity;

            if (pDoc.Url.LastIndexOf(".") < 0)
            {
                pDoc.Type = "file";
                return;
            }
            pDoc.Type = pDoc.Url.Substring(pDoc.Url.LastIndexOf(".") + 1, pDoc.Url.Length - pDoc.Url.LastIndexOf(".") - 1).ToLower();
            if (pDoc.Type == "docx")
            {
                pDoc.Type = "doc";
            }
            if (pDoc.Type != "doc" && pDoc.Type != "pdf")
            {
                pDoc.Type = "file";
            }
        }
        public virtual ProposalDTO Save([FromBody] ProposalDTO model)
        {
            Proposal proposal = string.IsNullOrEmpty(model.Id) ? new Proposal() : proposalService.GetById(model.Id);
            var      mapper   = new MapperConfiguration(cfg => { cfg.CreateMap <ProposalDTO, Proposal>().ForMember(m => m.ProposalDocuments, p => p.UseValue <List <ProposalDocument> >(null));
                                                                 cfg.CreateMap <InstitutionDTO, Institution>();
                                                                 cfg.CreateMap <ProposalDocumentDTO, ProposalDocument>(); }).CreateMapper();

            mapper.Map(model, proposal);
            proposal.Institution = this.institutionService.GetById(proposal.Institution.Id);


            if (string.IsNullOrEmpty(proposal.Id))
            {
                proposal.Id = string.IsNullOrEmpty(proposal.Id) ? Guid.NewGuid().ToString() : proposal.Id;
                proposalService.Add(proposal);
            }
            if (model.ProposalDocuments != null)
            {
                foreach (ProposalDocumentDTO doc in model.ProposalDocuments)
                {
                    ProposalDocument targetDoc = null;
                    if (!string.IsNullOrEmpty(doc.Id))
                    {
                        targetDoc = proposal.ProposalDocuments.FirstOrDefault(d => d.Id == doc.Id);
                    }
                    else
                    {
                        targetDoc = new ProposalDocument();
                    }

                    mapper.Map <ProposalDocumentDTO, ProposalDocument>(doc, targetDoc);
                    proposal.ProposalDocuments.Add(targetDoc);
                }
                proposal.ProposalDocuments.ForEach(d => { d.Id = string.IsNullOrEmpty(d.Id) ? Guid.NewGuid().ToString() : d.Id; });
            }
            proposalService.Save();
            mapper = new MapperConfiguration(cfg => { cfg.CreateMap <Proposal, ProposalDTO>();
                                                      cfg.CreateMap <Institution, InstitutionDTO>();
                                                      cfg.CreateMap <ProposalDocument, ProposalDocumentDTO>(); }).CreateMapper();
            return(mapper.Map <ProposalDTO>(proposal));
        }
Exemple #10
0
        public PublisherProposalDetailViewModel FindPublisherProposalDetailVMById(string proposalId)
        {
            ProposalDocument          proposal        = FindProposalById(proposalId);
            AdvertiserProfileDocument advertiser      = _advertiserProfileManager.FindProfileByProfileId(proposal.AdvertiserProfileId);
            AudienceChannelDocument   audienceChannel = GetAudienceChannelById(proposal.AudienceChannelId);
            string          audienceUrl = getAudienceUrlSite(audienceChannel.AudienceId);
            CountryDocument country     = _catalogManager.FindCountryById(advertiser.CountryBusinessInId);

            return(new PublisherProposalDetailViewModel
            {
                Accepted = proposal.AcceptedByPublisher,
                AdvertiserImage = advertiser.IconUrl,
                AdvertiserLocation = country.Name,
                AdvertiserName = advertiser.Title,
                ProposalId = proposal.Id,
                QuestionsAndAnswers = proposal.Questions,
                RejectDetail = proposal.RejectDetail,
                WebSite = audienceUrl,
                MemberSinceYear = advertiser.RegisterDate,
                Price = proposal.Price
            });
        }
Exemple #11
0
        private async Task <ProposalDocument> ProposalDocumentToEntityAsync(OpportunityViewModel viewModel, ProposalDocument proposalDocument, string requestId = "")
        {
            try
            {
                Guard.Against.Null(proposalDocument, "ProposalDocumentToEntityAsync", requestId);
                var entity = proposalDocument;
                var model  = viewModel.ProposalDocument;

                entity.Id          = model.Id ?? String.Empty;
                entity.DisplayName = model.DisplayName ?? String.Empty;
                entity.Reference   = model.Reference ?? String.Empty;
                entity.Version     = model.Version ?? String.Empty;

                if (entity.Content == null)
                {
                    entity.Content = ProposalDocumentContent.Empty;
                }


                // Storing previous section lists to compare and trigger notification if assigment changes
                var currProposalSectionList = entity.Content.ProposalSectionList.ToList();

                // Proposal sections are always overwritten
                entity.Content.ProposalSectionList = new List <DocumentSection>();

                if (model.Content.ProposalSectionList != null)
                {
                    var OwnerSendList      = new List <UserProfile>(); //receipients list for notifications
                    var AssignedToSendList = new List <UserProfile>(); //receipients list for notifications
                    // LIST: ProposalSectionList
                    foreach (var item in model.Content.ProposalSectionList)
                    {
                        var documentSection = new DocumentSection();
                        documentSection.DisplayName          = item.DisplayName ?? String.Empty;
                        documentSection.Id                   = item.Id ?? String.Empty;
                        documentSection.LastModifiedDateTime = item.LastModifiedDateTime;
                        documentSection.Owner                = await _userProfileHelpers.UserProfileToEntityAsync(item.Owner ?? new UserProfileViewModel(), requestId);

                        documentSection.SectionStatus = ActionStatus.FromValue(item.SectionStatus.Value);
                        documentSection.SubSectionId  = item.SubSectionId ?? String.Empty;
                        documentSection.AssignedTo    = await _userProfileHelpers.UserProfileToEntityAsync(item.AssignedTo ?? new UserProfileViewModel(), requestId);

                        documentSection.Task = item.Task ?? String.Empty;

                        // Check values to see if notification trigger is needed
                        var prevSectionList = currProposalSectionList.Find(x => x.Id == documentSection.Id);
                        if (prevSectionList != null)
                        {
                            if (prevSectionList.Owner.Id != documentSection.Owner.Id)
                            {
                                OwnerSendList.Add(documentSection.Owner);
                            }

                            if (prevSectionList.AssignedTo.Id != documentSection.AssignedTo.Id)
                            {
                                AssignedToSendList.Add(documentSection.AssignedTo);
                            }
                        }

                        entity.Content.ProposalSectionList.Add(documentSection);
                    }

                    // AssignedToSendList notifications
                    // Section owner changed / assigned
                    try
                    {
                        if (OwnerSendList.Count > 0)
                        {
                            _logger.LogInformation($"RequestId: {requestId} - ProposalDocumentToEntityAsync sendNotificationCardAsync for owner changed notification.");
                            var notificationOwner = await _cardNotificationService.sendNotificationCardAsync(
                                viewModel.DisplayName,
                                viewModel.OpportunityChannelId,
                                OwnerSendList,
                                $"Section(s) in the proposal document for opportunity {viewModel.DisplayName} has new/updated owners ",
                                requestId);
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"RequestId: {requestId} - ProposalDocumentToEntityAsync sendNotificationCardAsync for owner error: {ex}");
                    }

                    // Section AssignedTo changed / assigned
                    try
                    {
                        if (AssignedToSendList.Count > 0)
                        {
                            _logger.LogInformation($"RequestId: {requestId} - ProposalDocumentToEntityAsync sendNotificationCardAsync for AssigedTo changed notification.");
                            var notificationAssignedTo = await _cardNotificationService.sendNotificationCardAsync(
                                viewModel.DisplayName,
                                viewModel.OpportunityChannelId,
                                AssignedToSendList,
                                $"Task(s) in the proposal document for opportunity {viewModel.DisplayName} has new/updated assigments ",
                                requestId);
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"RequestId: {requestId} - ProposalDocumentToEntityAsync sendNotificationCardAsync for AssignedTo error: {ex}");
                    }
                }


                // Metadata
                if (entity.Metadata == null)
                {
                    entity.Metadata = DocumentMetadata.Empty;
                }

                entity.Metadata.DocumentUri = model.DocumentUri;
                entity.Metadata.Tags        = model.Tags;
                if (entity.Metadata.Category == null)
                {
                    entity.Metadata.Category = new Category();
                }

                entity.Metadata.Category.Id   = model.Category.Id ?? String.Empty;
                entity.Metadata.Category.Name = model.Category.Name ?? String.Empty;

                if (entity.Metadata.Notes == null)
                {
                    entity.Metadata.Notes = new List <Note>();
                }

                if (model.Notes != null)
                {
                    // LIST: Notes
                    foreach (var item in model.Notes)
                    {
                        entity.Metadata.Notes.Add(await NoteToEntityAsync(item, requestId));
                    }
                }

                return(entity);
            }
            catch (Exception ex)
            {
                //_logger.LogError(ex.Message);
                throw ex;
            }
        }