public IHttpActionResult AddToCart(List <string> rows) { var cartNo = DateTime.Now.Ticks.ToString(); var dateCreated = DateTime.Now; var customer = db.Customer.FirstOrDefault(); //TODO: add customer management foreach (var row in rows) { var record = row.Split(';'); if (record[2] != "0" && record[2] != String.Empty) { var tempName = record[0]; var orderModel = new Order { Id = Guid.NewGuid(), CartNo = cartNo, DateCreated = dateCreated, Customer = customer }; Guid id = db.Inventory.Where(y => y.Name == tempName).Select(y => y.Id) .SingleOrDefault(); var equipmentType = db.Inventory.Where(y => y.Name == tempName).Select(y => y.EquipmentType) .SingleOrDefault(); var points = CalculatePoints.Calculate(equipmentType); customer.BonusPoints += points; orderModel.ItemId = id; orderModel.Duration = Int32.Parse(record[2]); db.Order.Add(orderModel); } } db.SaveChanges(); return(StatusCode(HttpStatusCode.NoContent)); }
private void CallFunctionAfterSeconds() { timer.CallFunctionAfterSeconds(delayTime, () => { Debug.Log("stars component " + CalculatePoints.GetPoints()); CallFunctionAfterSeconds(); }); }
static void Main() { //Question-1 Console.WriteLine("Sum Checker::->"); SumOfNumbers sumOfNumbers = new SumOfNumbers(); Console.WriteLine("Enter First Number"); int num1 = int.Parse(Console.ReadLine()); Console.WriteLine("Enter Second Number"); int num2 = int.Parse(Console.ReadLine()); bool result = sumOfNumbers.SumNum(num1, num2); Console.WriteLine($"Your result is {result}."); //Question-2 Console.WriteLine(); Console.WriteLine("Points Calculator::->"); CalculatePoints calculatePoints = new CalculatePoints(); Console.Write("Enter the number of wins:"); int win = int.Parse(Console.ReadLine()); Console.Write("Enter the number of draws:"); int draw = int.Parse(Console.ReadLine()); Console.Write("Enter the number of loss:"); int loss = int.Parse(Console.ReadLine()); int totalPoints = calculatePoints.Points(win, draw, loss); Console.WriteLine($"The total point of your team is {totalPoints}"); //Question-3 Console.WriteLine(); Console.WriteLine("Read Initials::->"); Initials initials = new Initials(); Console.Write("Enter Your Name::"); string input = Console.ReadLine(); string resultInitials = initials.GetInitials(input); Console.WriteLine($"Your Initials is:: {resultInitials}"); }
protected override async Task RunAsync(CancellationToken cancellationToken) { // TODO: Replace the following sample code with your own logic // or remove this RunAsync override if it's not needed in your service. if (cancellationToken.IsCancellationRequested) { } var playerMatchStatisticsDictionary = await this.StateManager.GetOrAddAsync <IReliableDictionary <int, int> >("PlayerMatchStatisticsDictionary"); //while (true) //{ // cancellationToken.ThrowIfCancellationRequested(); // using (var tx = this.StateManager.CreateTransaction()) // { // var result = await myDictionary.TryGetValueAsync(tx, "Counter"); // ServiceEventSource.Current.ServiceMessage(this.Context, "Current Counter Value: {0}", // result.HasValue ? result.Value.ToString() : "Value does not exist."); // await myDictionary.AddOrUpdateAsync(tx, "Counter", 0, (key, value) => ++value); // // If an exception is thrown before calling CommitAsync, the transaction aborts, all changes are // // discarded, and nothing is saved to the secondary replicas. // await tx.CommitAsync(); // } // await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken); //} while (true) { List <PlayerMatchStatistics> stats; stats = new List <PlayerMatchStatistics>(); CancellationToken ct = new CancellationToken(); List <PlayerMatchStatistics> result = new List <PlayerMatchStatistics>(); using (var tx = this.StateManager.CreateTransaction()) { var playerlist = await playerMatchStatisticsDictionary.CreateEnumerableAsync(tx); Microsoft.ServiceFabric.Data.IAsyncEnumerator <KeyValuePair <int, int> > enumerator = playerlist.GetAsyncEnumerator(); while (await enumerator.MoveNextAsync(ct)) { stats.Add(new PlayerMatchStatistics { PlayerId = enumerator.Current.Key, PlayerPoints = enumerator.Current.Value }); } } ////get it from RD this returns instance of PlayerMatchStatistics //PlayerMatchStatistics playerMatchStatistics = new PlayerMatchStatistics(); //playerMatchStatistics.PlayerId = 1; //playerMatchStatistics.PlayerPoints = 100; //stats.Add(playerMatchStatistics); //playerMatchStatistics = new PlayerMatchStatistics(); //playerMatchStatistics.PlayerId = 2; //playerMatchStatistics.PlayerPoints = 100; //stats.Add(playerMatchStatistics); //playerMatchStatistics = new PlayerMatchStatistics(); //playerMatchStatistics.PlayerId = 3; //playerMatchStatistics.PlayerPoints = 100; //stats.Add(playerMatchStatistics); //playerMatchStatistics = new PlayerMatchStatistics(); //playerMatchStatistics.PlayerId = 4; //playerMatchStatistics.PlayerPoints = 100; //stats.Add(playerMatchStatistics); //playerMatchStatistics = new PlayerMatchStatistics(); //playerMatchStatistics.PlayerId = 5; //playerMatchStatistics.PlayerPoints = 100; //stats.Add(playerMatchStatistics); //playerMatchStatistics = new PlayerMatchStatistics(); //playerMatchStatistics.PlayerId = 6; //playerMatchStatistics.PlayerPoints = 100; //stats.Add(playerMatchStatistics); //playerMatchStatistics = new PlayerMatchStatistics(); //playerMatchStatistics.PlayerId = 7; //playerMatchStatistics.PlayerPoints = 100; //stats.Add(playerMatchStatistics); //playerMatchStatistics = new PlayerMatchStatistics(); //playerMatchStatistics.PlayerId = 8; //playerMatchStatistics.PlayerPoints = 100; //stats.Add(playerMatchStatistics); //Apply rules to the entries from the DB var json = "[{'matchPlayerPerformaId':1,'userId':1,'playerId':1,'matchId':1,'strike':4,'isCaughtAndBowled':false,'hasWicketTaken':false,'isStumped':false,'isRunOut':false,'isHalfCentury':false,'isCentury':false,'isFourWickets':false,'isEightWickets':false,'isMaidenOver':false,'isDismissalOnDuck':false,'totalRun':0,'totalWicket':0,'over':0.00},{'matchPlayerPerformaId':2,'userId':1,'playerId':8,'matchId':1,'strike':0,'isCaughtAndBowled':false,'hasWicketTaken':false,'isStumped':false,'isRunOut':true,'isHalfCentury':false,'isCentury':false,'isFourWickets':false,'isEightWickets':false,'isMaidenOver':false,'isDismissalOnDuck':false,'totalRun':0,'totalWicket':0,'over':0.00},{'matchPlayerPerformaId':3,'userId':1,'playerId':2,'matchId':1,'strike':0,'isCaughtAndBowled':false,'hasWicketTaken':false,'isStumped':true,'isRunOut':false,'isHalfCentury':false,'isCentury':false,'isFourWickets':false,'isEightWickets':false,'isMaidenOver':false,'isDismissalOnDuck':false,'totalRun':0,'totalWicket':0,'over':0.00},{'matchPlayerPerformaId':4,'userId':1,'playerId':3,'matchId':1,'strike':0,'isCaughtAndBowled':true,'hasWicketTaken':true,'isStumped':false,'isRunOut':false,'isHalfCentury':false,'isCentury':false,'isFourWickets':false,'isEightWickets':false,'isMaidenOver':false,'isDismissalOnDuck':false,'totalRun':0,'totalWicket':0,'over':0.00},{'matchPlayerPerformaId':5,'userId':1,'playerId':4,'matchId':1,'strike':6,'isCaughtAndBowled':false,'hasWicketTaken':false,'isStumped':false,'isRunOut':false,'isHalfCentury':true,'isCentury':false,'isFourWickets':false,'isEightWickets':false,'isMaidenOver':false,'isDismissalOnDuck':false,'totalRun':0,'totalWicket':0,'over':0.00},{'matchPlayerPerformaId':6,'userId':1,'playerId':5,'matchId':1,'strike':0,'isCaughtAndBowled':false,'hasWicketTaken':true,'isStumped':false,'isRunOut':false,'isHalfCentury':false,'isCentury':false,'isFourWickets':true,'isEightWickets':false,'isMaidenOver':true,'isDismissalOnDuck':false,'totalRun':0,'totalWicket':0,'over':0.00},{'matchPlayerPerformaId':7,'userId':1,'playerId':6,'matchId':1,'strike':0,'isCaughtAndBowled':false,'hasWicketTaken':false,'isStumped':false,'isRunOut':true,'isHalfCentury':false,'isCentury':false,'isFourWickets':false,'isEightWickets':false,'isMaidenOver':false,'isDismissalOnDuck':false,'totalRun':0,'totalWicket':0,'over':0.00},{'matchPlayerPerformaId':8,'userId':1,'playerId':7,'matchId':1,'strike':0,'isCaughtAndBowled':false,'hasWicketTaken':false,'isStumped':false,'isRunOut':false,'isHalfCentury':false,'isCentury':false,'isFourWickets':false,'isEightWickets':false,'isMaidenOver':false,'isDismissalOnDuck':true,'totalRun':0,'totalWicket':0,'over':0.00}]"; //using (var httpClient = new HttpClient()) //{ // json = httpClient.GetStringAsync(new Uri("http://idtp376.synerzipune.local:8562/api/PlayerPerfoma/")).Result; //} ValidationContext context = new ValidationContext(); var playerStatistics = JsonConvert.DeserializeObject <List <PlayerStatistics> >(json); foreach (var point in playerStatistics) { // var point = new PlayerStatistics { Strike = 3 }; var wicketpoints = Rule.Create(point, entity => entity.Strike > 0 ? CalculatePoints.CalculateStrikePoints(point, stats) : CalculatePoints.FillEmptyPoints(point)); // point = new PlayerStatistics { HasWicketTaken = true }; var strikePoints = Rule.Create(point, entity => entity.HasWicketTaken == true ? CalculatePoints.CalculateWicketsPoints(entity, stats) : CalculatePoints.FillEmptyPoints(entity)); // point = new PlayerStatistics { IsCaughtAndBowled = true }; var caughtandBowled = Rule.Create(point, entity => entity.IsCaughtAndBowled == true ? CalculatePoints.CalculateCaughtAndBowledPoints(entity, stats) : CalculatePoints.FillEmptyPoints(entity)); // point = new PlayerStatistics { IsRunout = false }; var runoutPoints = Rule.Create(point, entity => entity.IsRunout == true ? CalculatePoints.CalculateRunoutPoints(entity, stats) : CalculatePoints.FillEmptyPoints(entity)); // point = new PlayerStatistics { IsStumped = false }; var stumpOutPoints = Rule.Create(point, entity => entity.IsStumped == true ? CalculatePoints.CalculateStumpedPoints(entity, stats) : CalculatePoints.FillEmptyPoints(entity)); var maidenOverPoints = Rule.Create(point, entity => entity.IsMaidenOver == true ? CalculatePoints.CalculateMaidenOverPoints(entity, stats) : CalculatePoints.FillEmptyPoints(entity)); var eightWicketsPoints = Rule.Create(point, entity => entity.IsEightWickets == true ? CalculatePoints.CalculateEightWicketsPoints(entity, stats) : CalculatePoints.FillEmptyPoints(entity)); var fourWicketsPoints = Rule.Create(point, entity => entity.IsFourWickets == true ? CalculatePoints.CalculateFourWicketsPoints(entity, stats) : CalculatePoints.FillEmptyPoints(entity)); var halfCenturyWicketsPoints = Rule.Create(point, entity => entity.IsHalfCentury == true ? CalculatePoints.CalculateHalfCenturyPoints(entity, stats) : CalculatePoints.FillEmptyPoints(entity)); var centurysPoints = Rule.Create(point, entity => entity.IsCentury == true ? CalculatePoints.CalculateCenturyPoints(entity, stats) : CalculatePoints.FillEmptyPoints(entity)); var dismissalOnDuckPoints = Rule.Create(point, entity => entity.IsDismissalOnDuck == true ? CalculatePoints.CalculateDissmisalOnDuckPoints(entity, stats) : CalculatePoints.FillEmptyPoints(entity)); context = new ValidationContext(wicketpoints, strikePoints, caughtandBowled, runoutPoints, stumpOutPoints, maidenOverPoints, eightWicketsPoints, fourWicketsPoints, halfCenturyWicketsPoints, centurysPoints, dismissalOnDuckPoints); var totalPoints = context.GetResults(); totalPoints.Where(x => x.PlayerId > 0).ToList().ForEach(x => result.Add(new PlayerMatchStatistics { PlayerId = x.PlayerId, PlayerPoints = x.PlayerPoints })); } var res = result.GroupBy(x => x.PlayerId, (key, group) => group.First()).ToList(); foreach (var player in res) { using (var tx = this.StateManager.CreateTransaction()) { var playerdetail = await playerMatchStatisticsDictionary.TryGetValueAsync(tx, player.PlayerId); ServiceEventSource.Current.ServiceMessage(this.Context, "Current Counter Value: {0}", playerdetail.HasValue ? playerdetail.Value.ToString() : "Value does not exist."); await playerMatchStatisticsDictionary.AddOrUpdateAsync(tx, player.PlayerId, player.PlayerPoints, (key, value) => player.PlayerPoints); // If an exception is thrown before calling CommitAsync, the transaction aborts, all changes are // discarded, and nothing is saved to the secondary replicas. await tx.CommitAsync(); } } await Task.Delay(TimeSpan.FromMinutes(1)); } }
private void CallFunctionAfterSeconds() { Debug.Log("Stop " + CalculatePoints.GetPoints()); Destroy(timer); }
private void SetReferences() { islandCamera = FindObjectOfType <IslandCamera>(); pointsCalculator = GetComponent <CalculatePoints>(); gameModeManager = GlobalManager.instance.gameModeManager; }
public IHttpActionResult Create(string cartNo) { var cartData = db.Order.Where(x => x.CartNo == cartNo); var cartDate = cartData.Where(x => x.CartNo == cartNo).Select(x => x.DateCreated) .FirstOrDefault(); var customer = db.Customer.FirstOrDefault(x => x.Id == cartData.Select(y => y.Customer.Id).FirstOrDefault()); List <InvoiceItems> invoice = new List <InvoiceItems>(); foreach (var item in cartData) { var itemName = db.Inventory.Where(x => x.Id == item.ItemId).Select(x => x.Name) .FirstOrDefault(); var itemType = db.Inventory.Where(x => x.Id == item.ItemId).Select(x => x.EquipmentType) .FirstOrDefault(); int duration = item.Duration; InvoiceItems items = new InvoiceItems(); { items.ItemName = itemName; items.RentDuration = duration; items.RentPrice = CalculatePrice.Price(itemType, duration); items.BonusPoints = CalculatePoints.Calculate(itemType); } invoice.Add(items); } using (var stream = new MemoryStream()) { StreamWriter writer = new StreamWriter(stream); writer.WriteLine("Invoice no: " + cartDate.Ticks); writer.WriteLine("-------------------"); writer.WriteLine("Customer name: " + customer?.CustomerName + ", you have " + customer?.BonusPoints + " points"); writer.WriteLine("Equipment:"); writer.WriteLine("-------------------"); int priceSum = 0; int pointsSum = 0; foreach (var item in invoice) { writer.WriteLine(item.ItemName + "; " + item.RentDuration + " days; " + item.RentPrice + " €"); priceSum += item.RentPrice; pointsSum += item.BonusPoints; } writer.WriteLine("-------------------"); writer.WriteLine("Total: " + priceSum + " €"); writer.WriteLine("Points earned: " + pointsSum); writer.Flush(); writer.Close(); var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(stream.ToArray()) }; result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment") { FileName = "Invoice.txt" }; result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); var response = ResponseMessage(result); return(response); } }