Beispiel #1
0
        public async Task <IActionResult> Add([FromBody] ActivityViewModel activity)
        {
            var user = _context.Users
                       .Include(x => x.Activities)
                       .FirstOrDefault(x => x.UserId == activity.UserId);

            if (user != null)
            {
                if (user.Activities == null)
                {
                    user.Activities = new List <Activity>();
                }

                FitnessType activityType;

                if (!string.IsNullOrEmpty(activity.Type)) //Old clients
                {
                    activityType = OldSupport.PatchOld(activity.Type);
                }
                else
                {
                    activityType = activity.FitnessType;
                }

                var existing = user.Activities.FirstOrDefault(x => x.Date.Date == activity.Date.Date && x.Type == activityType);
                if (existing == null)
                {
                    user.Activities.Add(new Activity {
                        Amount = activity.Amount,
                        Date   = activity.Date,
                        Type   = activityType,
                        UserId = activity.UserId
                    });
                }
                else
                {
                    existing.Date   = activity.Date;
                    existing.Amount = activity.Amount;
                }

                user.LastRecordedDate = activity.Date.Date;
                await _context.SaveChangesAsync();

                return(Ok());
            }
            {
                return(NotFound());
            }
        }
Beispiel #2
0
 public IActionResult GetUsers(string type)
 {
     return(GetUsers(OldSupport.PatchOld(type), FilterType.All));
 }
Beispiel #3
0
 public IActionResult Activities(string userId, string type = "getDailyDistanceSamples")
 {
     return(RedirectToAction("Activities", "Activity", new { userId, type = OldSupport.PatchOld(type), filter = FilterType.All }));
 }