public InsertOpportunityBuyerResponse InsertOpportunityBuyer(InsertOpportunityBuyerRequest request) { InsertOpportunityBuyerResponse response = new InsertOpportunityBuyerResponse(); List <OpportunityContactMapTableType> opportunityBuyers = new List <OpportunityContactMapTableType>(); foreach (int contactid in request.opportunityViewModel.Contacts.Select(c => c.Id)) { OpportunityContactMapTableType oppBuyerTableType = new OpportunityContactMapTableType(); oppBuyerTableType.OpportunityContactMapID = 0; oppBuyerTableType.OpportunityID = request.opportunityViewModel.OpportunityID; oppBuyerTableType.ContactID = contactid; oppBuyerTableType.Potential = request.opportunityViewModel.Potential; oppBuyerTableType.ExpectedToClose = request.opportunityViewModel.ExpectedCloseDate; oppBuyerTableType.Comments = request.opportunityViewModel.Comments; oppBuyerTableType.Owner = request.opportunityViewModel.OwnerId; oppBuyerTableType.StageID = request.opportunityViewModel.StageID; oppBuyerTableType.CreatedOn = DateTime.Now.ToUniversalTime(); oppBuyerTableType.CreatedBy = request.RequestedBy.Value; opportunityBuyers.Add(oppBuyerTableType); this.addToTopic(request.opportunityViewModel.OpportunityID, request.opportunityViewModel.AccountID, new List <int>() { contactid }, request.opportunityViewModel.StageID); } if (request.RequestedBy != request.opportunityViewModel.OwnerId) { Notification notificationdata = new Notification(); notificationdata.Details = "[|An opportunity has been assigned to you.|]"; notificationdata.EntityId = request.opportunityViewModel.OpportunityID; notificationdata.Subject = "[|An opportunity has been assigned to you.|]"; notificationdata.Time = DateTime.Now.ToUniversalTime(); notificationdata.Status = NotificationStatus.New; notificationdata.UserID = request.opportunityViewModel.OwnerId; notificationdata.ModuleID = request.ModuleID; userRepository.AddNotification(notificationdata); } IEnumerable <OpportunityContactMapTableType> buyers = opportunityBuyers.ToList(); opportunityRepository.InsertAndUpdateOpportunityBuyers(buyers); Opportunity updatedOpportunity = opportunityRepository.FindBy(request.opportunityViewModel.OpportunityID); if (indexingService.Update <Opportunity>(updatedOpportunity) > 0) { Logger.Current.Verbose("Opportunity updated to elasticsearch successfully"); } return(response); }
public HttpResponseMessage InsertBuyer(OpportunityViewModel viewModel) { viewModel.CreatedOn = DateTime.Now.ToUniversalTime(); viewModel.CreatedBy = this.UserId; if (viewModel.ExpectedCloseDate.HasValue) { viewModel.ExpectedCloseDate = viewModel.ExpectedCloseDate.Value.ToUniversalTime().Date; } InsertOpportunityBuyerResponse response = opportunityService.InsertOpportunityBuyer( new InsertOpportunityBuyerRequest() { RequestedBy = this.UserId, opportunityViewModel = viewModel, AccountId = this.AccountId, RoleId = this.RoleId, ModuleID = (byte)AppModules.Opportunity }); return(Request.BuildResponse(response)); }