public PhoneBl MapPhoneToPhoneBl(Phone phone) { var phoneBl = new PhoneBl { Id = phone.Id, PhoneNumber = phone.PhoneNumber, SecondsLeftInBundle = phone.SecondsLeftInBundle, TextMessagesLeftInBundle = phone.TextMessagesLeftInBundle, CostOfConnectionsOutsideBundle = phone.CostOfConnectionsOutsideBundle, CostOfMessagesOutsideBundle = phone.CostOfMessagesOutsideBundle, }; if (phone.ShortTextMessages != null) { phoneBl.ShortTextMessages = MapSmsListToSmsBlList(phone.ShortTextMessages); } if (phone.Connections != null) { phoneBl.Connections = MapConnectionsListToConnectionsBlList(phone.Connections); } if (phone.Offer != null) { phoneBl.Offer = MapOfferToOfferBl(phone.Offer); } return(phoneBl); }
public void AddCostOfConnectionToTotalCost(PhoneBl phone, int secondsLeftInBundle) { if (CheckIfBundleOfMinutesExceeded(secondsLeftInBundle)) { phone.CostOfConnectionsOutsideBundle += GetPriceOfTheConnection(phone, secondsLeftInBundle); phone.SecondsLeftInBundle = (int)resetValue; } }
public bool CheckIfBundleOfSMSExceeded(PhoneBl phone) { if (phone.TextMessagesLeftInBundle < 0) { return(true); } return(false); }
public void AddCostOfTextMessageToTotalCost(PhoneBl phone) { if (CheckIfBundleOfSMSExceeded(phone)) { phone.CostOfMessagesOutsideBundle += phone.Offer.PricePerTextMessage; phone.TextMessagesLeftInBundle = (int)resetValue; } }
public PhoneBl Capture(OfferBl chosenOffer, int generatedNumber) { var newPhone = new PhoneBl { Offer = chosenOffer, PhoneNumber = generatedNumber, SecondsLeftInBundle = chosenOffer.BundleOfMinutes * _secondsInMinute, TextMessagesLeftInBundle = chosenOffer.BundleOfTextMessages }; return(newPhone); }
public void UpdatePhone(PhoneBl phoneBl) { var phone = _dataObjectMapper.MapPhoneBlToPhone(phoneBl); using (var dbContext = _dbContextFactory()) { dbContext.PhoneDbSet.Attach(phone); dbContext.Entry(phone).State = EntityState.Modified; dbContext.SaveChanges(); } }
public PhoneReportBl GenerateReport(PhoneBl phone) { var report = new PhoneReportBl { NameOfTheOffer = phone.Offer.Name, PriceOfTheOffer = phone.Offer.PriceOfTheOffer, TotlaCostOfConnections = phone.CostOfConnectionsOutsideBundle, TotlaCostOfTextMessages = phone.CostOfMessagesOutsideBundle, PhoneNumber = phone.PhoneNumber }; return(report); }
public Phone MapPhoneBlToPhone(PhoneBl phoneBl) { var phone = new Phone { Id = phoneBl.Id, PhoneNumber = phoneBl.PhoneNumber, SecondsLeftInBundle = phoneBl.SecondsLeftInBundle, TextMessagesLeftInBundle = phoneBl.TextMessagesLeftInBundle, CostOfConnectionsOutsideBundle = phoneBl.CostOfConnectionsOutsideBundle, CostOfMessagesOutsideBundle = phoneBl.CostOfMessagesOutsideBundle, Offer = MapOfferBlToOffer(phoneBl.Offer), ShortTextMessages = MapSmsBlListToSmsList(phoneBl.ShortTextMessages), Connections = MapConnectionsBlListToConnectionsList(phoneBl.Connections) }; return(phone); }
public int DecreaseNumberOfSmsInBundle(PhoneBl phone) { return(_phoneService.DecreaseNumberOfSmsInBundle(phone)); }
public void UpdatePhone(PhoneBl phoneBl) { _phoneService.UpdatePhone(phoneBl); }
public void AddCostOfConnectionToTotalCost(PhoneBl phone, int secondsLeftInBundle) { _phoneService.AddCostOfConnectionToTotalCost(phone, secondsLeftInBundle); }
public decimal GetPriceOfTheConnection(PhoneBl phone, int secondsOfConnection) { return(_phoneService.GetPriceOfTheConnection(phone, secondsOfConnection)); }
public int DecreaseBundleOfMinutes(PhoneBl phone, ConnectionBl connection) { return(_phoneService.DecreaseBundleOfMinutes(phone, connection)); }
public async Task AddGeneratedPhoneAsync(int indexOfSubscriber, int indexOfOffer, PhoneBl phoneBl) { await _phoneService.AddPhoneAsync(indexOfSubscriber, indexOfOffer, phoneBl); }
public void AddCostOfTextMessageToTotalCost(PhoneBl phone) { _phoneService.AddCostOfTextMessageToTotalCost(phone); }
public int DecreaseBundleOfMinutes(PhoneBl phone, ConnectionBl connection) { phone.SecondsLeftInBundle -= connection.TimeOfConnectionInSeconds; return(phone.SecondsLeftInBundle); }
public int DecreaseNumberOfSmsInBundle(PhoneBl phone) { return(phone.TextMessagesLeftInBundle--); }
public async Task <int> AddPhoneAsync(int indexOfSubscriber, int indexOfOffer, PhoneBl phoneBl) { var phone = _dataObjectMapper.MapPhoneBlToPhone(phoneBl); using (var dbContext = _dbContextFactory()) { var chosenSubscriber = await dbContext.SubscriberDbSet .Include(s => s.Phones) .SingleOrDefaultAsync(s => s.Id == indexOfSubscriber); var chosenOffer = await dbContext.OfferDbSet. SingleOrDefaultAsync(o => o.Id == indexOfOffer); phone.Subscriber = chosenSubscriber; phone.Offer = chosenOffer; await Task.Run(() => { dbContext.PhoneDbSet.Add(phone); dbContext.SaveChanges(); }); return(phone.Id); } }
public bool CheckIfBundleOfSMSExceeded(PhoneBl phone) { return(_phoneService.CheckIfBundleOfSMSExceeded(phone)); }
public decimal GetPriceOfTheConnection(PhoneBl phone, int secondsOfConnection) { return(Math.Ceiling((phone.Offer.PricePerMinute / _numberOfSecInMinute) * Math.Abs(secondsOfConnection) * 100) / 100); }