Example #1
0
        public bool AddFoodPortion(string userId, string portions, int FPID)
        {
            trainer     trainer     = db.trainer.FirstOrDefault(x => x.ID == userId);
            foodProgram foodProgram = db.foodProgram.FirstOrDefault(x => x.FPMID == FPID);

            if (trainer.TRID != foodProgram.trainer_TRID)
            {
                return(false);
            }
            else
            {
                try
                {
                    List <int> FPIDList     = new List <int>();
                    var        portionArray = JsonConvert.DeserializeObject <List <FoodPortionDTO> >(portions);
                    foreach (FoodPortionDTO x in portionArray)
                    {
                        var t = new foodPortion
                        {
                            FPID          = x.FPID,
                            foodItem_FIID = x.foodItem_FIID,
                            timeOfDay     = x.timeOfDay,
                            quantity      = x.quantity,
                            sunday        = x.sunday,
                            monday        = x.monday,
                            tuesday       = x.tuesday,
                            wednesday     = x.wednesday,
                            thursday      = x.thursday,
                            friday        = x.friday,
                            saturday      = x.saturday,
                            className     = x.className,
                        };
                        db.foodPortion.Add(t);
                        db.SaveChanges();
                        FPIDList.Add(t.FPID);
                    }
                    foreach (int x in FPIDList)
                    {
                        db.foodProgramPortion.Add(new foodProgramPortion {
                            foodProgram_FPMID = FPID, foodPortion_FPID = x
                        });
                    }
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
Example #2
0
        public int AddFoodProgram(string name, string userId)
        {
            trainer t = db.trainer.FirstOrDefault(x => x.ID == userId);

            var f = new foodProgram
            {
                name         = name,
                trainer_TRID = t.TRID
            };

            db.foodProgram.Add(f);
            db.SaveChanges();

            return(f.FPMID);
        }
Example #3
0
        public FoodProgramDTO GetCurrentFoodProgramDateByCID(int CID)
        {
            foodProgram f         = new foodProgram();
            var         currentFp = db.foodProgramDate.OrderByDescending(x => x.date).FirstOrDefault(x => x.customer_CID == CID);

            if (currentFp != null)
            {
                f = db.foodProgram.FirstOrDefault(x => x.FPMID == currentFp.foodProgram_FPMID);
            }
            var fp = new FoodProgramDTO
            {
                FPMID = f.FPMID,
                name  = f.name
            };

            return(fp);
        }
Example #4
0
        public FoodProgramDTO GetCurrentFoodProgramDateByUserID(string UserId)
        {
            foodProgram f         = new foodProgram();
            customer    c         = db.customer.FirstOrDefault(x => x.ID == UserId);
            var         currentFp = db.foodProgramDate.OrderByDescending(x => x.date).FirstOrDefault(x => x.customer_CID == c.CID);

            if (currentFp != null)
            {
                f = db.foodProgram.FirstOrDefault(x => x.FPMID == currentFp.foodProgram_FPMID);
            }
            var fp = new FoodProgramDTO
            {
                FPMID = f.FPMID,
                name  = f.name,
            };

            return(fp);
        }