Exemplo n.º 1
0
        public static R_Food ConvertDTOtoEntity(FoodDTO dto)
        {
            R_Food food = new R_Food();

            food.FoodId                  = dto.FoodId;
            food.Name                    = dto.Name;
            food.Quantity                = dto.Quantity;
            food.FoodTemplateId          = dto.FoodTemplateId;
            food.SpecificObservations    = dto.SpecificObservations;
            food.Location                = dto.Location;
            food.Progress                = dto.Progress;
            food.Expired                 = dto.Expired;
            food.Liquid                  = dto.Liquid;
            food.Rating                  = dto.Rating;
            food.FeedbackFromBeneficiary = dto.FeedbackFromBeneficiary;
            food.DeliveredBy             = dto.DeliveredBy;
            food.DeliveredTo             = dto.DeliveredTo;
            food.OrderDateTime           = dto.OrderDateTime;
            food.CookedDateTime          = dto.CookedDateTime;
            food.PickupDateTime          = dto.PickupDateTime;
            food.StorageDateTime         = dto.StorageDateTime;
            food.DeliveryDateTime        = dto.DeliveryDateTime;
            food.Active                  = dto.Active;
            food.IsDeleted               = dto.IsDeleted;
            food.CreateBy                = dto.CreateBy;
            food.CreateOn                = dto.CreateOn;
            food.UpdateBy                = dto.UpdateBy;
            food.UpdateOn                = dto.UpdateOn;

            return(food);
        }
Exemplo n.º 2
0
        public void UpdateFood(R_Food t)
        {
            //Requires.NotNull(t);
            //Requires.PropertyNotNegative(t, "FoodId");

            t.Update();
        }
Exemplo n.º 3
0
 public FoodDTO(R_Food food)
 {
     FoodId                  = food.FoodId;
     Name                    = food.Name;
     Quantity                = food.Quantity;
     FoodTemplateId          = food.FoodTemplateId;
     SpecificObservations    = food.SpecificObservations;
     Location                = food.Location;
     Progress                = food.Progress;
     Expired                 = food.Expired;
     Liquid                  = food.Liquid;
     Rating                  = food.Rating;
     FeedbackFromBeneficiary = food.FeedbackFromBeneficiary;
     DeliveredBy             = food.DeliveredBy;
     DeliveredTo             = food.DeliveredTo;
     OrderDateTime           = food.OrderDateTime;
     CookedDateTime          = food.CookedDateTime;
     PickupDateTime          = food.PickupDateTime;
     StorageDateTime         = food.StorageDateTime;
     DeliveryDateTime        = food.DeliveryDateTime;
     Active                  = food.Active;
     IsDeleted               = food.IsDeleted;
     CreateBy                = food.CreateBy;
     CreateOn                = food.CreateOn;
     UpdateBy                = food.UpdateBy;
     UpdateOn                = food.UpdateOn;
 }
Exemplo n.º 4
0
        public int AddFood(FoodDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(FoodDTO.FormatFoodDTO(dto));

                R_Food t = FoodDTO.ConvertDTOtoEntity(dto);

                // add
                id         = Repository.AddFood(t);
                dto.FoodId = id;

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

                throw;
            }

            return(id);
        }
Exemplo n.º 5
0
        public FoodDTO GetFood(int foodId)
        {
            try
            {
                //Requires.NotNegative("foodId", foodId);

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

                // get
                R_Food t = Repository.GetFood(foodId);

                FoodDTO dto = new FoodDTO(t);

                log.Debug(FoodDTO.FormatFoodDTO(dto));

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

                throw;
            }
        }
Exemplo n.º 6
0
        public void GetFoods_Success_Test()
        {
            // Arrange
            R_Food food = SampleFood(1);

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

            list.Add(food);

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

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

            // service
            FoodService foodService = new FoodService();

            FoodService.Repository = mock.Object;

            // Act
            var     resultList = foodService.GetFoods();
            FoodDTO result     = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.FoodId);
        }
Exemplo n.º 7
0
        public R_Food GetFood(int foodId)
        {
            //Requires.NotNegative("foodId", foodId);

            R_Food t = R_Food.SingleOrDefault(foodId);

            return(t);
        }
Exemplo n.º 8
0
        // example data

        public static R_Food SampleFood(int id = 1)
        {
            R_Food food = new R_Food();

            // int
            food.FoodId = id;
            // string
            food.Name = "NameTestValue";
            // double?
            food.Quantity = 1;
            // int?
            food.FoodTemplateId = 1;
            // string
            food.SpecificObservations = "SpecificObservationsTestValue";
            // string
            food.Location = "LocationTestValue";
            // int?
            food.Progress = 1;
            // bool
            food.Expired = false;
            // bool
            food.Liquid = false;
            // int?
            food.Rating = 1;
            // string
            food.FeedbackFromBeneficiary = "FeedbackFromBeneficiaryTestValue";
            // int?
            food.DeliveredBy = 1;
            // int?
            food.DeliveredTo = 1;
            // System.DateTime?
            food.OrderDateTime = new System.DateTime();
            // System.DateTime?
            food.CookedDateTime = new System.DateTime();
            // System.DateTime?
            food.PickupDateTime = new System.DateTime();
            // System.DateTime?
            food.StorageDateTime = new System.DateTime();
            // System.DateTime?
            food.DeliveryDateTime = new System.DateTime();
            // bool
            food.Active = false;
            // bool
            food.IsDeleted = false;
            // int?
            food.CreateBy = 1;
            // System.DateTime?
            food.CreateOn = new System.DateTime();
            // int?
            food.UpdateBy = 1;
            // System.DateTime?
            food.UpdateOn = new System.DateTime();

            return(food);
        }
Exemplo n.º 9
0
        public IEnumerable <R_Food> GetFoods()
        {
            IEnumerable <R_Food> results = null;

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

            ;

            results = R_Food.Query(sql);

            return(results);
        }
Exemplo n.º 10
0
        public IList <R_Food> GetFoods(string searchTerm, int pageIndex, int pageSize)
        {
            IList <R_Food> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_Food")
                      .Where("IsDeleted = 0")
                      .Where(
                "Name like '%" + searchTerm + "%'"
                + " or " + "SpecificObservations like '%" + searchTerm + "%'"
                + " or " + "Location like '%" + searchTerm + "%'"
                + " or " + "FeedbackFromBeneficiary like '%" + searchTerm + "%'"
                )
            ;

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

            return(results);
        }
Exemplo n.º 11
0
        public void DeleteFood(FoodDTO dto)
        {
            try
            {
                log.Debug(FoodDTO.FormatFoodDTO(dto));

                R_Food t = FoodDTO.ConvertDTOtoEntity(dto);

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

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

                throw;
            }
        }
Exemplo n.º 12
0
        public void GetFood_Success_Test()
        {
            // Arrange
            int    id   = 1;
            R_Food food = SampleFood(id);

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

            mock.Setup(s => s.GetFood(Moq.It.IsAny <int>())).Returns(food);

            // service
            FoodService foodService = new FoodService();

            FoodService.Repository = mock.Object;

            // Act
            FoodDTO result = foodService.GetFood(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.FoodId);
        }
Exemplo n.º 13
0
        public void UpdateFood(FoodDTO dto)
        {
            try
            {
                //Requires.NotNull(t);
                //Requires.PropertyNotNegative(t, "FoodId");

                log.Debug(FoodDTO.FormatFoodDTO(dto));

                R_Food t = FoodDTO.ConvertDTOtoEntity(dto);

                // update
                Repository.UpdateFood(t);

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

                throw;
            }
        }
Exemplo n.º 14
0
        public IEnumerable <R_Food> GetFoodListAdvancedSearch(
            string name
            , double?quantity
            , int?foodTemplateId
            , string specificObservations
            , string location
            , int?progress
            , bool?expired
            , bool?liquid
            , int?rating
            , string feedbackFromBeneficiary
            , int?deliveredBy
            , int?deliveredTo
            , System.DateTime?orderDateTimeFrom
            , System.DateTime?orderDateTimeTo
            , System.DateTime?cookedDateTimeFrom
            , System.DateTime?cookedDateTimeTo
            , System.DateTime?pickupDateTimeFrom
            , System.DateTime?pickupDateTimeTo
            , System.DateTime?storageDateTimeFrom
            , System.DateTime?storageDateTimeTo
            , System.DateTime?deliveryDateTimeFrom
            , System.DateTime?deliveryDateTimeTo
            , bool?active
            )
        {
            IEnumerable <R_Food> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_Food")
                      .Where("IsDeleted = 0"
                             + (name != null ? " and Name like '%" + name + "%'" : "")
                             + (quantity != null ? " and Quantity like '%" + quantity + "%'" : "")
                             + (foodTemplateId != null ? " and FoodTemplateId like '%" + foodTemplateId + "%'" : "")
                             + (specificObservations != null ? " and SpecificObservations like '%" + specificObservations + "%'" : "")
                             + (location != null ? " and Location like '%" + location + "%'" : "")
                             + (progress != null ? " and Progress like '%" + progress + "%'" : "")
                             + (expired != null ? " and Expired = " + (expired == true ? "1" : "0") : "")
                             + (liquid != null ? " and Liquid = " + (liquid == true ? "1" : "0") : "")
                             + (rating != null ? " and Rating like '%" + rating + "%'" : "")
                             + (feedbackFromBeneficiary != null ? " and FeedbackFromBeneficiary like '%" + feedbackFromBeneficiary + "%'" : "")
                             + (deliveredBy != null ? " and DeliveredBy like '%" + deliveredBy + "%'" : "")
                             + (deliveredTo != null ? " and DeliveredTo like '%" + deliveredTo + "%'" : "")
                             + (orderDateTimeFrom != null ? " and OrderDateTime >= '" + orderDateTimeFrom.Value.ToShortDateString() + "'" : "")
                             + (orderDateTimeTo != null ? " and OrderDateTime <= '" + orderDateTimeTo.Value.ToShortDateString() + "'" : "")
                             + (cookedDateTimeFrom != null ? " and CookedDateTime >= '" + cookedDateTimeFrom.Value.ToShortDateString() + "'" : "")
                             + (cookedDateTimeTo != null ? " and CookedDateTime <= '" + cookedDateTimeTo.Value.ToShortDateString() + "'" : "")
                             + (pickupDateTimeFrom != null ? " and PickupDateTime >= '" + pickupDateTimeFrom.Value.ToShortDateString() + "'" : "")
                             + (pickupDateTimeTo != null ? " and PickupDateTime <= '" + pickupDateTimeTo.Value.ToShortDateString() + "'" : "")
                             + (storageDateTimeFrom != null ? " and StorageDateTime >= '" + storageDateTimeFrom.Value.ToShortDateString() + "'" : "")
                             + (storageDateTimeTo != null ? " and StorageDateTime <= '" + storageDateTimeTo.Value.ToShortDateString() + "'" : "")
                             + (deliveryDateTimeFrom != null ? " and DeliveryDateTime >= '" + deliveryDateTimeFrom.Value.ToShortDateString() + "'" : "")
                             + (deliveryDateTimeTo != null ? " and DeliveryDateTime <= '" + deliveryDateTimeTo.Value.ToShortDateString() + "'" : "")
                             + (active != null ? " and Active = " + (active == true ? "1" : "0") : "")
                             )
            ;

            results = R_Food.Query(sql);

            return(results);
        }
Exemplo n.º 15
0
 public void DeleteFood(R_Food t)
 {
     t.IsDeleted = true;
     t.Update();
 }
Exemplo n.º 16
0
        public int AddFood(R_Food t)
        {
            int id = (int)t.Insert();

            return(id);
        }