Beispiel #1
0
        public void AddDietPlanTest()
        {
            //// Arrange
            var controller = _controller;
            var dietPlan   = new POCO.DietPlan
            {
                Name        = "TestControl",
                Information = "Test diet plan",
                PersonId    = 2
            };

            //// Action - this assume there is data for student with id=1 in the db
            var detail = (JsonResult)controller.Create(dietPlan);

            //// Assert
            Assert.Equal(200, detail.StatusCode);

            //// Action again
            dietPlan.Id = ((POCO.DietPlan)detail.Value).Id;
            controller.Delete(dietPlan.Id);

            //// Assert
            detail = (JsonResult)controller.GetDietPlanById(dietPlan.Id);
            Assert.Equal(200, detail.StatusCode);
        }
Beispiel #2
0
        public void UpdateDietPlanTest()
        {
            //// Arrange
            var controller = _controller;
            var dietPlan   = new POCO.DietPlan
            {
                Name        = "TestControl",
                Information = "Test Dietplan",
                PersonId    = 10
            };

            //// Action
            var detail = (JsonResult)controller.Create(dietPlan);

            //// Assert
            Assert.Equal(200, detail.StatusCode);

            //// Action again
            var updateDietPlan = new POCO.DietPlan
            {
                Id          = ((POCO.DietPlan)detail.Value).Id,
                Name        = "Changed",
                Information = "Changed Diet plan",
                PersonId    = 10
            };

            detail = (JsonResult)controller.Update(updateDietPlan);

            //// Assert
            Assert.Equal(200, detail.StatusCode);
            detail = (JsonResult)controller.GetDietPlanById(dietPlan.Id);
            Assert.Equal(200, detail.StatusCode);
            dietPlan.Id = ((POCO.DietPlan)detail.Value).Id;
            controller.Delete(dietPlan.Id);
        }
Beispiel #3
0
        // Return list of pinned DietPlan with only basic information
        public static List <POCO.DietPlan> PinnedDietPlansEntityToPOCO(ICollection <PinnedDietPlans> entities)
        {
            if (entities == null)
            {
                return(null);
            }

            List <POCO.DietPlan> result = new List <POCO.DietPlan>();

            foreach (PinnedDietPlans dietPlanPin in entities)
            {
                if (dietPlanPin.DietPlan != null)
                {
                    var dp = new POCO.DietPlan
                    {
                        Id          = dietPlanPin.DietPlan.Id,
                        Name        = dietPlanPin.DietPlan.Name,
                        Information = dietPlanPin.DietPlan.Information,
                        PersonId    = dietPlanPin.DietPlan.PersonId
                    };
                    result.Add(dp);
                }
            }

            return(result);
        }
Beispiel #4
0
        private static POCO.DietPlan DietPlanViewModelToPOCO(DietPlan dietPlan)
        {
            var result = new POCO.DietPlan
            {
                Id          = dietPlan.Id,
                Name        = dietPlan.Name,
                Information = dietPlan.Information,
                PersonId    = dietPlan.PersonId
            };

            return(result);
        }
Beispiel #5
0
        private static DietPlan DietPlanPOCOToViewModel(POCO.DietPlan pDietPlan)
        {
            var result = new DietPlan
            {
                Id          = pDietPlan.Id,
                Name        = pDietPlan.Name,
                Information = pDietPlan.Information,
                PersonId    = pDietPlan.PersonId,
                CreatorName = getCreatorName(pDietPlan.Creator)
            };

            return(result);
        }
        public bool update(POCO.DietPlan dietPlan)
        {
            if (dietPlan == null)
            {
                throw new ArgumentNullException();
            }

            var entity = POCOObjToEntity(dietPlan);

            entity = _genericAccess.Update <DietPlans>(entity, dietPlan.Id);
            if (entity != null)
            {
                return(true);
            }
            return(false);
        }
        public static DietPlans POCOObjToEntity(POCO.DietPlan dietPlan)
        {
            if (dietPlan == null)
            {
                return(null);
            }

            var d = new DietPlans
            {
                Id          = dietPlan.Id,
                Name        = dietPlan.Name,
                Information = dietPlan.Information,
                PersonId    = dietPlan.PersonId
            };

            return(d);
        }
        public static POCO.DietPlan DietPlanEntityObjToPOCO(DietPlans entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var dietPlan = new POCO.DietPlan
            {
                Id          = entity.Id,
                Name        = entity.Name,
                Information = entity.Information,
                PersonId    = entity.PersonId,
                Creator     = PersonEntityToPOCO(entity.Person),
                Meals       = getMealList(entity.Meals)
            };

            return(dietPlan);
        }
Beispiel #9
0
        public IActionResult Update(POCO.DietPlan dietPlan)
        {
            var        service = new DietPlanService(_genericAccess, _dietPlansAccess);
            JsonResult result;

            try
            {
                var ret = service.update(dietPlan);
                result            = Json(ret);
                result.StatusCode = 200;
            }
            catch (Exception e)
            {
                result            = Json(e);
                result.StatusCode = 400;
            }

            return(result);
        }
        public POCO.DietPlan create(POCO.DietPlan dietPlan)
        {
            if (dietPlan == null)
            {
                throw new ArgumentNullException();
            }

            if (string.IsNullOrEmpty(dietPlan.Name) || dietPlan.PersonId <= 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            var d = new DietPlans
            {
                Name        = dietPlan.Name,
                Information = dietPlan.Information,
                PersonId    = dietPlan.PersonId
            };

            d           = _genericAccess.Add(d);
            dietPlan.Id = d.Id;
            return(dietPlan);
        }