public void UpdateOpportunity(OpportunityDto dto) { var existingUpportunity = new Opportunity(); //you'll need some database query logic here MapProperties(dto, existingUpportunity); //Add save/update logic }
public void SaveOpportunity(OpportunityDto opportunityDto) { var opportunity = _mapper.Map <Opportunity>(opportunityDto); _context.Opportunities.Add(opportunity); _context.SaveChanges(); }
public void CreateOpportunity(OpportunityDto dto) { var newOpportunity = new Opportunity(); //You'll need some database logic here MapProperties(dto, newOpportunity); //Add save/create logic }
internal IFacadeUpdateResult <OpportunityData> SaveOpportunity(OpportunityDto dto) { ArgumentValidator.IsNotNull("dto", dto); FacadeUpdateResult <OpportunityData> result = new FacadeUpdateResult <OpportunityData>(); IOpportunityService service = UnitOfWork.GetService <IOpportunityService>(); Opportunity instance = RetrieveOrNew <OpportunityData, Opportunity, IOpportunityService>(result.ValidationResult, dto.Id); if (result.IsSuccessful) { instance.Name = dto.Name; instance.Description = dto.Description; instance.ContactId = dto.ContactId; instance.CustomerId = dto.CustomerId; instance.ProductId = dto.ProductId; instance.EstimateAmount = dto.EstimateAmount; var saveQuery = service.Save(instance); result.AttachResult(instance.RetrieveData <OpportunityData>()); result.Merge(saveQuery); } return(result); }
public void MapProperties(OpportunityDto dto, Opportunity target) { //Mapper.Map<OpportunityDto, Opportunity>(dto, target); //Or manually : target.Title = dto.Title; target.Location = dto.Location; target.StartDate = dto.StartDate; }
public async Task <int> CreateOpportunityAsync(OpportunityDto dto) { dto.Id = 0; var opportunity = _mapper.Map <Opportunity>(dto); var opportunityId = await _opportunityRepository.CreateAsync(opportunity); return(opportunityId); }
public int AddOpportunity(OpportunityDto opportunityDto) { bool manageOpportunitiesInCRM = false; ClientLoginDto dto = new ClientLoginDL().ManageOpportunitiesInCRM(opportunityDto.ClientID); if (dto.ManageOppysInCRM) { manageOpportunitiesInCRM = dto.ManageOppysInCRM; } return(new OpportunityDL().AddOpportunity(opportunityDto, manageOpportunitiesInCRM)); }
public void MapProperties(OpportunityDto dto, Opportunity target) { Mapper.CreateMap <OpportunityDto, Opportunity>() .ForAllMembers(opt => opt.Condition(srs => !srs.IsSourceValueNull)); Mapper.Map <OpportunityDto, Opportunity>(dto, target); target.Startdate = dto.StartDate; //Insert more logic & mumbo jumbo here //Or manually : //target.Title = dto.Title; //target.Location = dto.Location; //target.StartDate = dto.StartDate; }
public When_Opportunity_Is_Created(OpportunityTestFixture testFixture) { _testFixture = testFixture; _testFixture.ResetData(EmployerContact); var opportunityDto = new OpportunityDto { EmployerCrmId = new Guid("11111111-1111-1111-1111-111111111111"), PrimaryContact = EmployerContact }; _opportunityId = _testFixture.OpportunityService.CreateOpportunityAsync(opportunityDto).GetAwaiter().GetResult(); }
public When_OpportunityService_Is_Called_To_Create_Opportunity() { var httpContextAccessor = Substitute.For <IHttpContextAccessor>(); httpContextAccessor.HttpContext.Returns(new DefaultHttpContext { User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.GivenName, "adminUserName") })) }); var config = new MapperConfiguration(c => { c.AddMaps(typeof(OpportunityMapper).Assembly); c.ConstructServicesUsing(type => type.Name.Contains("LoggedInUserEmailResolver") ? new LoggedInUserEmailResolver <OpportunityDto, Domain.Models.Opportunity>(httpContextAccessor) : type.Name.Contains("LoggedInUserNameResolver") ? (object)new LoggedInUserNameResolver <OpportunityDto, Domain.Models.Opportunity>(httpContextAccessor) : type.Name.Contains("UtcNowResolver") ? new UtcNowResolver <OpportunityDto, Domain.Models.Opportunity>(new DateTimeProvider()) : null); }); var mapper = new Mapper(config); _opportunityRepository = Substitute.For <IOpportunityRepository>(); var opportunityItemRepository = Substitute.For <IRepository <OpportunityItem> >(); var provisionGapRepository = Substitute.For <IRepository <ProvisionGap> >(); var referralRepository = Substitute.For <IRepository <Domain.Models.Referral> >(); var googleMapApiClient = Substitute.For <IGoogleMapApiClient>(); var opportunityPipelineReportWriter = Substitute.For <IFileWriter <OpportunityReportDto> >(); var dateTimeProvider = Substitute.For <IDateTimeProvider>(); _opportunityRepository.CreateAsync(Arg.Any <Domain.Models.Opportunity>()) .Returns(OpportunityId); var opportunityService = new OpportunityService(mapper, _opportunityRepository, opportunityItemRepository, provisionGapRepository, referralRepository, googleMapApiClient, opportunityPipelineReportWriter, dateTimeProvider); var dto = new OpportunityDto { EmployerCrmId = new Guid("11111111-1111-1111-1111-111111111111"), PrimaryContact = "Employer contact", Email = "*****@*****.**", Phone = "020 123 4567" }; _result = opportunityService.CreateOpportunityAsync(dto).GetAwaiter().GetResult(); }
private void CreateOpportunities(IServiceProvider serviceProvider) { string[] opportunities = { "PPA", "Produto Digital", "Analytics", "BPM" }; foreach (var opportunity in opportunities) { var opportunityService = serviceProvider.GetRequiredService <IOpportunityService>(); if (opportunityService.OpportunityExists(opportunity)) { continue; } var opportunityDto = new OpportunityDto(opportunity); opportunityService.SaveOpportunity(opportunityDto); } }
/// <summary> /// Get an opportunity by CRMOppID /// </summary> /// <param name="clientID">The ClientID</param> /// <param name="value">The value.</param> /// <param name="searchType">Type of the search.</param> /// <returns></returns> public Response GetOpportunityByClientIDAndSearchType(int clientID, string value, string searchType) { var response = new Response(); var opportunityBL = new OpportunityBL(); OpportunityDto opportunity = null; // Get the opportunity data switch (searchType.ToUpper()) { case "CRMOPPID": opportunity = opportunityBL.GetNonDeletedOpportunityByClientIDAndCRMOppID(clientID, value); break; case "QUOTEID": opportunity = opportunityBL.GetNonDeletedOpportunityByClientIDAndQuoteID(clientID, value); break; case "OPPID": int oppId; if (int.TryParse(value, out oppId)) { opportunity = opportunityBL.GetNonDeletedOpportunityByClientIDAndOppID(clientID, oppId); } break; } if (opportunity != null) { response.Results.Add("Success"); // Serialize the object string userSerialize = JsonConvert.SerializeObject(opportunity); response.Results.Add(userSerialize); } else { response.Results.Add("Error"); response.Errors.Add("Invalid opportunity data."); } return(response); }
/// <summary> /// Sets the property. /// </summary> /// <param name="opportunity">The opportunity object.</param> /// <param name="propertyInfo">The property info.</param> /// <param name="value">The value.</param> public void SetProperty(OpportunityDto opportunity, PropertyInfo propertyInfo, object value) { string name; if (propertyInfo.PropertyType.IsGenericType) { var args = propertyInfo.PropertyType.GetGenericArguments(); name = args[0].Name; } else { name = propertyInfo.PropertyType.Name; } switch (name) { case "Int32": propertyInfo.SetValue(opportunity, Convert.ToInt32(value), null); break; case "String": propertyInfo.SetValue(opportunity, value.ToString(), null); break; case "DateTime": propertyInfo.SetValue(opportunity, Convert.ToDateTime(value), null); break; case "Double": propertyInfo.SetValue(opportunity, Convert.ToDouble(value), null); break; case "Decimal": propertyInfo.SetValue(opportunity, Convert.ToDecimal(value), null); break; } }
/// <summary> /// Runs the update CRM opportunities. /// </summary> /// <param name="opportunitiesToUpdate">The opportunities to update.</param> /// <returns></returns> public Response RunUpdateCRMOpportunities(OpportunityDto opportunitiesToUpdate) { var dataService = new UpdateCRMDataService(); return(dataService.RunUpdateCRMOpportunities(opportunitiesToUpdate)); }
public IFacadeUpdateResult <OpportunityData> SaveOpportunity(OpportunityDto dto) { return(OpportunitySystem.SaveOpportunity(dto)); }
public Response RunUpdateCRMOpportunities(OpportunityDto opportunityDto) { // Initialise variables Response response = Authenticate(opportunityDto.LoginInfo); if (response.Errors.Count > 0) { return(response); } var opportunitiesToUpdate = opportunityDto.OpportunityTable; var xRefDef = opportunityDto.CRMXrefDefinition; CreateSqlAndMapper(xRefDef); try { var opportunityBL = new OpportunityBL(); var utilityBl = new UtilityBL(); // Create a list of opportunities // mapping the values of the opportunity table with the ones on the Salesforce Opportunity object var recordsSdaUpdate = new List <OpportunityDto>(); var recordsSdaAdd = new List <OpportunityDto>(); int crmClientId = -1; foreach (DataRow row in opportunitiesToUpdate.Rows) { int clientID = -1; if (row.Table.Columns.Contains("ClientID") && row["ClientID"] != DBNull.Value) { int.TryParse(row["ClientID"].ToString(), out clientID); crmClientId = clientID; } else { response.Errors.Add("Invalid Client Id."); } var strCRMOppId = string.Empty; if (row.Table.Columns.Contains("CRMOppID") && row["CRMOppID"] != DBNull.Value) { strCRMOppId = row["CRMOppID"].ToString(); } List <OppStatusDto> lstat = utilityBl.GetStatuses(clientID); bool hasStatus = false; if (row.Table.Columns.Contains("OppStatus") && row["OppStatus"] != DBNull.Value) { var strStatus = row["OppStatus"].ToString(); int statValue = 0; foreach (var stat in lstat) { if (stat.OppStatus.ToLower().Trim().Equals(strStatus.ToLower().Trim())) { statValue = stat.ID; break; } } if (statValue > 0) { row["OppStatus"] = statValue; hasStatus = true; } } if (!hasStatus) { if (lstat.Count > 0) { var defaultStatus = lstat.Where(s => s.Default.Equals("Y")).FirstOrDefault(); if (defaultStatus != null) { row["OppStatus"] = defaultStatus.ID; hasStatus = true; } } if (!hasStatus) { response.Errors.Add("Invalid Opp Status."); } } OpportunityDto opportunity = null; if (!string.IsNullOrEmpty(strCRMOppId)) { opportunity = opportunityBL.GetOpportunityByClientIDAndCRMOppID(clientID, strCRMOppId); } bool isNewOpportunity; if (opportunity == null) { // Create a new opportunity opportunity = new OpportunityDto(); isNewOpportunity = true; } else { isNewOpportunity = false; } // Copy the fields to the opportunity var type = opportunity.GetType(); //loop over the rows mapping the database field with the corresponding field on the CRM foreach (var mappingObject in DatabaseToCRMMap) { var propertyInfo = type.GetProperty(mappingObject.CRMField); if (propertyInfo != null) { if (row[mappingObject.SdaField] != DBNull.Value) { utilityBl.SetProperty(opportunity, propertyInfo, row[mappingObject.SdaField]); } } } if (isNewOpportunity) { recordsSdaAdd.Add(opportunity); } else { recordsSdaUpdate.Add(opportunity); } } // Update the list of opportunities on Salesforce response = new Response(); Response responseUpdate = opportunityBL.UpdateSdaCloudOpportunity(recordsSdaUpdate); Response responseAdd = opportunityBL.AddSdaCloudOpportunity(recordsSdaAdd); // Merge both results foreach (string result in responseUpdate.Results) { response.Results.Add(result); } foreach (string result in responseAdd.Results) { response.Results.Add(result); } //Merge both errors foreach (string error in responseUpdate.Errors) { response.Errors.Add(error); } foreach (string error in responseAdd.Errors) { response.Errors.Add(error); } } catch (Exception ex) { response.Errors.Add(ex.Message); if (ex.InnerException != null) { response.Errors.Add(ex.InnerException.Message); } } return(response); }
private async Task <int> CreateOpportunityAsync(OpportunityDto dto) { var opportunityId = await _opportunityService.CreateOpportunityAsync(dto); return(opportunityId); }
public int UpdateOpportunityById(OpportunityDto opportunityDto) { return(new OpportunityDL().UpdateOpportunityById(opportunityDto)); }