示例#1
0
        //SaveDietPlan() saves DietPlan in the database
        public DietPlan SaveDietPlan(DietPlanModel dietPlan)
        {
            //open a connection to a database FitnesspointDatabase
            using (var context = new FitnesspointDatabaseEntities())
            {
                //Creating DietPlan object and assigning data using DietPlanModel class
                DietPlan dietPlan1 = new DietPlan()
                {
                    Slots        = dietPlan.Slots,
                    FoodType     = dietPlan.FoodType,
                    FatRatio     = dietPlan.FatRatio,
                    CarbsRatio   = dietPlan.CarbsRatio,
                    ProteinRatio = dietPlan.ProteinRatio,
                    TotalCalorie = dietPlan.FatRatio + dietPlan.CarbsRatio + dietPlan.ProteinRatio,
                    UserId       = dietPlan.UserId
                };


                //add dietPlan1 to the database DietPlan using model DietPlan
                context.DietPlans.Add(dietPlan1);
                //save the changes to the database
                context.SaveChanges();

                return(dietPlan1);
            }
        }
示例#2
0
        //REGISTERING A USER
        public int AddUser(UserModel model)
        {
            using (var context = new FitnesspointDatabaseEntities())
            {
                UserDetail user = new UserDetail()
                {
                    Name             = model.Name,
                    Gender           = model.Gender,
                    DOB              = model.DOB,
                    Weight           = model.Weight,
                    Height           = model.Height,
                    MedicalCondition = model.MedicalCondition,
                    AllergicTo       = model.AllergicTo,
                    Goal             = model.Goal,
                    Contact          = model.Contact,
                    Email            = model.Email,
                    Username         = model.Username,
                    Password         = model.Password,
                    Role             = model.Role
                };
                context.UserDetails.Add(user);
                context.SaveChanges();

                return(user.UserId);
            }
        }
示例#3
0
        //FindDietPlan() returns the DietPlans based on DietId
        public DietPlanModel FindDietPlan(int diet_id)
        {
            //open a connection to a database FitnesspointDatabase
            using (var context = new FitnesspointDatabaseEntities())
            {
                //retrieving dietPlan from the database DietPlan
                //using model DietPlanModel based on DietId

                var res = context.DietPlans
                          .Where(x => x.DietId == diet_id)
                          .Select(x => new DietPlanModel()
                {
                    DietId       = x.DietId,
                    Slots        = x.Slots,
                    FoodType     = x.FoodType,
                    FatRatio     = x.FatRatio,
                    CarbsRatio   = x.CarbsRatio,
                    ProteinRatio = x.ProteinRatio,
                    TotalCalorie = x.TotalCalorie,
                    UserId       = x.UserId
                }).FirstOrDefault();


                return(res);
            }
        }
示例#4
0
        public ActionResult Login(UserModel model)
        {
            using (var context = new FitnesspointDatabaseEntities())
            {
                bool isvalid = context.UserDetails.Any(x => x.Username == model.Username && x.Password == model.Password && x.Role == "User");

                bool valid = context.UserDetails.Any(x => x.Username == model.Username && x.Password == model.Password && x.Role == "Admin");

                if (isvalid)
                {
                    Session["Username"] = model.Username.ToString();

                    FormsAuthentication.SetAuthCookie(model.Username.ToString(), false);

                    return(RedirectToAction("WelcomeUser", "User"));
                }
                else
                {
                    if (valid)
                    {
                        FormsAuthentication.SetAuthCookie(model.Username, false);

                        return(RedirectToAction("Adminview", "Admin"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "You entered incorrect username or password");
                    }
                }
            }
            return(View());
        }
示例#5
0
        //To check if username already exists.
        public bool UsernameExits(UserModel model)
        {
            bool uniqueUser = true;

            using (var context = new FitnesspointDatabaseEntities())
            {
                UserDetail User = new UserDetail();
                if (context.UserDetails.Any(u => u.Username == model.Username))
                {
                    uniqueUser = false;
                }
            }

            return(uniqueUser);
        }
示例#6
0
        //FindAllWeight() returns the list of WeightLogModel Objects
        public List <WeightLogModel> FindAllWeight()
        {
            //open a connection to a database FitnesspointDatabase
            using (var context = new FitnesspointDatabaseEntities())
            {
                //retrieving weightLog from the database WeightLog using model WeightLogModel in the list form
                var res = context.WeightLogs.Select(x => new WeightLogModel()
                {
                    WeightId   = x.WeightId,
                    Weight     = x.Weight,
                    Created_At = x.Created_At,
                    Updated_At = x.Updated_At,
                    UserId     = x.UserId
                }).ToList();

                return(res);
            }
        }
示例#7
0
 public ActionResult Paid()
 {
     using (var context = new FitnesspointDatabaseEntities())
     {
         PaymentTbl Pay = new PaymentTbl()
         {
             User_id   = (int)TempData["User_id"],
             Plan_id   = (int)TempData["Plan_id"],
             Plan_name = TempData["Plan_name"].ToString(),
             Amount    = (int)TempData["Amount"]
         };
         context.PaymentTbls.Add(Pay);
         context.SaveChanges();
         int Order_id = Pay.Order_id;
         Session["orderid"] = Order_id;
     }
     return(View());
 }
示例#8
0
 //deleteDietPlan() deletes the DietPlans based on DietId and DietPlanModel
 public bool DeleteDietPlan(int diet_id)
 {
     //open a connection to a database FitnesspointDatabase
     using (var context = new FitnesspointDatabaseEntities())
     {
         //retrieving dietPlan from the database DietPlan based on DietId
         var dietPlan1 = context.DietPlans.FirstOrDefault(x => x.DietId == diet_id);
         if (dietPlan1 != null)
         {
             //delete the data if it is present in the database
             context.DietPlans.Remove(dietPlan1);
             //save the changes to the database
             context.SaveChanges();
             //returns true if data is deleted
             return(true);
         }
         //returns false if data is not deleted
         return(false);
     }
 }
示例#9
0
 //UpdateWeight() update the WeightLogs based on WeightId and WeightLogModel
 public bool UpdateWeight(int weight_id, WeightLogModel weight)
 {
     //open a connection to a database FitnesspointDatabase
     using (var context = new FitnesspointDatabaseEntities())
     {
         //retrieving weightLog from the database WeightLog based on WeightId
         var weightLog = context.WeightLogs.FirstOrDefault(x => x.WeightId == weight_id);
         //replace the data in the database with WeightLogModel data based on WeightId
         if (weightLog != null)
         {
             weightLog.Weight     = weight.Weight;
             weightLog.Updated_At = DateTime.UtcNow;
             weightLog.UserId     = weight.UserId;
         }
         //save the changes to the database
         context.SaveChanges();
         //returns true if data is updated
         return(true);
     }
 }
示例#10
0
 //DeleteWeight() deletes the WeightLogs based on WeightId and WeightLogModel
 public bool DeleteWeight(int weight_id)
 {
     //open a connection to a database FitnesspointDatabase
     using (var context = new FitnesspointDatabaseEntities())
     {
         //retrieving weightLog from the database WeightLog based on WeightId
         var weightLog = context.WeightLogs.FirstOrDefault(x => x.WeightId == weight_id);
         if (weightLog != null)
         {
             //delete the data if it is present in the database
             context.WeightLogs.Remove(weightLog);
             //save the changes to the database
             context.SaveChanges();
             //returns true if data is deleted
             return(true);
         }
         //returns false if data is not deleted
         return(false);
     }
 }
        //FindAllNutritionPlan() returns the list of NutritionPlanModel Objects
        public List <NutritionPlanModel> FindAllNutritionPlan()
        {
            //open a connection to a database FitnesspointDatabase
            using (var context = new FitnesspointDatabaseEntities())
            {
                //retrieving nutritionPlan from the database NutritionPlan using model NutritionPlanModel in the list form
                var res = context.NutritionPlans.Select(x => new NutritionPlanModel()
                {
                    NutriPlanId     = x.NutriPlanId,
                    Name            = x.Name,
                    PlanDescription = x.PlanDescription,
                    Created_At      = x.Created_At,
                    Updated_At      = x.Updated_At,
                    Price           = x.Price,
                }).ToList();


                return(res);
            }
        }
 //UpdateNutritionPlan() update the NutritionPlans based on NutriPlanId and NutritionPlanModel
 public bool UpdateNutritionPlan(int plan_id, NutritionPlanModel nutritionPlan)
 {
     //open a connection to a database FitnesspointDatabase
     using (var context = new FitnesspointDatabaseEntities())
     {
         //retrieving nutritionPlan from the database NutritionPlan based on NutriPlanId
         var nutritionPlan1 = context.NutritionPlans.FirstOrDefault(x => x.NutriPlanId == plan_id);
         //replace the data in the database with NutritionPlanModel data based on NutriPlanId
         if (nutritionPlan1 != null)
         {
             nutritionPlan1.Name            = nutritionPlan.Name;
             nutritionPlan1.PlanDescription = nutritionPlan.PlanDescription;
             nutritionPlan1.Updated_At      = DateTime.UtcNow;
             nutritionPlan1.Price           = nutritionPlan.Price;
         }
         //save the changes to the database
         context.SaveChanges();
         //returns true if data is updated
         return(true);
     }
 }
示例#13
0
        //FindAllDietPlan() returns the list of DietPlanModel Objects
        public List <DietPlanModel> FindAllDietPlan()
        {
            //open a connection to a database FitnesspointDatabase
            using (var context = new FitnesspointDatabaseEntities())
            {
                //retrieving dietPlan from the database DietPlan using model DietPlanModel in the list form
                var res = context.DietPlans.Select(x => new DietPlanModel()
                {
                    DietId       = x.DietId,
                    Slots        = x.Slots,
                    FoodType     = x.FoodType,
                    FatRatio     = x.FatRatio,
                    CarbsRatio   = x.CarbsRatio,
                    ProteinRatio = x.ProteinRatio,
                    TotalCalorie = x.TotalCalorie,
                    UserId       = x.UserId
                }).ToList();


                return(res);
            }
        }
示例#14
0
        //SaveWeight() saves WeightLog in the database
        public WeightLog SaveWeight(WeightLogModel weight)
        {
            //open a connection to a database FitnesspointDatabase
            using (var context = new FitnesspointDatabaseEntities())
            {
                //Creating WieghtLog object and assigning data using WeightLogModel class
                WeightLog weightLog = new WeightLog()
                {
                    Weight     = weight.Weight,
                    Created_At = DateTime.UtcNow,
                    Updated_At = DateTime.UtcNow,
                    UserId     = weight.UserId
                };

                //add weightLog to the database WeightLog using model WeightLog
                context.WeightLogs.Add(weightLog);
                //save the changes to the database
                context.SaveChanges();

                return(weightLog);
            }
        }
示例#15
0
        //To get the details of logged in user.
        public UserModel GetUser(string username)
        {
            using (var context = new FitnesspointDatabaseEntities())
            {
                var result = context.UserDetails.Where(x => x.Username == username)
                             .Select(x => new UserModel()
                {
                    UserId           = x.UserId,
                    Name             = x.Name,
                    Gender           = x.Gender,
                    Weight           = x.Weight,
                    Height           = x.Height,
                    MedicalCondition = x.MedicalCondition,
                    AllergicTo       = x.AllergicTo,
                    Goal             = x.Goal,
                    Email            = x.Email,
                    Contact          = (long)x.Contact,
                    Role             = x.Role
                }).FirstOrDefault();

                return(result);
            }
        }
示例#16
0
        //FindWeight() returns the WeightLog based on WeightId
        public WeightLogModel FindWeight(int weight_id)
        {
            //open a connection to a database FitnesspointDatabase
            using (var context = new FitnesspointDatabaseEntities())
            {
                //retrieving weightLog from the database WeightLog
                //using model WeightLogModel based on WeightId

                var res = context.WeightLogs
                          .Where(x => x.WeightId == weight_id)
                          .Select(x => new WeightLogModel()
                {
                    WeightId   = x.WeightId,
                    Weight     = x.Weight,
                    Created_At = x.Created_At,
                    Updated_At = x.Updated_At,
                    UserId     = x.UserId
                }).FirstOrDefault();


                return(res);
            }
        }
        //SavePlan() saves NutritionPlan in the database
        public NutritionPlan SavePlan(NutritionPlanModel nutritionPlan)
        {
            //open a connection to a database FitnesspointDatabase
            using (var context = new FitnesspointDatabaseEntities())
            {
                //Creating NutritionPlan object and assigning data using NutritionPlanModel class
                NutritionPlan nutritionPlan1 = new NutritionPlan()
                {
                    Name            = nutritionPlan.Name,
                    PlanDescription = nutritionPlan.PlanDescription,
                    Created_At      = DateTime.UtcNow,
                    Updated_At      = DateTime.UtcNow,
                    Price           = nutritionPlan.Price,
                };


                //add nutritionPlan to the database NutritionPlan using model NutritionPlan
                context.NutritionPlans.Add(nutritionPlan1);
                //save the changes to the database
                context.SaveChanges();

                return(nutritionPlan1);
            }
        }
        //FindNutritionPlan() returns the NutritionPlans based on NutriPlanId
        public NutritionPlanModel FindNutritionPlan(int plan_id)
        {
            //open a connection to a database FitnesspointDatabase
            using (var context = new FitnesspointDatabaseEntities())
            {
                //retrieving nutritionPlan from the database NutritionPlan
                //using model NutritionPlanModel based on NutriPlanId

                var res = context.NutritionPlans
                          .Where(x => x.NutriPlanId == plan_id)
                          .Select(x => new NutritionPlanModel()
                {
                    NutriPlanId     = x.NutriPlanId,
                    Name            = x.Name,
                    PlanDescription = x.PlanDescription,
                    Created_At      = x.Created_At,
                    Updated_At      = x.Updated_At,
                    Price           = x.Price,
                }).FirstOrDefault();


                return(res);
            }
        }
示例#19
0
 //UpdateDietPlan() update the DietPlans based on DietId and DietPlanModel
 public bool UpdateDietPlan(int diet_id, DietPlanModel dietPlan)
 {
     //open a connection to a database FitnesspointDatabase
     using (var context = new FitnesspointDatabaseEntities())
     {
         //retrieving dietPlan from the database DietPlan based on DietId
         var dietPlan1 = context.DietPlans.FirstOrDefault(x => x.DietId == diet_id);
         //replace the data in the database with DietPlanModel data based on DietId
         if (dietPlan1 != null)
         {
             dietPlan1.Slots        = dietPlan.Slots;
             dietPlan1.FoodType     = dietPlan.FoodType;
             dietPlan1.FatRatio     = dietPlan.FatRatio;
             dietPlan1.CarbsRatio   = dietPlan.CarbsRatio;
             dietPlan1.ProteinRatio = dietPlan.ProteinRatio;
             dietPlan1.TotalCalorie = dietPlan1.FatRatio + dietPlan1.CarbsRatio + dietPlan1.ProteinRatio;
             dietPlan1.UserId       = dietPlan.UserId;
         }
         //save the changes to the database
         context.SaveChanges();
         //returns true if data is updated
         return(true);
     }
 }