Example #1
0
        public Response Post(string id, [FromBody] Exercise value)
        {
            Response r = new Response();

            if (value == null)
            {
                r.Success = false;
                r.Message = "Null Exercise Found";
                return(r);
            }

            /*if (id != null)
             * {
             *  Exercise exercise = accessor.Get<Exercise>(id);
             *  if (!exercise.Description.Equals(value.Description))
             *  {
             *      bUpdateDescriptions = true;
             *  }
             * }*/

            value = GlobalFunctions.AddIdIfNeeded(value, id);
            r     = accessor.Post(value);
            if (r.Success)
            {
                r.Message = value.idString;
                CopySettingsToAllWorkoutPlans(value);
            }
            return(r);
        }
Example #2
0
        public IActionResult Post([FromBody] adjunct value, string id)
        {
            //double ibu = MathFunctions.IBU.basicIBU(value, 1.07);

            DataAccess accessor = new DataAccess();

            value = GlobalFunctions.AddIdIfNeeded(value, id);

            return(Json(accessor.Post(value)));
        }
Example #3
0
        public RecipeStatsResponse Post([FromBody] recipe value, string id, Boolean bSaveRecipe)
        {
            RecipeStatsResponse response = new RecipeStatsResponse();

            if (value != null)
            {
                DataAccess accessor = new DataAccess();
                try
                {
                    /*
                     * Checks if someone else has modified the recipe.
                     * */
                    if (!String.IsNullOrEmpty(id) && !id.Equals("000000000000000000000000"))
                    {
                        recipe existingRecipe = accessor.Get <recipe>(id);
                        //TODO: id is coming in as all 0's and then existing recipe becomes null, then this throws an exception
                        if (existingRecipe.lastModifiedGuid != value.lastModifiedGuid)
                        {
                            throw new Exception("Recipe has been modified.  Please refresh");
                        }
                    }
                    Guid lastModified = Guid.NewGuid();
                    value.lastModifiedGuid = lastModified;
                    value             = GlobalFunctions.AddIdIfNeeded(value, id);
                    value.recipeStats = MathFunctions.GlobalFunctions.updateStats(value);

                    if (bSaveRecipe)
                    {
                        accessor.PostRecipe(value);
                    }

                    response                  = new RecipeStatsResponse();
                    response.recipeStats      = value.recipeStats;
                    response.idString         = value.idString;
                    response.lastModifiedGuid = lastModified;
                    return(response);
                }
                catch (Exception e)
                {
                    response.Fail(e);
                    return(response);
                }
            }
            else
            {
                response.RecipeNullFailure();
                return(response);
            }
        }
Example #4
0
        public Response Post(string id, [FromBody] Goal value)
        {
            Response r = new Response();

            if (value == null)
            {
                r.Success = false;
                r.Message = "Null WorkoutType Found";
                return(r);
            }

            value = GlobalFunctions.AddIdIfNeeded(value, id);
            accessor.Post(value);

            r.Message = value.idString;

            return(r);
        }
Example #5
0
        public LastModifiedGuidResponse Post([FromBody] BrewLog value, string id)
        {
            LastModifiedGuidResponse response = new LastModifiedGuidResponse();

            if (value != null)
            {
                try
                {
                    /*
                     * Checks if someone else has modified the recipe.
                     * */
                    if (!String.IsNullOrEmpty(id))
                    {
                        BrewLog existingRecipe = accessor.Get <BrewLog>(id);
                        if (existingRecipe.lastModifiedGuid != value.lastModifiedGuid)
                        {
                            throw new Exception("Recipe has been modified.  Please refresh");
                        }
                    }
                    Guid lastModified = Guid.NewGuid();
                    value.lastModifiedGuid = lastModified;
                    value = GlobalFunctions.AddIdIfNeeded(value, id);

                    accessor.Post <BrewLog>(value);

                    response.lastModifiedGuid = lastModified;
                    response.idString         = value.idString;
                    return(response);
                }
                catch (Exception e)
                {
                    response.Fail(e);
                    return(response);
                }
            }
            else
            {
                response.Message = "No BrewLog given.";
                response.Success = false;
            }

            return(response);
        }
Example #6
0
        public IActionResult UpdateUserInfo([FromBody] userSettings currentUserSettings)
        {
            string       userID               = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            DataAccess   accessor             = new DataAccess();
            userSettings existingUserSettings = accessor.GetAll <userSettings>().FirstOrDefault();

            if (existingUserSettings == null)
            {
                existingUserSettings = generateDefaultUserSettings();
                accessor.Post(currentUserSettings);
                existingUserSettings           = accessor.GetAll <userSettings>().FirstOrDefault();
                existingUserSettings.firstName = currentUserSettings.firstName;
                existingUserSettings.lastName  = currentUserSettings.lastName;
                existingUserSettings.theme     = currentUserSettings.theme;
            }
            else
            {
                existingUserSettings.firstName = currentUserSettings.firstName;
                existingUserSettings.lastName  = currentUserSettings.lastName;
                existingUserSettings.theme     = currentUserSettings.theme;
            }
            currentUserSettings = GlobalFunctions.AddIdIfNeeded(existingUserSettings, existingUserSettings.idString);
            return(Json(accessor.Post(currentUserSettings)));
        }
Example #7
0
        public IActionResult Post(string id, [FromBody] Ingredient value)
        {
            value = GlobalFunctions.AddIdIfNeeded(value, id);

            return(Json(accessor.Post(value)));
        }