// GET: Kitchen public ActionResult Index() { KitchenModel objKitchenModel = new KitchenModel(); objKitchenModel.ProductList = new List <ProductItem>(); objSyncFoodContext = new SyncFoodContext(); using (IUnitOfWork unitOfWork = new UnitOfWork(objSyncFoodContext)) { Kitchen objKitchen = unitOfWork.Kitchens.GetKitchenByName(DateTime.Now.ToShortDateString()); int kitchenId = objKitchen.Id; FoodSync.Core.Model.Domain.User objUser = unitOfWork.Users.SingleOrDefault(u => u.UserName == User.Identity.Name); double totalCalloriesInKitchen = 0.0; List <KitchenProduct> lstProductsInKitchen = unitOfWork.Kitchens.GetProductsFromKitchen(kitchenId, objKitchen.Name, objUser.Id); foreach (KitchenProduct product in lstProductsInKitchen) { ProductItem objPI = new ProductItem(); objPI.Id = product.UserKitchenId; objPI.ProductId = product.ProductId; objPI.Name = product.ProductName; objKitchenModel.ProductList.Add(objPI); totalCalloriesInKitchen += product.ProductCallories; } objKitchenModel.TotalCallories = totalCalloriesInKitchen; objKitchenModel.OptimalCalloriesPerDay = objUser.OptimalCalloriesPerDay; } return(View(objKitchenModel)); }
public ActionResult TrainKitchen() { objSyncFoodContext = new SyncFoodContext(); using (IUnitOfWork unitOfWork = new UnitOfWork(objSyncFoodContext)) { FoodSync.Core.Model.Domain.User objUser = unitOfWork.Users.SingleOrDefault(u => u.UserName == User.Identity.Name); List <UserKitchen> lstUserKitchen = unitOfWork.Kitchens.GetLatestProductFromKitchen(DateTime.Today.ToShortDateString(), objUser.Id); List <int> lstUniqueProducts = new List <int>(); string latestRecord = lstUserKitchen[0].Name; if (latestRecord != DateTime.Today.ToShortDateString()) { foreach (UserKitchen item in lstUserKitchen) { if (lstUniqueProducts.Contains(item.ProductId)) { continue; } lstUniqueProducts.Add(item.ProductId); } foreach (var productId in lstUniqueProducts) { int quantity = unitOfWork.Kitchens.GetNumberOfItems(latestRecord, objUser.Id, productId); unitOfWork.DataSet.AddTrainingSet(objUser.Id, (int)DateTime.Today.DayOfWeek, 0, quantity, DateTime.Today.ToShortDateString()); } //Save the Kitchen //unitOfWork.DataSet.AddTrainingSet(objUser.Id,(int)DateTime.Today.DayOfWeek,0,) } } return(Redirect("Index")); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); FoodSync.Core.Model.Domain.User objNewUser = new FoodSync.Core.Model.Domain.User(); objNewUser.FirstName = model.FirstName; objNewUser.LastName = model.LastName; objNewUser.UserName = model.Email; objNewUser.Password = model.Password; objNewUser.BloodType = FoodSync.Core.Model.Domain.Enums.BloodType.A; objNewUser.Country = "Macedonia"; objNewUser.DateOfBirth = new DateTime(1987, 9, 16); objNewUser.fk_user_id = user.Id; objNewUser.Gender = FoodSync.Core.Model.Domain.Enums.Gender.Male; objNewUser.Height = 0; objNewUser.Weight = 0; objNewUser.ImageFilePath = ""; objNewUser.fk_user_id = user.Id; objNewUser.OptimalCalloriesPerDay = 0; objNewUser.CurrentActivity = String.Empty; SyncFoodContext objSyncFoodContext = new SyncFoodContext(); using (IUnitOfWork unitOfWork = new UnitOfWork(objSyncFoodContext)) { unitOfWork.Users.Add(objNewUser); unitOfWork.Complete(); } return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
// GET: EditUser public ActionResult Index() { if (Request.IsAuthenticated) { string userName = User.Identity.Name; using (IUnitOfWork unitOfWork = new UnitOfWork(objSyncFoodContext)) { FoodSync.Core.Model.Domain.User objUser = unitOfWork.Users.SingleOrDefault(user => user.UserName == userName); if (objUser != null) { EditUserModel objUserModel = new EditUserModel(); objUserModel.FirstName = objUser.FirstName; objUserModel.LastName = objUser.LastName; objUserModel.Country = objUser.Country; objUserModel.Gender = (int)objUser.Gender; objUserModel.Height = objUser.Height; objUserModel.Weight = objUser.Weight; objUserModel.DateOfBirth = objUser.DateOfBirth.ToShortDateString(); objUserModel.SelectedActivity = objUser.CurrentActivity; List <Activity> lstActivities = unitOfWork.Activity.GetAllActivities(); List <SelectListItem> lstItems = new List <SelectListItem>(); List <string> lstA = new List <string>(); //IEnumerable<SelectListItem> lstItems = new IEnumerable<SelectListItem>(); foreach (Activity activity in lstActivities) { lstA.Add(activity.Name); SelectListItem objNewItem = new SelectListItem(); objNewItem.Text = activity.Name; objNewItem.Value = activity.Name; if (activity.Name == objUser.CurrentActivity) { objNewItem.Selected = true; } else { objNewItem.Selected = false; } lstItems.Add(objNewItem); } objUserModel.ActivityList = new SelectList(lstItems.ToArray()); objUserModel.ActivityList2 = lstA; return(View(objUserModel)); } } } return(RedirectToAction("Index", "Home")); }
public ActionResult ProposeRecipe() { string productName = String.Empty; if (Session[ProductModel.SessionName] != null) { productName = Session[ProductModel.SessionName].ToString(); } TopUserInfo objTUI = null; objSyncFoodContext = new SyncFoodContext(); using (IUnitOfWork unitOfWork = new UnitOfWork(objSyncFoodContext)) { FoodSync.Core.Model.Domain.User objUser = unitOfWork.Users.SingleOrDefault(u => u.UserName == User.Identity.Name); if (Session[TopUserInfo.SessionName] != null) { objTUI = Session[TopUserInfo.SessionName] as TopUserInfo; objTUI.lstRecipes = new List <RecipeModel>(); List <KitchenProduct> lstProducts = unitOfWork.Kitchens.GetProductsFromKitchen(DateTime.Today.ToShortDateString(), objUser.Id); List <int> lstOriginals = new List <int>(); foreach (var product in lstProducts) { if (lstOriginals.Contains(product.ProductId)) { continue; } lstOriginals.Add(product.ProductId); List <Recipe> lstR = unitOfWork.Recipes.GetRecipesForProduct(product.ProductId); foreach (var itemR in lstR) { RecipeModel objNewRecipe = new RecipeModel(); objNewRecipe.RecipeName = itemR.RecipeName; objNewRecipe.RecipeDescription = itemR.Instructions; objTUI.lstRecipes.Add(objNewRecipe); } } } } return(RedirectToAction("Index")); }
public ActionResult AddToKitchen() { string productName = String.Empty; if (Session[ProductModel.SessionName] != null) { productName = Session[ProductModel.SessionName].ToString(); } KitchenModel objKitchenModel = new KitchenModel(); objSyncFoodContext = new SyncFoodContext(); using (IUnitOfWork unitOfWork = new UnitOfWork(objSyncFoodContext)) { Product objProduct = unitOfWork.Products.GetProductByName(productName); FoodSync.Core.Model.Domain.User objUser = unitOfWork.Users.SingleOrDefault(u => u.UserName == User.Identity.Name); Kitchen objKitchen = unitOfWork.Kitchens.GetKitchenByName(DateTime.Now.ToShortDateString()); if (objKitchen == null) { objKitchen = new Kitchen(); objKitchen.Name = DateTime.Today.ToShortDateString(); unitOfWork.Kitchens.Add(objKitchen); unitOfWork.Complete(); } if (objProduct == null) { return(RedirectToAction("Index", "Home")); } int kitchenId = objKitchen.Id; int userId = objUser.Id; int productId = objProduct.Id; bool userKitchenExists = unitOfWork.Kitchens.UserKitchenExists(userId, kitchenId); if (userKitchenExists) { unitOfWork.Kitchens.AddProductToKitchen(productId, userId, kitchenId, DateTime.Today.ToShortDateString()); /* * objKitchenModel.ProductList = new List<ProductItem>(); * List<KitchenProduct> lstProductsInKitchen = unitOfWork.Kitchens.GetProductsFromKitchen(kitchenId, objKitchen.Name); * foreach (KitchenProduct product in lstProductsInKitchen) * { * ProductItem objPI = new ProductItem(); * objPI.Id = product.UserKitchenId; * objPI.ProductId = product.ProductId; * objPI.Name = product.ProductName; * objKitchenModel.ProductList.Add(objPI); * } */ } else { unitOfWork.Kitchens.AddProductToKitchen(productId, userId, objKitchen.Id, DateTime.Today.ToShortDateString()); /* * objKitchenModel.ProductList = new List<ProductItem>(); * List<KitchenProduct> lstProductsInKitchen = unitOfWork.Kitchens.GetProductsFromKitchen(kitchenId, objKitchen.Name); * foreach (KitchenProduct product in lstProductsInKitchen) * { * ProductItem objPI = new ProductItem(); * objPI.Id = product.UserKitchenId; * objPI.ProductId = product.ProductId; * objPI.Name = product.ProductName; * objKitchenModel.ProductList.Add(objPI); * } */ } if (unitOfWork.DataSet.Exists(objUser.Id, DateTime.Today.ToShortDateString())) { unitOfWork.DataSet.UpdateTrainingSet(objUser.Id, DateTime.Today.ToShortDateString(), 1); } else { unitOfWork.DataSet.AddTrainingSet(objUser.Id, (int)DateTime.Now.DayOfWeek, 0, 1, DateTime.Today.ToShortDateString()); } objKitchenModel.Name = objProduct.Name; } return(RedirectToAction("Index")); }
public ActionResult Index() { if (Request.IsAuthenticated) { objSyncFoodContext = new SyncFoodContext(); using (IUnitOfWork unitOfWork = new UnitOfWork(objSyncFoodContext)) { FoodSync.Core.Model.Domain.User objUser = unitOfWork.Users.SingleOrDefault(user => user.UserName == User.Identity.Name); if (objUser != null) { TopUserInfo objTUI = null; if (Session[TopUserInfo.SessionName] != null) { objTUI = (TopUserInfo)Session[TopUserInfo.SessionName]; } else { objTUI = new TopUserInfo(); } objTUI.Name = String.Format("{0} {1}", objUser.FirstName, objUser.LastName); objTUI.OptimalCalloriesPerDay = objUser.OptimalCalloriesPerDay; DateTime now = DateTime.Today; objTUI.Age = now.Year - objUser.DateOfBirth.Year; objTUI.Height = objUser.Height; objTUI.Weight = objUser.Weight; string[] files = Directory.GetFiles(Server.MapPath("~/Images")); if (files.Length == 1) { objTUI.ImagePath = files[0]; Python.Python objPython = new Python.Python(); string classifierPath = @"C:\Users\Vancho\Desktop\NASA Space App\Python\Food Classifier"; string recognizedProductClass = objPython.ProcessImage(files[0], "SyncFoodClassifier.py", classifierPath); string condition = "fresh"; //nemame rasipani od drugite proizvodi if (recognizedProductClass == "banana") { condition = objPython.ProcessImage(files[0], "SpoiledClassifier.py", @"C:\Users\Vancho\Desktop\NASA Space App\Python\Spoiled Classifier"); } Product objProduct = unitOfWork.Products.GetProductByName(recognizedProductClass); ProductModel objProductModel = new ProductModel(); objProductModel.Name = String.Empty; if (objProduct != null) { objProductModel.Name = objProduct.Name; objProductModel.ProductInfo = objProduct.Info; objProductModel.Callories = objProduct.Calories.ToString(); objProductModel.Season = objProduct.Season.ToString(); objProductModel.ShelfLife = objProduct.ShelfLife.ToString() + " days"; objProductModel.Condition = condition; objProductModel.CarbonFootPrint = objProduct.CarbonFootPrint.ToString(); objProductModel.Allergens = objProduct.Allergens.ToString(); objProductModel.Hazards = objProduct.Hazards.ToString(); Session[ProductModel.SessionName] = objProduct.Name; } objTUI.Product = objProductModel; objTUI.ImagePath = String.Format("~/Images/Product.jpg?t={0}", DateTime.Now.ToShortTimeString()); } //Proveri za recepti objTUI.lstRecipes = new List <RecipeModel>(); List <KitchenProduct> lstProducts = unitOfWork.Kitchens.GetProductsFromKitchen(DateTime.Today.ToShortDateString(), objUser.Id); List <int> lstOriginals = new List <int>(); foreach (var product in lstProducts) { if (lstOriginals.Contains(product.ProductId)) { continue; } lstOriginals.Add(product.ProductId); List <Recipe> lstR = unitOfWork.Recipes.GetRecipesForProduct(product.ProductId); foreach (var itemR in lstR) { RecipeModel objNewRecipe = new RecipeModel(); objNewRecipe.RecipeName = itemR.RecipeName; objNewRecipe.RecipeDescription = itemR.Instructions; objTUI.lstRecipes.Add(objNewRecipe); } } Session[TopUserInfo.SessionName] = objTUI; return(View(objTUI)); } } } return(View()); }