Example #1
0
        public void Reset()
        {
            var result = db.Projects.ToList();

            foreach (var item in result)
            {
                item.UpVote          = 0;
                item.DownVote        = 0;
                db.Entry(item).State = EntityState.Modified;
            }

            db.SaveChanges();
        }
Example #2
0
        public async override Task ExecuteAsync()
        {
            var players = context.Players.OrderByDescending(player => player.Clicks).ToList();

            for (int i = 0; i < players.Count; i++)
            {
                var player = context.Entry <Player>(players[i]);
                player.Entity.Rank      = i + 1;
                player.Entity.OldClicks = player.Entity.Clicks;
            }

            await context.SaveChangesAsync();

            players = context.Players.OrderByDescending(player => player.Clicks).ToList();
            Player winner = null;

            for (int i = 0; i < players.Count; i++)
            {
                var player = context.Entry <Player>(players[i]).Entity;
                if (i == 0)
                {
                    winner = player;
                    WindowsPushMessage message = new WindowsPushMessage();

                    // Define the XML paylod for a WNS native toast notification
                    // that contains the text of the inserted item.
                    message.XmlPayload = @"<?xml version=""1.0"" encoding=""utf-8""?>" +
                                         @"<toast><visual><binding template=""ToastText01"">" +
                                         @"<text id=""1"">" + "Congratulations " + player.Name + "!! You are todays first player with " + player.Clicks + " clicks. " + @"</text>" +
                                         @"</binding></visual></toast>";

                    // Use a tag to only send the notification to the logged-in user.
                    var result = await Services.Push.SendAsync(message, player.UserId);
                }
                else
                {
                    WindowsPushMessage message = new WindowsPushMessage();

                    // Define the XML paylod for a WNS native toast notification
                    // that contains the text of the inserted item.
                    message.XmlPayload = @"<?xml version=""1.0"" encoding=""utf-8""?>" +
                                         @"<toast><visual><binding template=""ToastText01"">" +
                                         @"<text id=""1"">" + "Sorry " + player.Name + ". You lost to " + winner.Name + ". Better luck next time." + @"</text>" +
                                         @"</binding></visual></toast>";

                    // Use a tag to only send the notification to the logged-in user.
                    var result = await Services.Push.SendAsync(message, player.UserId);
                }
            }
        }
Example #3
0
        public async Task <IHttpActionResult> PutAgent(string id, Agent agent)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != agent.Id)
            {
                return(BadRequest());
            }

            db.Entry(agent).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AgentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #4
0
        private void SaveParameter(string name, int value)
        {
            using (var contextService = new MobileServiceContext())
            {
                Parameters paramChange = contextService.Parameters.FirstOrDefault(p => p.Name == name);
                if (paramChange != null)
                {
                    paramChange.Value = value;
                    contextService.Entry(paramChange).State = EntityState.Modified;
                }
                else
                {
                    contextService.Parameters.Add(new Parameters()
                    {
                        Name  = name,
                        Id    = Guid.NewGuid().ToString(),
                        Value = value
                    });
                }

                try
                {
                    contextService.SaveChanges();
                }
                catch (DbUpdateConcurrencyException e)
                {
                    Debug.WriteLine(String.Format(e.Message + "\n" + e.Entries.Single().ToString()));
                }
            }
        }
Example #5
0
        // PATCH tables/Player/48D68C86-6EA6-4C25-AA33-223FC9A27959
        public async Task <Player> PatchPlayer(string id, Delta <Player> patch)
        {
            var currentUser = User as ServiceUser;
            var item        = patch.GetEntity();

            var result = await UpdateAsync(id, patch);

            var players = context.Players.OrderByDescending(player => player.Clicks).ToList();

            for (int i = 0; i < players.Count; i++)
            {
                var player = context.Entry <Player>(players[i]);
                player.Entity.Rank      = i + 1;
                player.Entity.OldClicks = player.Entity.Clicks;
            }

            await context.SaveChangesAsync();

            var message = new WindowsPushMessage();

            message.Headers.Add("X-WNS-Type", "wns/raw");
            message.XmlPayload = JsonConvert.SerializeObject(context.Players.ToList());

            await Services.Push.SendAsync(message);

            return(result);
        }
Example #6
0
 public ActionResult Edit([Bind(Include = "Id,UserName,Category,SubCategory,Amount,Comment,Receipt,Location,Status,PaymentMethod,Credit,Date,UploadedImage,Version,CreatedAt,UpdatedAt,Deleted")] Expense expense)
 {
     if (ModelState.IsValid)
     {
         db.Entry(expense).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(expense));
 }
        // GET api/DataRefresh
        public async Task <bool> Get()
        {
            // get all the orders
            var orders = _MobileServiceContext.Orders.ToList();

            if (orders.Count < 1)
            {
                throw new Exception("There doesn't seem to be any orders currently in the database.");
            }

            var lastUpdated = orders.First(x => x.UpdatedAt != null).UpdatedAt;

            if (lastUpdated != null)
            {
                var last = lastUpdated.Value.ToUniversalTime();

                DateTime now = DateTime.UtcNow;

                var today = DateTime.SpecifyKind(new DateTime(now.Year, now.Month, now.Day, 0, 0, 0), DateTimeKind.Utc);

                var lastUpdatedDay = DateTime.SpecifyKind(new DateTime(last.Year, last.Month, last.Day, 0, 0, 0), DateTimeKind.Utc);

                var daysElapsed = (int)(today - lastUpdatedDay).TotalDays;

                var weeksElapsed = (daysElapsed / 7);

                var daysToAdjust = weeksElapsed * 7;

                if (weeksElapsed > 0)
                {
                    foreach (var o in orders)
                    {
                        o.OrderDate  = o.OrderDate.AddDays(daysToAdjust);
                        o.DueDate    = o.DueDate.AddDays(daysToAdjust);
                        o.ClosedDate = o.ClosedDate?.AddDays(daysToAdjust);
                        o.UpdatedAt  = o.UpdatedAt?.AddDays(daysToAdjust);

                        _MobileServiceContext.Entry(o).State = EntityState.Modified;

                        await _MobileServiceContext.SaveChangesAsync();
                    }
                }
            }
            else
            {
                throw new  Exception("No orders have an UpdatedAt value. This should not happen.");
            }

            // all went well, so return a success result
            return(await Task.FromResult(true));
        }
Example #8
0
        public async override Task ExecuteAsync()
        {
            try
            {
                var orderList = _MobileServiceContext.Orders as IList <Order> ?? _MobileServiceContext.Orders.ToList();

                var oldestUpdatedOrder = orderList.OrderBy(o => o.UpdatedAt).FirstOrDefault();

                if (oldestUpdatedOrder?.UpdatedAt != null)
                {
                    DateTime lastUpdatedDate = oldestUpdatedOrder.UpdatedAt.Value.UtcDateTime;

                    int daysSinceUpdate = (DateTime.UtcNow - lastUpdatedDate).Days;

                    foreach (var o in orderList)
                    {
                        o.OrderDate  = o.OrderDate.AddDays(daysSinceUpdate);
                        o.DueDate    = o.DueDate.AddDays(daysSinceUpdate);
                        o.ClosedDate = o.ClosedDate?.AddDays(daysSinceUpdate);

                        _MobileServiceContext.Entry(o).State = EntityState.Modified;

                        await _MobileServiceContext.SaveChangesAsync();
                    }

                    Services.Log.Info($"Orders successfully refreshed. Total orders: {orderList.Count}");
                    await Task.FromResult(true);
                }
                else
                {
                    Services.Log.Warn("None of the orders seem to have an UpdatedAt value. This may mean there's no orders at all in the database.");
                    await Task.FromResult(false);
                }
            }
            catch (Exception ex)
            {
                Services.Log.Error($"Orders failed to refresh refresh: {ex.Message}");
                throw;
            }
        }