コード例 #1
0
 /// <summary>
 /// Instantiates a new MainPage.
 /// </summary>
 /// <param name="activityService">The activityService.</param>
 /// <param name="sqlService">The SqlService.</param>
 /// <param name="fitnessService">The fitnessSerivice.</param>
 public MainPage(ActivityService activityService, Sql sqlService)
 {
     _activityService = activityService;
     _sqlService      = sqlService;
     _fitness         = new Fitness();
     InitializeComponent();
     model = new FitnessModel();
     SetColours();
 }
コード例 #2
0
        private async void Refresh(object sender, EventArgs e)
        {
            isLoading = true;
            model     = await _fitness.GetCurrentFitness();

            var athlete = await _activityService.GetAthlete();

            MainLayout.BindingContext = model;
            isLoading = false;
        }
コード例 #3
0
 /// <summary>
 /// Saves a fitness model.
 /// </summary>
 /// <param name="f"></param>
 /// <returns>The objects primary key.</returns>
 public int SaveFitness(FitnessModel f)
 {
     if (GetFitnessItem(f.Id) != null)
     {
         return(database.Update(f));
     }
     else
     {
         return(database.Insert(f));
     }
 }
コード例 #4
0
 public ActionResult Create(FitnessModel model)
 {
     if (Request.IsAuthenticated)
     {
         if (Request.Files.Count > 0)
         {
             var uploadFile = Request.Files[0];
             if (uploadFile != null && uploadFile.ContentLength > 4096 * 1024)
             {
                 ModelState.AddModelError("Filesize", "Image is too big, please select at smaller file");
             }
             if (uploadFile != null && uploadFile.ContentLength > 0 && uploadFile.ContentLength < 4096 * 1024)
             {
                 var fullPath  = Server.MapPath("~/Content/img/user/" + model.Img);
                 var sFullPath = Server.MapPath("~/Content/img/user/sm-" + model.Img);
                 if (System.IO.File.Exists(fullPath))
                 {
                     System.IO.File.Delete(fullPath);
                     System.IO.File.Delete(sFullPath);
                 }
                 var      fileName = Path.GetFileName(uploadFile.FileName);
                 var      fileId   = Guid.NewGuid().ToString();
                 var      path     = Path.Combine(Server.MapPath("~/Content/img/user/"), fileId + fileName);
                 var      sPath    = Path.Combine(Server.MapPath("~/Content/img/user/"), "sm-" + fileId + fileName);
                 WebImage img      = new WebImage(uploadFile.InputStream);
                 img.Save(path);
                 if (img.Width > 1000)
                 {
                     img.Resize(1000, 300);
                 }
                 model.Img = fileId + fileName;
                 img.Save(sPath);
             }
         }
         model.Id     = Guid.NewGuid().ToString();
         model.UserId = UserViewModel.GetCurrentUser().Id;
         model.Author = UserViewModel.GetCurrentUser().Name;
         if (ModelState.IsValid)
         {
             _db.Fitness.Add(model);
             _db.SaveChanges();
             return(RedirectToAction("Edit", "Fitness", model.Id));
         }
         return(View(model));
     }
     return(RedirectToAction("Index", "Account"));
 }
コード例 #5
0
        protected async override void OnAppearing()
        {
            isLoading = true;
            model     = await _fitness.GetCurrentFitness();

            var now = DateTime.Now;

            var lseven = new Label()
            {
                Text = "Past 7 Days"
            };

            lseven.HorizontalOptions = LayoutOptions.CenterAndExpand;
            var sevenDayChart = CreateLineChart(DateTime.Now.AddDays(-7), now);
            var lfourteen     = new Label()
            {
                Text = "Past 28 Days"
            };

            lfourteen.HorizontalOptions = LayoutOptions.CenterAndExpand;
            var fourteenDayChart = CreateLineChart(DateTime.Now.AddDays(-14), now);
            var lmonth           = new Label()
            {
                Text = "Last 2 Months"
            };

            lmonth.HorizontalOptions = LayoutOptions.CenterAndExpand;
            var fourtyTwoDayChart = CreateLineChart(DateTime.Now.AddMonths(-2), now);

            MainLayout.Children.Add(lseven);
            MainLayout.Children.Add(sevenDayChart);
            MainLayout.Children.Add(lfourteen);
            MainLayout.Children.Add(fourteenDayChart);
            MainLayout.Children.Add(lmonth);
            MainLayout.Children.Add(fourtyTwoDayChart);


            SetColours();

            base.OnAppearing();

            isLoading = false;
        }
コード例 #6
0
        protected override async void OnAppearing()
        {
            FitnessModel model = new FitnessModel();

            isLoading = true;

            if (!string.IsNullOrEmpty(Settings.AccessToken))
            {
                model = await _fitness.GetCurrentFitness();

                GetImprovement();
                GetConsistency();
                GetRiskOfInjury();
                GetPredictions();
            }

            MainLayout.BindingContext = model;

            base.OnAppearing();

            isLoading = false;
        }
コード例 #7
0
        public ActionResult Edit(FitnessModel model)
        {
            var formData  = Request.Form.AllKeys.ToList();
            var sm        = new ScheduleModel();
            var fitnessId = Request.Form["Id"];
            var f         = _db.Fitness.Find(fitnessId);

            if (Request.Files.Count > 0)
            {
                var uploadFile = Request.Files[0];
                if (uploadFile != null && uploadFile.ContentLength > (4096 * 1024))
                {
                    ModelState.AddModelError("Filesize", "Image is too big, please try uploading a smaller one");
                }
                if (uploadFile != null && (uploadFile.ContentLength > 0 && uploadFile.ContentLength < (4096 * 1024)))
                {
                    if (f != null)
                    {
                        var fullPath  = Server.MapPath("~/Content/img/user/" + f.Img);
                        var sFullPath = Server.MapPath("~/Content/img/user/sm-" + f.Img);
                        if (System.IO.File.Exists(fullPath))
                        {
                            System.IO.File.Delete(fullPath);
                            System.IO.File.Delete(sFullPath);
                        }
                    }
                    var      fileName = Path.GetFileName(uploadFile.FileName);
                    var      fileId   = Guid.NewGuid().ToString();
                    var      path     = Path.Combine(Server.MapPath("~/Content/img/user/"), fileId + fileName);
                    var      sPath    = Path.Combine(Server.MapPath("~/Content/img/user/"), "sm-" + fileId + fileName);
                    WebImage img      = new WebImage(uploadFile.InputStream);
                    img.Save(path);
                    if (img.Width > 1000)
                    {
                        img.Resize(1000, 300);
                    }
                    if (f != null)
                    {
                        f.Img = fileId + fileName;
                    }
                    img.Save(sPath);
                }
            }
            if (ModelState.IsValid)
            {
                if (f != null)
                {
                    f.Title            = model.Title;
                    f.Description      = model.Description;
                    f.Tags             = model.Tags;
                    _db.Entry(f).State = EntityState.Modified;
                }
                _db.SaveChanges();
            }
            else
            {
                return(View(model));
            }

            foreach (var key in formData)
            {
                if (!key.StartsWith("Description") && !key.StartsWith("Title"))
                {
                    string[] value  = Request.Form[key].Split(',');
                    string[] values = key.Split('_');

                    if (value[0] != "")
                    {
                        if (key.StartsWith("schedule_"))
                        {
                            sm.Id = value[0];
                        }
                        if (key.StartsWith("calories_"))
                        {
                            sm.Calories = value[0];
                        }

                        if (key.StartsWith("exerciseId_"))
                        {
                            sm.ExerciseId = value[0];
                            var exerciseModel = _db.Exercise.Find(sm.ExerciseId);
                            if (exerciseModel != null)
                            {
                                sm.Exercise = exerciseModel.Name;
                            }
                            int day = Convert.ToInt32(values[3].Replace("d", ""));
                            day              = day - 1;
                            sm.Day           = day;
                            sm.Week          = Convert.ToInt32(values[4].Replace("w", ""));
                            sm.ExerciseIndex = Convert.ToInt32(values[2].Replace("e", ""));
                        }
                        if (key.StartsWith("interval_"))
                        {
                            sm.Time = value[0];
                        }
                        sm.FitnessId = fitnessId;
                        if (!string.IsNullOrEmpty(sm.Time))
                        {
                            if (string.IsNullOrEmpty(sm.Id))
                            {
                                sm.Id = Guid.NewGuid().ToString();
                                _db.Schedule.Add(sm);
                                _db.SaveChanges();
                            }
                            else
                            {
                                _db.Entry(sm).State = EntityState.Modified;
                                _db.SaveChanges();
                            }
                            sm = new ScheduleModel();
                        }
                    }
                }
            }
            return(RedirectToAction("../Fitness/Details/" + fitnessId));
        }
コード例 #8
0
        public IHttpActionResult Like(JObject jsonData)
        {
            var lm = new LikeModel();

            dynamic json       = jsonData;
            var     user       = UserViewModel.GetCurrentUser();
            var     liked      = _db.Like.ToList().Where(x => x.Type == Convert.ToInt32(json.type) && x.TypeId == json.typeId.ToString() && x.UserId == user.Id);
            var     likeModels = liked as LikeModel[] ?? liked.ToArray();

            if (!likeModels.Any())
            {
                lm.Id     = Guid.NewGuid().ToString();
                lm.Type   = json.type;
                lm.UserId = user.Id;
                lm.TypeId = json.typeId.ToString();
                _db.Like.Add(lm);
                if (json.type == 1)
                {
                    DietModel d = _db.Diet.Find(json.typeId.ToString());
                    d.Likes++;
                    _db.Entry(d).State = System.Data.Entity.EntityState.Modified;
                }
                if (json.type == 2)
                {
                    FitnessModel f = _db.Fitness.Find(json.typeId.ToString());
                    f.Likes++;
                    _db.Entry(f).State = System.Data.Entity.EntityState.Modified;
                }
                if (json.type == 3)
                {
                    HealthModel h = _db.Health.Find(json.typeId.ToString());
                    h.Likes++;
                    _db.Entry(h).State = System.Data.Entity.EntityState.Modified;
                }
                _db.SaveChanges();
                return(Ok(lm));
            }
            else
            {
                var like = likeModels.First();

                _db.Like.Remove(like);
                if (json.type == 1)
                {
                    DietModel d = _db.Diet.Find(json.typeId.ToString());
                    d.Likes            = d.Likes - 1;
                    _db.Entry(d).State = System.Data.Entity.EntityState.Modified;
                }
                if (json.type == 2)
                {
                    FitnessModel f = _db.Fitness.Find(json.typeId.ToString());
                    f.Likes            = f.Likes - 1;
                    _db.Entry(f).State = System.Data.Entity.EntityState.Modified;
                }
                if (json.type == 3)
                {
                    HealthModel h = _db.Health.Find(json.typeId.ToString());
                    h.Likes            = h.Likes - 1;
                    _db.Entry(h).State = System.Data.Entity.EntityState.Modified;
                }
                _db.SaveChanges();
                return(Ok());
            }
        }