コード例 #1
0
        /// <summary>
        /// Updates a user in the database
        /// </summary>
        /// <param name="user"></param>
        public void updateUser(string str)
        {
            masterEntities m            = ContextSingleton.getContext();
            RecipeService  recipeclient = new RecipeService();

            User user       = JsonConvert.DeserializeObject <User>(str, jsettings);
            User updateUser = JsonConvert.DeserializeObject <User>(GetUser(user.User_id), jsettings);

            updateUser.dairyfree      = user.dairyfree;
            updateUser.favJokes       = user.favJokes;
            updateUser.favTrivia      = user.favTrivia;
            updateUser.favorites      = user.favorites;
            updateUser.First_name     = user.First_name;
            updateUser.gender         = user.gender;
            updateUser.glutenfree     = user.glutenfree;
            updateUser.height         = user.height;
            updateUser.Last_name      = user.Last_name;
            updateUser.password       = user.password;
            updateUser.userName       = user.userName;
            updateUser.User_id        = user.User_id;
            updateUser.vegan          = user.vegan;
            updateUser.vegetarian     = user.vegetarian;
            updateUser.weight         = user.weight;
            m.Entry(updateUser).State = System.Data.Entity.EntityState.Modified;

            m.SaveChanges();
        }
コード例 #2
0
        /// <summary>
        /// Gets one user from backend
        /// </summary>
        /// <param name="value">Id of the desired </param>
        /// <returns></returns>
        public string GetUser(int value)
        {
            masterEntities m       = ContextSingleton.getContext();
            var            userlst = from k in m.User where k.User_id == value select k;
            var            user    = new User();

            foreach (var usr in userlst)
            {
                user = usr;
            }
            m.Entry(user).State = System.Data.Entity.EntityState.Detached;
            return(JsonConvert.SerializeObject(user, jsettings));
        }
コード例 #3
0
ファイル: RecipeService.cs プロジェクト: Zeydel/FoodsMedZ
        /// <summary>
        /// Fetches one recipe from database based on id.
        /// </summary>
        /// <param name="id">Id of the desired recipe</param>
        /// <returns>One recipe object</returns>
        public Recipe getRecipe(int id)
        {
            masterEntities m         = ContextSingleton.getContext();
            var            Recipelst = from k in m.Recipe where k.Recipe_id == id select k;
            var            recipe    = new Recipe();

            foreach (var rcp in Recipelst)
            {
                recipe = rcp;
            }
            m.Entry(recipe).State = System.Data.Entity.EntityState.Detached;
            return(recipe);
        }