public ActionResult AddProgressAjax(GoalProgress model)
 {
     if (ModelState.IsValid == true)
     {
         try
         {
             GoalProgress Goalprogress = IBOVirtualAPI.GetProgress(model.goalId.ToString());
             if (model.progress == 100)
             {
                 Goal Goal = IBOVirtualAPI.Get <Goal>(model.goalId.ToString());
                 Goal.completed = true;
                 string result = IBOVirtualAPI.Update <Goal>(Goal.goalId.ToString(), Goal);
             }
             if (Goalprogress == null)
             {
                 bool result = IBOVirtualAPI.CreateProgress(model);
             }
             else
             {
                 model.progressId = Goalprogress.progressId;
                 string result = IBOVirtualAPI.UpdateProgress(model.progressId.ToString(), model);
             }
             return(Json(model));
         }
         catch
         {
             return(Json(new { success = false }));
         }
     }
     else
     {
         return(Json(new { success = false }));
     }
 }
        public ActionResult CreateProgress(int id)
        {
            GoalProgress Progress = new GoalProgress();

            Progress.goalId   = id;
            Progress.datetime = DateTime.Now;
            return(PartialView(Progress));
        }
        public decimal GetProgress(string id)
        {
            GoalProgress Goalprogress = IBOVirtualAPI.GetProgress(id);

            try
            {
                return(Goalprogress.progress);
            }
            catch
            {
                return(0);
            }
        }
        public HttpResponseMessage PostProgress(GoalProgress progress)
        {
            if (ModelState.IsValid)
            {
                db.GoalProgresses.Add(progress);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, progress);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = progress.progressId }));
                return(response);
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
        public async Task <IActionResult> AddProgress(AddGoalProgressInputModel Progress)
        {
            FitnessUser currentUser = await GetUser();

            Goal goal = await storageService.GetGoalByID(currentUser, Progress.GoalID);

            if (goal == null)
            {
                return(BadRequest());
            }

            GoalProgress newProgress = null;

            switch (Progress.Type.ToLower())
            {
            case "weightlifting":
                newProgress = new WeightliftingProgress()
                {
                    Weight = Progress.Weight,
                    Reps   = Progress.Reps
                };
                break;

            case "timed":
                newProgress = new TimedProgress()
                {
                    Time     = new TimeSpan(Progress.Hours, Progress.Minutes, Progress.Seconds),
                    Quantity = Progress.Quantity
                };
                break;

            default:
                return(BadRequest());
            }

            newProgress.Goal = goal;
            newProgress.Date = Progress.Date;
            newProgress.User = currentUser;

            await storageService.StoreGoalProgress(newProgress);

            return(RedirectToAction("ViewGoal", new { ID = Progress.GoalID }));
        }
        public HttpResponseMessage DeleteProgress(long id)
        {
            GoalProgress progress = db.GoalProgresses.Find(id);

            if (progress == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            db.GoalProgresses.Remove(progress);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, progress));
        }
        public HttpResponseMessage PutProgress(long id, GoalProgress progress)
        {
            if (ModelState.IsValid && id == progress.progressId)
            {
                db.Entry(progress).State = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Ejemplo n.º 8
0
        public static string UpdateProgress(string id, GoalProgress model)
        {
            BaseClient client = new BaseClient(baseApiUrl, "Progress", "PutProgress");

            return(client.Put <GoalProgress>(id.ToString(), model));
        }
Ejemplo n.º 9
0
        public static bool CreateProgress(GoalProgress model)
        {
            BaseClient client = new BaseClient(baseApiUrl, "Progress", "PostProgress");

            return(client.Post <GoalProgress>(model));
        }
        public ActionResult EditProgress(string id)
        {
            GoalProgress Goalprogress = IBOVirtualAPI.GetProgress(id);

            return(PartialView(Goalprogress));
        }
 public async Task StoreGoalProgress(GoalProgress Progress)
 {
     dbContext.GoalProgressRecords.Add(Progress);
     await dbContext.SaveChangesAsync();
 }