Exemplo n.º 1
0
        public IEnumerable <R_FoodTemplate> GetFoodTemplateListAdvancedSearch(
            string name
            , string description
            , string foodCategory
            , int?calories
            , System.DateTime?averageExpirationTimeFrom
            , System.DateTime?averageExpirationTimeTo
            , bool?liquid
            , bool?needsRefrigeration
            , bool?active
            )
        {
            IEnumerable <R_FoodTemplate> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_FoodTemplate")
                      .Where("IsDeleted = 0"
                             + (name != null ? " and Name like '%" + name + "%'" : "")
                             + (description != null ? " and Description like '%" + description + "%'" : "")
                             + (foodCategory != null ? " and FoodCategory like '%" + foodCategory + "%'" : "")
                             + (calories != null ? " and Calories like '%" + calories + "%'" : "")
                             + (averageExpirationTimeFrom != null ? " and AverageExpirationTime >= '" + averageExpirationTimeFrom.Value.ToShortDateString() + "'" : "")
                             + (averageExpirationTimeTo != null ? " and AverageExpirationTime <= '" + averageExpirationTimeTo.Value.ToShortDateString() + "'" : "")
                             + (liquid != null ? " and Liquid = " + (liquid == true ? "1" : "0") : "")
                             + (needsRefrigeration != null ? " and NeedsRefrigeration = " + (needsRefrigeration == true ? "1" : "0") : "")
                             + (active != null ? " and Active = " + (active == true ? "1" : "0") : "")
                             )
            ;

            results = R_FoodTemplate.Query(sql);

            return(results);
        }
Exemplo n.º 2
0
        public void UpdateFoodTemplate(R_FoodTemplate t)
        {
            //Requires.NotNull(t);
            //Requires.PropertyNotNegative(t, "FoodTemplateId");

            t.Update();
        }
Exemplo n.º 3
0
        // example data

        public static R_FoodTemplate SampleFoodTemplate(int id = 1)
        {
            R_FoodTemplate foodTemplate = new R_FoodTemplate();

            // int
            foodTemplate.FoodTemplateId = id;
            // string
            foodTemplate.Name = "NameTestValue";
            // string
            foodTemplate.Description = "DescriptionTestValue";
            // string
            foodTemplate.FoodCategory = "FoodCategoryTestValue";
            // int?
            foodTemplate.Calories = 1;
            // System.DateTime?
            foodTemplate.AverageExpirationTime = new System.DateTime();
            // bool
            foodTemplate.Liquid = false;
            // bool
            foodTemplate.NeedsRefrigeration = false;
            // bool
            foodTemplate.Active = false;
            // bool
            foodTemplate.IsDeleted = false;
            // int?
            foodTemplate.CreateBy = 1;
            // System.DateTime?
            foodTemplate.CreateOn = new System.DateTime();
            // int?
            foodTemplate.UpdateBy = 1;
            // System.DateTime?
            foodTemplate.UpdateOn = new System.DateTime();

            return(foodTemplate);
        }
Exemplo n.º 4
0
        public void GetFoodTemplates_Success_Test()
        {
            // Arrange
            R_FoodTemplate foodTemplate = SampleFoodTemplate(1);

            IList <R_FoodTemplate> list = new List <R_FoodTemplate>();

            list.Add(foodTemplate);

            // create mock for repository
            var mock = new Mock <IFoodTemplateRepository>();

            mock.Setup(s => s.GetFoodTemplates()).Returns(list);

            // service
            FoodTemplateService foodTemplateService = new FoodTemplateService();

            FoodTemplateService.Repository = mock.Object;

            // Act
            var             resultList = foodTemplateService.GetFoodTemplates();
            FoodTemplateDTO result     = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.FoodTemplateId);
        }
Exemplo n.º 5
0
        public FoodTemplateDTO GetFoodTemplate(int foodTemplateId)
        {
            try
            {
                //Requires.NotNegative("foodTemplateId", foodTemplateId);

                log.Debug("foodTemplateId: " + foodTemplateId + " ");

                // get
                R_FoodTemplate t = Repository.GetFoodTemplate(foodTemplateId);

                FoodTemplateDTO dto = new FoodTemplateDTO(t);

                log.Debug(FoodTemplateDTO.FormatFoodTemplateDTO(dto));

                return(dto);
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Exemplo n.º 6
0
        public int AddFoodTemplate(FoodTemplateDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(FoodTemplateDTO.FormatFoodTemplateDTO(dto));

                R_FoodTemplate t = FoodTemplateDTO.ConvertDTOtoEntity(dto);

                // add
                id = Repository.AddFoodTemplate(t);
                dto.FoodTemplateId = id;

                log.Debug("result: 'success', id: " + id);
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }

            return(id);
        }
Exemplo n.º 7
0
        public R_FoodTemplate GetFoodTemplate(int foodTemplateId)
        {
            //Requires.NotNegative("foodTemplateId", foodTemplateId);

            R_FoodTemplate t = R_FoodTemplate.SingleOrDefault(foodTemplateId);

            return(t);
        }
Exemplo n.º 8
0
        public IEnumerable <R_FoodTemplate> GetFoodTemplates()
        {
            IEnumerable <R_FoodTemplate> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_FoodTemplate")
                      .Where("IsDeleted = 0")

            ;

            results = R_FoodTemplate.Query(sql);

            return(results);
        }
Exemplo n.º 9
0
 public FoodTemplateDTO(R_FoodTemplate foodTemplate)
 {
     FoodTemplateId        = foodTemplate.FoodTemplateId;
     Name                  = foodTemplate.Name;
     Description           = foodTemplate.Description;
     FoodCategory          = foodTemplate.FoodCategory;
     Calories              = foodTemplate.Calories;
     AverageExpirationTime = foodTemplate.AverageExpirationTime;
     Liquid                = foodTemplate.Liquid;
     NeedsRefrigeration    = foodTemplate.NeedsRefrigeration;
     Active                = foodTemplate.Active;
     IsDeleted             = foodTemplate.IsDeleted;
     CreateBy              = foodTemplate.CreateBy;
     CreateOn              = foodTemplate.CreateOn;
     UpdateBy              = foodTemplate.UpdateBy;
     UpdateOn              = foodTemplate.UpdateOn;
 }
Exemplo n.º 10
0
        public IList <R_FoodTemplate> GetFoodTemplates(string searchTerm, int pageIndex, int pageSize)
        {
            IList <R_FoodTemplate> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_FoodTemplate")
                      .Where("IsDeleted = 0")
                      .Where(
                "Name like '%" + searchTerm + "%'"
                + " or " + "Description like '%" + searchTerm + "%'"
                + " or " + "FoodCategory like '%" + searchTerm + "%'"
                )
            ;

            results = R_FoodTemplate.Fetch(pageIndex, pageSize, sql);

            return(results);
        }
Exemplo n.º 11
0
        public static R_FoodTemplate ConvertDTOtoEntity(FoodTemplateDTO dto)
        {
            R_FoodTemplate foodTemplate = new R_FoodTemplate();

            foodTemplate.FoodTemplateId        = dto.FoodTemplateId;
            foodTemplate.Name                  = dto.Name;
            foodTemplate.Description           = dto.Description;
            foodTemplate.FoodCategory          = dto.FoodCategory;
            foodTemplate.Calories              = dto.Calories;
            foodTemplate.AverageExpirationTime = dto.AverageExpirationTime;
            foodTemplate.Liquid                = dto.Liquid;
            foodTemplate.NeedsRefrigeration    = dto.NeedsRefrigeration;
            foodTemplate.Active                = dto.Active;
            foodTemplate.IsDeleted             = dto.IsDeleted;
            foodTemplate.CreateBy              = dto.CreateBy;
            foodTemplate.CreateOn              = dto.CreateOn;
            foodTemplate.UpdateBy              = dto.UpdateBy;
            foodTemplate.UpdateOn              = dto.UpdateOn;

            return(foodTemplate);
        }
Exemplo n.º 12
0
        public void DeleteFoodTemplate(FoodTemplateDTO dto)
        {
            try
            {
                log.Debug(FoodTemplateDTO.FormatFoodTemplateDTO(dto));

                R_FoodTemplate t = FoodTemplateDTO.ConvertDTOtoEntity(dto);

                // delete
                Repository.DeleteFoodTemplate(t);
                dto.IsDeleted = t.IsDeleted;

                log.Debug("result: 'success'");
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Exemplo n.º 13
0
        public void GetFoodTemplate_Success_Test()
        {
            // Arrange
            int            id           = 1;
            R_FoodTemplate foodTemplate = SampleFoodTemplate(id);

            // create mock for repository
            var mock = new Mock <IFoodTemplateRepository>();

            mock.Setup(s => s.GetFoodTemplate(Moq.It.IsAny <int>())).Returns(foodTemplate);

            // service
            FoodTemplateService foodTemplateService = new FoodTemplateService();

            FoodTemplateService.Repository = mock.Object;

            // Act
            FoodTemplateDTO result = foodTemplateService.GetFoodTemplate(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.FoodTemplateId);
        }
Exemplo n.º 14
0
        public void UpdateFoodTemplate(FoodTemplateDTO dto)
        {
            try
            {
                //Requires.NotNull(t);
                //Requires.PropertyNotNegative(t, "FoodTemplateId");

                log.Debug(FoodTemplateDTO.FormatFoodTemplateDTO(dto));

                R_FoodTemplate t = FoodTemplateDTO.ConvertDTOtoEntity(dto);

                // update
                Repository.UpdateFoodTemplate(t);

                log.Debug("result: 'success'");
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Exemplo n.º 15
0
 public void DeleteFoodTemplate(R_FoodTemplate t)
 {
     t.IsDeleted = true;
     t.Update();
 }
Exemplo n.º 16
0
        public int AddFoodTemplate(R_FoodTemplate t)
        {
            int id = (int)t.Insert();

            return(id);
        }