public async Task <PackageDto> CreatePackage(PackageDto package, PackageIncludesDto packageIncludes) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (package != null) { PackageEntity entity = new PackageEntity() { PackageName = package.PackageName, PackageTotalPrice = package.PackageTotalPrice, }; db.PackageIncludes.Add(packageIncludes.ToModel()); await db.SaveChangesAsync(); return(entity.ToDto()); } return(null); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public double GetNumberOfMinutes(LineDto line, PackageIncludesDto packageIncludes) { lock (obj) { return(callManager.GetNumberOfMinutes(line, packageIncludes)); } }
public async Task <PackageIncludesDto> UpdatePackageInclude(PackageIncludesDto packageIncludes) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (packageIncludes != null) { PackageIncludesEntity entity = packageIncludes.ToModel(); entity.Id = packageIncludes.Id; db.PackageIncludes.Attach(entity); foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames) { if (propName != "Id") { db.Entry(entity).Property(propName).IsModified = true; } } await db.SaveChangesAsync(); return(entity.ToDto()); } return(null); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public async Task <double> GetNumberOfMinutes(LineDto line, PackageIncludesDto packageIncludes) { var task = Task.Factory.StartNew(() => { var a = _manager.GetNumberOfMinutes(line, packageIncludes); return(a); }); return(await task.ConfigureAwait(false)); }
public async Task <PackageDto> AddPackage(PackageDto package, PackageIncludesDto packageIncludes) { Task <PackageDto> packageDto; lock (obj) { packageDto = packageManager.AddPackageDto(package, packageIncludes); } return(await packageDto); }
public static PackageIncludesEntity ToModel(this PackageIncludesDto package) { return(new PackageIncludesEntity() { DiscountPrecentage = package.DiscountPrecentage, FavoriteNumbersId = package.FavoriteNumbersId, FixedPrice = package.FixedPrice, Id = package.Id, IncludeName = package.IncludeName, InsideFamilyCalls = package.InsideFamilyCalls, MaxMinute = package.MaxMinute, MostCalledNumber = package.MostCalledNumber, PackageId = package.PackageId, //Package=package.Package.ToModel(), //SelectedNumber=package.SelectedNumber.ToModel() }); }
public static PackageIncludesEntity ToModel(this PackageIncludesDto package) { if (package == null) { return(null); } return(new PackageIncludesEntity() { DiscountPrecentage = package.DiscountPrecentage, FixedPrice = package.FixedPrice, PackageIncludesId = package.Id, IncludeName = package.IncludeName, InsideFamilyCalls = package.InsideFamilyCalls, MaxMinute = package.MaxMinute, MostCalledNumber = package.MostCalledNumber, //Package=package.Package.ToModel(), //Package = package.Package.ToModel(), //Line=package.Line.ToModel(), }); }
public IEnumerable <PackageDto> GetOptimalPackage(int lineId) { lock (obj) { LineDto line = lineManager.GetLineDto(lineId); Dictionary <PackageDto, double> dictionary = new Dictionary <PackageDto, double>(); foreach (var item in packageManager.GetPackageDtos()) { PackageIncludesDto packageIncludes = packageManager.GetPackageIncludes(item.PackageId); if (packageIncludes.InsideFamilyCalls == true) { dictionary.Add(item, CalculateTotalMinutesWithFamily(lineId) * packageIncludes.DiscountPrecentage); } if (packageIncludes.MostCalledNumber == true) { dictionary.Add(item, CalculateTotalMinutesOfTopNumber(lineId) * packageIncludes.DiscountPrecentage); } } return(dictionary.OrderBy(v => v.Value).Select(k => k.Key)); } }
public double GetNumberOfMinutes(LineDto line, PackageIncludesDto packageIncludes) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { double minutes = db.Calls.Where(l => l.LineId == line.LineId).Sum(l => l.Duration); if (minutes >= packageIncludes.MaxMinute) { return(minutes - packageIncludes.MaxMinute); } else { return(0); } } catch (Exception ex) { Debug.WriteLine(ex.Message); return(0); } } }
public async Task <PackageIncludesDto> UpdatePackageIncludesDto(PackageIncludesDto dto) { return(await GetContainer().Resolve <IPackageIncludesRepository>().UpdatePackageInclude(dto)); }
public async Task <PackageDto> AddPackage(PackageDto package, PackageIncludesDto packageIncludes) { return(await _manager.AddPackage(package, packageIncludes)); }
public double GetNumberOfMinutes(LineDto line, PackageIncludesDto packageIncludes) { return(GetContainer().Resolve <ICallsRepository>().GetNumberOfMinutes(line, packageIncludes)); }
public async Task <PackageDto> AddPackageDto(PackageDto dto, PackageIncludesDto packageIncludes) { return(await GetContainer().Resolve <IPackageRepository>().CreatePackage(dto, packageIncludes)); }
public async Task <PackageIncludesModel> GetPackageIncludes(int packageId) { PackageIncludesDto a = await invoice.GetLinePackageIncludesAsync(packageId); return(a.ToModel()); }