예제 #1
0
        // Creates a recipe that will be used to update the containers
        // meaning that the amounts of all dry ingredients are in grams
        // and the liquid ingredients are in ml
        private void CreateConvertedRecipe()
        {
            ConvertedRecipe         = new UserRecipe();
            ConvertedRecipe.UserID  = Recipe.UserID;
            ConvertedRecipe.LastUse = Recipe.LastUse;

            ConvertedRecipe.Ingredient1 = Recipe.Ingredient1;
            ConvertedRecipe.Amount1     = Recipe.Amount1;
            if (Recipe.Type1 != "gr")
            {
                ConvertedRecipe.Amount1 = App.Ingredients.ConvertToGr(Recipe.Ingredient1, Recipe.Amount1, Recipe.Type1);
            }
            ConvertedRecipe.Type1 = "gr";

            ConvertedRecipe.Ingredient2 = Recipe.Ingredient2;
            ConvertedRecipe.Amount2     = Recipe.Amount2;
            if (Recipe.Type2 != "gr")
            {
                ConvertedRecipe.Amount2 = App.Ingredients.ConvertToGr(Recipe.Ingredient2, Recipe.Amount2, Recipe.Type2);
            }
            ConvertedRecipe.Type2 = "gr";

            ConvertedRecipe.Ingredient3 = Recipe.Ingredient3;
            ConvertedRecipe.Amount3     = Recipe.Amount3;
            if (Recipe.Type3 != "gr")
            {
                ConvertedRecipe.Amount3 = App.Ingredients.ConvertToGr(Recipe.Ingredient3, Recipe.Amount3, Recipe.Type3);
            }
            ConvertedRecipe.Type3 = "gr";

            ConvertedRecipe.Ingredient4 = Recipe.Ingredient4;
            ConvertedRecipe.Amount4     = Recipe.Amount4;
            if (Recipe.Type4 != "gr")
            {
                ConvertedRecipe.Amount4 = App.Ingredients.ConvertToGr(Recipe.Ingredient4, Recipe.Amount4, Recipe.Type4);
            }
            ConvertedRecipe.Type4 = "gr";

            ConvertedRecipe.Ingredient5 = Recipe.Ingredient5;
            ConvertedRecipe.Amount5     = Recipe.Amount5;
            if (Recipe.Type5 != "gr")
            {
                ConvertedRecipe.Amount5 = App.Ingredients.ConvertToGr(Recipe.Ingredient5, Recipe.Amount5, Recipe.Type5);
            }
            ConvertedRecipe.Type5 = "gr";

            ConvertedRecipe.Ingredient6 = Recipe.Ingredient6;
            ConvertedRecipe.Amount6     = Recipe.Amount6;
            if (Recipe.Type6 != "gr")
            {
                ConvertedRecipe.Amount6 = App.Ingredients.ConvertToGr(Recipe.Ingredient6, Recipe.Amount6, Recipe.Type6);
            }
            ConvertedRecipe.Type6 = "gr";

            ConvertedRecipe.Ingredient7 = Recipe.Ingredient7;
            ConvertedRecipe.Amount7     = App.Ingredients.ConvertToMl(Recipe.Ingredient7, Recipe.Amount7);

            ConvertedRecipe.Ingredient8 = Recipe.Ingredient8;
            ConvertedRecipe.Amount8     = App.Ingredients.ConvertToMl(Recipe.Ingredient8, Recipe.Amount8);
        }
예제 #2
0
        public ActionResult Create([Bind(Include = "RecipeId,RecipeName")] Recipe recipe)
        {
            string user = this.Session["Username"] as string;

            if (ModelState.IsValid)
            {
                int userId = db.Users.Where(u => u.Username.Equals(user)).Single().UserId;


                bool recipeExists = db.Recipes.Where(r => r.RecipeName.Equals(recipe.RecipeName)).Count() == 1 ? true : false;
                if (!recipeExists)
                {
                    //System.Diagnostics.Debug.WriteLine("Doesn't exist");
                    db.Recipes.Add(recipe);
                    db.SaveChanges();
                }

                UserRecipe userRecipe = new UserRecipe()
                {
                    UserId   = db.Users.Single(u => u.Username.Equals(user)).UserId,
                    RecipeId = db.Recipes.Single(r => r.RecipeName.Equals(recipe.RecipeName)).RecipeId
                };

                db.UserRecipes.Add(userRecipe);

                db.SaveChanges();
                return(RedirectToAction("Index", "Users"));
            }

            return(View(recipe));
        }
예제 #3
0
        public void Save(string username, int id)
        {
            var user = this.dbContext
                       .Users
                       .FirstOrDefault(u => u.UserName == username);

            if (user == null)
            {
                throw new ArgumentNullException("User not found");
            }

            var recipe = this.dbContext
                         .Recipes
                         .Find(id);

            if (recipe == null)
            {
                throw new ArgumentNullException("Recipe not found");
            }

            var userRecipe = new UserRecipe
            {
                User   = user,
                Recipe = recipe
            };

            this.dbContext.Add(userRecipe);
            user.SavedRecipes.Add(userRecipe);

            this.dbContext.SaveChanges();
        }
        public void LikeRecipe(int recipeId, User user)
        {
            var recipe = recipeContext.Recipes.Include(x => x.RecipeLikes).Include(x => x.User).FirstOrDefault(x => x.Id == recipeId);

            if (recipe == null)
            {
                return;
            }

            if (IsUserLiked(recipeId, user.Id))
            {
                var olds = recipe.RecipeLikes.Where(x => x.RecipeId == recipeId && x.UserId == user.Id).ToArray();
                foreach (var item in olds)
                {
                    recipe.RecipeLikes.Remove(item);
                }
                recipeContext.SaveChanges();
            }
            else
            {
                UserRecipe ur = new UserRecipe {
                    Recipe = recipe, User = user
                };
                recipe.RecipeLikes.Add(ur);
                recipeContext.SaveChanges();

                var obj = RecipeJungle.Controllers.UsersController.notifications;
                obj[recipe.User.Username] = user.Username;
            }
        }
예제 #5
0
        public async Task <RecipeServiceModel> GetRecommendedRecipeAsync(string userId)
        {
            var random = new Random();

            var filteredRecipes = await(await this.recipeService
                                        .GetAllFilteredAsync(userId))
                                  .OrderBy(x => random.Next())
                                  .Take(MaxIterationsCount)
                                  .ToListAsync();

            var userRecipe = new UserRecipe()
            {
                UserId = userId,
            };

            for (int i = 0; i < filteredRecipes.Count; i++)
            {
                userRecipe.RecipeId = filteredRecipes[i].Id;
                var prediction = this.predictionEnginePool.Predict <UserRecipe, UserRecipeScore>(userRecipe);

                if (prediction.Score >= MinPredictionScore ||
                    i == filteredRecipes.Count - 1)
                {
                    return(filteredRecipes[i]);
                }
            }

            return(new RecipeServiceModel());
        }
예제 #6
0
파일: UserDatabase.cs 프로젝트: avidvid/OUP
    internal void UpdateUserRecipe(UserRecipe userRecipe)
    {
        for (int i = 0; i < _userRecipes.Count; i++)
        {
            if (_userRecipes[i].Id == userRecipe.Id)
            {
                _userRecipes[i].RecipeCode = "";
                for (int j = 0; j < _myRecipes.Count; j++)
                {
                    if (_myRecipes[j].Id == _userRecipes[i].RecipeId)
                    {
                        _myRecipes[j].IsEnable = true;
                        var recipeHandler = FindObjectOfType(typeof(RecipeListHandler)) as RecipeListHandler;
                        if (recipeHandler != null)
                        {
                            recipeHandler.SceneRefresh = true;
                        }
                        return;
                    }
                }
            }
        }
        _userRecipes.Add(userRecipe);
        var    itemDatabase = ItemDatabase.Instance();
        Recipe recipe       = itemDatabase.GetRecipeById(userRecipe.RecipeId);

        _myRecipes.Add(recipe);
    }
예제 #7
0
파일: RecipeHandling.cs 프로젝트: Yusoi/LI4
        public void resetRecipe(int userID, int recipeID)
        {
            var oldr       = _context.Recipe.Find(recipeID);
            var recipebook = _context.RecipeBook.Find(oldr.recipeID, userID);

            if (recipebook != null)
            {
                _context.RecipeBook.Remove(recipebook);
                _context.SaveChanges();
            }
            if (oldr.original != -1)
            {
                cleanNotOriginalRecipe(oldr.recipeID);
                UserRecipe ur = _context.UserRecipe.Find(recipeID, userID);
                if (ur != null)
                {
                    _context.UserRecipe.Remove(ur);
                    _context.SaveChanges();
                }
                _context.Recipe.Remove(oldr);
                _context.SaveChanges();
            }
            RecipeBook rb    = new RecipeBook(oldr.original, userID);
            var        rbori = _context.RecipeBook.Find(oldr.original, userID);

            if (rbori == null)
            {
                _context.RecipeBook.Add(rb);
                _context.SaveChanges();
            }
        }
예제 #8
0
        public async Task <UserRecipe> AddOrUpdateUserRecipe(UserRecipe recipe, string userName)
        {
            if (recipe.Id == null)
            {
                var allUsers = await _applicationUserRepo.GetAll();

                recipe.UserId = Guid.Parse(allUsers.FirstOrDefault(m => m.UserName == userName).Id);
                // new insertion
                return(await(_mapper.Map(await _userRecipeRepo.Insert(await _mapper.Map(recipe)))));
            }
            else
            {
                var oldRecipe = await _userRecipeRepo.Get(int.Parse(recipe.Id.ToString()));

                oldRecipe.Id     = int.Parse(recipe.Id.ToString());
                oldRecipe.Name   = recipe.Name;
                oldRecipe.UserId = Guid.Parse(recipe.UserId.ToString());
                oldRecipe.EstimatedCookingTime = recipe.EstimatedCookingTime;
                oldRecipe.IngredientsList      = recipe.IngredientsList;
                oldRecipe.IsGlutenFree         = recipe.IsGlutenFree;
                oldRecipe.IsVegan  = recipe.IsVegan;
                oldRecipe.Category = recipe.Category;
                return(await _mapper.Map(oldRecipe));
            }
        }
예제 #9
0
        public IActionResult UserRecipe(string Title)
        {
            int?       UserId = HttpContext.Session.GetInt32("UserId");
            User       User   = dbContext.Users.Include(user => user.Ratings).FirstOrDefault(user => user.UserId == UserId);
            UserRecipe Recipe = dbContext.UserRecipes.Include(recipe => recipe.User).Include(recipe => recipe.Ratings).Include(recipe => recipe.Likes).Include(recipe => recipe.Comments).FirstOrDefault(recipe => recipe.Title == Title);
            bool       Liked  = false;

            if (Recipe != null)
            {
                if (User != null)
                {
                    Rating Rating = User.Ratings.FirstOrDefault(rating => rating.RecipeId == Recipe.RecipeId);
                    ViewBag.Rating = Rating;
                    if (Recipe.Likes.FirstOrDefault(like => like.UserId == UserId) != null)
                    {
                        Liked        = true;
                        ViewBag.Like = Recipe.Likes.FirstOrDefault(like => like.UserId == UserId);
                    }
                }
                List <Comment> Comments = dbContext.Comments.Include(comment => comment.Recipe).Include(comment => comment.User).Where(comment => comment.RecipeId == Recipe.RecipeId).ToList();
                Comments.Reverse();
                ViewBag.Comments = Comments;
                ViewBag.User     = User;
                ViewBag.Liked    = Liked;
                ViewBag.Recipe   = Recipe;
                ViewBag.Title    = Recipe.Title;
                return(View());
            }
            return(RedirectToAction("UserRecipes", "Home"));
        }
예제 #10
0
        public UserRecipe AddRecipe(UserRecipe recipe)
        {
            UserRecipe convertedRecipe = new UserRecipe();

            var httpWebRequest = (HttpWebRequest)WebRequest.Create(addOrUpdateUrl);

            httpWebRequest.ContentType = "application/json; charset=utf-8";
            httpWebRequest.Method      = "POST";
            httpWebRequest.Accept      = "application/json; charset=utf-8";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                string jsonOutput = JsonConvert.SerializeObject(recipe);

                streamWriter.Write(jsonOutput);
                streamWriter.Flush();
                streamWriter.Close();

                try
                {
                    HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                    {
                        var result = streamReader.ReadToEnd();
                        convertedRecipe = JsonConvert.DeserializeObject <UserRecipe>(result.ToString());
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
            }

            return(convertedRecipe);
        }
예제 #11
0
        public ActionResult DeleteConfirmed(string id)
        {
            UserRecipe userRecipe = db.UserRecipes.Find(id, User.Identity.Name);

            db.UserRecipes.Remove(userRecipe);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #12
0
파일: RecipeHandling.cs 프로젝트: Yusoi/LI4
        public void setRecipeRating(int UserID, int RecipeID, char rating)
        {
            var userRecipe = _context.UserRecipe.Find(UserID, RecipeID);

            if (userRecipe == null)
            {
                UserRecipe urecipe = new UserRecipe(UserID, RecipeID, rating);
                _context.UserRecipe.Add(urecipe);
                _context.SaveChanges();
            }
        }
예제 #13
0
        public async Task AddRecipeToUser(string recipeId, string userId)
        {
            var userRecipe = new UserRecipe
            {
                RecipeId = recipeId,
                UserId   = userId,
            };

            await this.userRecipesRepository.AddAsync(userRecipe);

            await this.userRecipesRepository.SaveChangesAsync();
        }
예제 #14
0
        // Creates a recipe that will be used to create the command to send to the machine
        // meaning that the amounts of the first 3 ingredients are in grams,
        // and the amount of the last 3 ingredients are in tsp
        private void CreateCommandRecipe()
        {
            if (ConvertedRecipe == null)
            {
                CreateConvertedRecipe();
            }

            CommandRecipe         = new UserRecipe();
            CommandRecipe.UserID  = Recipe.UserID;
            CommandRecipe.LastUse = Recipe.LastUse;

            CommandRecipe.Ingredient1 = Recipe.Ingredient1;
            CommandRecipe.Amount1     = ConvertedRecipe.Amount1;
            CommandRecipe.Type1       = "gr";

            CommandRecipe.Ingredient2 = Recipe.Ingredient2;
            CommandRecipe.Amount2     = ConvertedRecipe.Amount2;
            CommandRecipe.Type2       = "gr";

            CommandRecipe.Ingredient3 = Recipe.Ingredient3;
            CommandRecipe.Amount3     = ConvertedRecipe.Amount3;
            CommandRecipe.Type3       = "gr";

            CommandRecipe.Ingredient4 = Recipe.Ingredient4;
            CommandRecipe.Amount4     = Recipe.Amount4;
            if (Recipe.Type4 != "tsp")
            {
                CommandRecipe.Amount4 = App.Ingredients.ConvertToTsp(Recipe.Ingredient4, Recipe.Amount4, Recipe.Type4);
            }
            CommandRecipe.Type4 = "tsp";

            CommandRecipe.Ingredient5 = Recipe.Ingredient5;
            CommandRecipe.Amount5     = Recipe.Amount5;
            if (Recipe.Type5 != "tsp")
            {
                CommandRecipe.Amount5 = App.Ingredients.ConvertToTsp(Recipe.Ingredient5, Recipe.Amount5, Recipe.Type5);
            }
            CommandRecipe.Type5 = "tsp";

            CommandRecipe.Ingredient6 = Recipe.Ingredient6;
            CommandRecipe.Amount6     = Recipe.Amount6;
            if (Recipe.Type6 != "tsp")
            {
                CommandRecipe.Amount6 = App.Ingredients.ConvertToTsp(Recipe.Ingredient6, Recipe.Amount6, Recipe.Type6);
            }
            CommandRecipe.Type6 = "tsp";

            CommandRecipe.Ingredient7 = Recipe.Ingredient7;
            CommandRecipe.Amount7     = Recipe.Amount7;

            CommandRecipe.Ingredient8 = Recipe.Ingredient8;
            CommandRecipe.Amount8     = Recipe.Amount8;
        }
예제 #15
0
        public IActionResult AddToFavourites(int recipeId)
        {
            var userRecipe = new UserRecipe
            {
                UserId = User.FindFirstValue(ClaimTypes.NameIdentifier)
                ,
                RecipeId = recipeId
            };

            _userRecipeData.Add(userRecipe);
            _userRecipeData.Commit();
            return(RedirectToAction(nameof(Index)));
        }
예제 #16
0
 //Save the user recipe to the local database
 public Task SaveRecipeAsync(UserRecipe recipe)
 {
     if (recipe.Id != null)
     {
         return(database.UpdateAsync(recipe));
     }
     else
     {
         //generate id before saving
         recipe.Id = DateTime.Now.GetHashCode().ToString();
         return(database.InsertAsync(recipe));
     }
 }
예제 #17
0
        public IActionResult MakeRecipeAdminRecipe(string Title)
        {
            int? AdminId = HttpContext.Session.GetInt32("UserId");
            User Admin   = dbContext.Users.FirstOrDefault(user => user.UserId == AdminId);

            if (Admin != null && Admin.AdminState == 1)
            {
                UserRecipe Recipe = dbContext.UserRecipes.FirstOrDefault(recipe => recipe.Title == Title);
                ViewBag.Recipe = Recipe;
                ViewBag.Title  = "Make Recipe Into an Admin Recipe";
                return(View());
            }
            return(RedirectToAction("Index", "Home"));
        }
예제 #18
0
        public IActionResult UnLikeUserRecipe(int RecipeId)
        {
            int?       UserId = HttpContext.Session.GetInt32("UserId");
            User       User   = dbContext.Users.Include(user => user.Likes).FirstOrDefault(user => user.UserId == UserId);
            UserRecipe Recipe = dbContext.UserRecipes.FirstOrDefault(recipe => recipe.RecipeId == RecipeId);

            if (User != null)
            {
                Like Like = User.Likes.FirstOrDefault(like => like.RecipeId == RecipeId);
                dbContext.Remove(Like);
                dbContext.SaveChanges();
            }
            return(RedirectToAction("UserRecipe", new { Title = Recipe.Title }));
        }
예제 #19
0
        // Checks for each ingredient that is in the recipe if it is in one of the containers or not
        // Returns false if there is an ingredient that is not in one of the containers
        // Otherwise, returns true
        private bool CheckIfRecipeIsPossible(UserRecipe recipe)
        {
            bool possible   = true;
            var  containers = App.Containers.GetContainers();

            possible = possible && CheckIngredientInContainers(containers, recipe.Ingredient1);
            possible = possible && CheckIngredientInContainers(containers, recipe.Ingredient2);
            possible = possible && CheckIngredientInContainers(containers, recipe.Ingredient3);
            possible = possible && CheckIngredientInContainers(containers, recipe.Ingredient4);
            possible = possible && CheckIngredientInContainers(containers, recipe.Ingredient5);
            possible = possible && CheckIngredientInContainers(containers, recipe.Ingredient6);

            return(possible);
        }
예제 #20
0
        public IActionResult DeleteCommentOnUserRecipe(int RecipeId, int CommentId)
        {
            int?       UserId  = HttpContext.Session.GetInt32("UserId");
            User       User    = dbContext.Users.FirstOrDefault(user => user.UserId == UserId);
            UserRecipe Recipe  = dbContext.UserRecipes.FirstOrDefault(recipe => recipe.RecipeId == RecipeId);
            Comment    Comment = dbContext.Comments.FirstOrDefault(comment => comment.CommentId == CommentId);

            if (UserId != Comment.UserId || User.AdminState != 1)
            {
                dbContext.Remove(Comment);
                dbContext.SaveChanges();
            }
            return(RedirectToAction("UserRecipe", new { Title = Recipe.Title }));
        }
예제 #21
0
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserRecipe userRecipe = db.UserRecipes.Find(id, User.Identity.Name);

            if (userRecipe == null)
            {
                return(HttpNotFound());
            }

            return(View(userRecipe));
        }
        public bool CreateUserRecipeAuto(Recipe entity)
        {
            var userRecipe =
                new UserRecipe
            {
                RecipeId = entity.RecipeId,
                UserId   = entity.UserId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.UserRecipes.Add(userRecipe);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #23
0
        public async Task <IActionResult> PostUserRecipeAsync(UserRecipe Recipe)
        {
            int? UserId = HttpContext.Session.GetInt32("UserId");
            User User   = dbContext.Users.FirstOrDefault(user => user.UserId == UserId);

            if (User != null)
            {
                if (User.AdminState != 1)
                {
                    Recipe.UserId = User.UserId;
                    if (dbContext.Recipes.Any(recipe => recipe.Title == Recipe.Title))
                    {
                        ModelState.AddModelError("Title", "A recipe already has that title");
                        return(View("NewUserRecipe"));
                    }
                    if (Recipe.UploadPicture != null)
                    {
                        var container = Recipe.GetBlobContainer(configuration.GetSection("PictureBlobInfo:AzureStorageConnectionString").Value, "foodforumpictures");
                        var Content   = ContentDispositionHeaderValue.Parse(Recipe.UploadPicture.ContentDisposition);
                        var FileName  = Content.FileName.ToString().Trim('"');
                        var blockBlob = container.GetBlockBlobReference(FileName);
                        BlobRequestOptions options = new BlobRequestOptions();
                        options.SingleBlobUploadThresholdInBytes = 16777216;
                        await blockBlob.UploadFromStreamAsync(Recipe.UploadPicture.OpenReadStream());

                        Recipe.PictureURL = blockBlob.Uri.AbsoluteUri;
                    }
                    string check = RegexCheck(Recipe, RegEx);
                    if (check != null)
                    {
                        ModelState.AddModelError(check, "Please use only letters, numbers, periods, commas, hyphens, or exclamation points");
                    }
                    if (ModelState.IsValid)
                    {
                        if (!dbContext.Recipes.Any(recipe => recipe.PictureURL == Recipe.PictureURL) || Recipe.PictureURL == null)
                        {
                            dbContext.Add(Recipe);
                            dbContext.SaveChanges();
                            return(RedirectToAction("UserRecipes", "Home"));
                        }
                        ModelState.AddModelError("UploadPicture", "A recipe already has a picture with that file name, please rename it and try again");
                    }
                    return(View("NewUserRecipe"));
                }
            }
            return(RedirectToAction("UserRecipes", "Home"));
        }
예제 #24
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var recipe = await _context.Recipes.FindAsync(request.Id);

                if (recipe == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { Recipe = "Could not find Recipe" });
                }

                var user = await _context.Users.SingleOrDefaultAsync(x =>
                                                                     x.UserName == _userAccessor.GetCurrentUsername());

                var following = await _context.UserRecipes
                                .SingleOrDefaultAsync(x =>
                                                      x.RecipeId == recipe.Id &&
                                                      x.AppUserId == user.Id);

                if (following != null)
                {
                    throw new RestException(HttpStatusCode.BadRequest, new { Recipe = "Already following this Recipe" });
                }

                if (recipe.IsPrivate)
                {
                    throw new RestException(HttpStatusCode.BadRequest, new { Recipe = "This Recipe is private" });
                }

                following = new UserRecipe
                {
                    Recipe    = recipe,
                    AppUser   = user,
                    IsCreator = false,
                    DateAdded = DateTime.Now
                };

                _context.UserRecipes.Add(following);

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new System.Exception("Problem saving changes");
            }
예제 #25
0
        public IActionResult UpdateUserRecipe(string Title)
        {
            int? UserId = HttpContext.Session.GetInt32("UserId");
            User User   = dbContext.Users.FirstOrDefault(user => user.UserId == UserId);

            if (User != null)
            {
                UserRecipe Recipe = dbContext.UserRecipes.Include(recipe => recipe.User).FirstOrDefault(recipe => recipe.Title == Title);
                if (Recipe != null && Recipe.UserId == UserId || User.AdminState == 1)
                {
                    ViewBag.Recipe = Recipe;
                    ViewBag.Title  = "Update User Recipe";
                    return(View());
                }
            }
            return(RedirectToAction("UserRecipes"));
        }
예제 #26
0
        public IActionResult DeleteUserRecipe(int RecipeId)
        {
            int?       UserId = HttpContext.Session.GetInt32("UserId");
            User       User   = dbContext.Users.FirstOrDefault(user => user.UserId == UserId);
            UserRecipe Recipe = dbContext.UserRecipes.FirstOrDefault(recipe => recipe.RecipeId == RecipeId);

            if (User != null)
            {
                if (Recipe.UserId == UserId || User.AdminState == 1)
                {
                    dbContext.Remove(Recipe);
                    dbContext.SaveChanges();
                    return(RedirectToAction("UserRecipes", "Home"));
                }
            }
            return(RedirectToAction("UserRecipe", new { Title = Recipe.Title }));
        }
        public bool CreateUserRecipe(UserRecipeCreate model)
        {
            var entity =
                new UserRecipe()
            {
                RecipeId       = model.RecipeId,
                UserId         = _userId.ToString(),
                AddToFavorites = model.AddToFavorites,
                //Notes = model.Notes,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.UserRecipes.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #28
0
    internal void PutUserRecipe(UserRecipe userRecipe, string code = null)
    {
        _apiGate = "GetUserRecipes";
        _uri     = String.Format(ApiPath + ApiStage + _apiGate + "?id={0}", userRecipe.Id.ToString());
        ApiRequest ap = new ApiRequest
        {
            Action     = "Insert",
            UserRecipe = userRecipe
        };

        if (code != null)
        {
            ap.Action = "Update";
            ap.Code   = code;
        }
        Debug.Log(ap.Action + " UserRecipe : " + userRecipe.MyInfo());
        StartCoroutine(PutRequest(_uri, ap, true));
    }
예제 #29
0
파일: UserDatabase.cs 프로젝트: avidvid/OUP
    internal bool AddNewRandomUserRecipe()
    {
        var        itemDatabase    = ItemDatabase.Instance();
        var        recipes         = itemDatabase.GetRecipes();
        List <int> availableRecipe = new List <int>();
        int        key             = DateTime.Now.DayOfYear;
        var        rarity          = RandomHelper.Range(key, (int)DataTypes.Rarity.Common);
        bool       userOwnedRecipe = false;

        for (int i = 0; i < recipes.Count; i++)
        {
            if (recipes[i].IsEnable && !recipes[i].IsPublic)
            {
                if ((int)recipes[i].Rarity < rarity)
                {
                    continue;
                }
                for (int j = 0; j < _userRecipes.Count; j++)
                {
                    if (recipes[i].Id == _userRecipes[j].RecipeId && string.IsNullOrEmpty(_userRecipes[j].RecipeCode))
                    {
                        userOwnedRecipe = true;
                        break;
                    }
                }
                if (!userOwnedRecipe)
                {
                    availableRecipe.Add(recipes[i].Id);
                }
                userOwnedRecipe = false;
            }
        }
        if (availableRecipe.Count > 0)
        {
            var recipeId = availableRecipe[RandomHelper.Range(key, availableRecipe.Count)];
            var ur       = new UserRecipe(recipeId, _userPlayer.Id);
            _userRecipes.Add(ur);
            _xmlHelper.SaveUserRecipes(_userRecipes);
            //_apiGatewayConfig.PutUserRecipe(ur);
            return(true);
        }
        return(false);
    }
예제 #30
0
        public ActionResult DeleteConfirmed(int id)
        {
            string username = this.Session["Username"] as string;
            Recipe recipe   = db.Recipes.Find(id);

            //check associations and remove the link from the user to the recipe
            int        UserId     = db.Users.Where(u => u.Username.Equals(username)).Single().UserId;
            UserRecipe userRecipe = db.UserRecipes.Where(ur => ur.UserId.Equals(UserId) && ur.RecipeId.Equals(id)).Single();
            //only delete the recipe if this was the last/only link
            int linkCount = db.UserRecipes.Where(c => c.RecipeId.Equals(id)).Count();

            if (linkCount <= 1)
            {
                db.Recipes.Remove(recipe);
            }
            db.UserRecipes.Remove(userRecipe);
            db.SaveChanges();
            return(RedirectToAction("Index", "Users"));
        }