コード例 #1
0
        public void UpdateVehicleType(R_VehicleType t)
        {
            //Requires.NotNull(t);
            //Requires.PropertyNotNegative(t, "VehicleTypeId");

            t.Update();
        }
コード例 #2
0
        // example data

        public static R_VehicleType SampleVehicleType(int id = 1)
        {
            R_VehicleType vehicleType = new R_VehicleType();

            // int
            vehicleType.VehicleTypeId = id;
            // string
            vehicleType.Name = "NameTestValue";
            // string
            vehicleType.Description = "DescriptionTestValue";
            // bool
            vehicleType.Active = false;
            // bool
            vehicleType.IsDeleted = false;
            // int?
            vehicleType.CreateBy = 1;
            // System.DateTime?
            vehicleType.CreateOn = new System.DateTime();
            // int?
            vehicleType.UpdateBy = 1;
            // System.DateTime?
            vehicleType.UpdateOn = new System.DateTime();

            return(vehicleType);
        }
コード例 #3
0
        public VehicleTypeDTO GetVehicleType(int vehicleTypeId)
        {
            try
            {
                //Requires.NotNegative("vehicleTypeId", vehicleTypeId);

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

                // get
                R_VehicleType t = Repository.GetVehicleType(vehicleTypeId);

                VehicleTypeDTO dto = new VehicleTypeDTO(t);

                log.Debug(VehicleTypeDTO.FormatVehicleTypeDTO(dto));

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

                throw;
            }
        }
コード例 #4
0
        public void GetVehicleTypes_Success_Test()
        {
            // Arrange
            R_VehicleType vehicleType = SampleVehicleType(1);

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

            list.Add(vehicleType);

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

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

            // service
            VehicleTypeService vehicleTypeService = new VehicleTypeService();

            VehicleTypeService.Repository = mock.Object;

            // Act
            var            resultList = vehicleTypeService.GetVehicleTypes();
            VehicleTypeDTO result     = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.VehicleTypeId);
        }
コード例 #5
0
        public int AddVehicleType(VehicleTypeDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(VehicleTypeDTO.FormatVehicleTypeDTO(dto));

                R_VehicleType t = VehicleTypeDTO.ConvertDTOtoEntity(dto);

                // add
                id = Repository.AddVehicleType(t);
                dto.VehicleTypeId = id;

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

                throw;
            }

            return(id);
        }
コード例 #6
0
        public R_VehicleType GetVehicleType(int vehicleTypeId)
        {
            //Requires.NotNegative("vehicleTypeId", vehicleTypeId);

            R_VehicleType t = R_VehicleType.SingleOrDefault(vehicleTypeId);

            return(t);
        }
コード例 #7
0
 public VehicleTypeDTO(R_VehicleType vehicleType)
 {
     VehicleTypeId = vehicleType.VehicleTypeId;
     Name          = vehicleType.Name;
     Description   = vehicleType.Description;
     Active        = vehicleType.Active;
     IsDeleted     = vehicleType.IsDeleted;
     CreateBy      = vehicleType.CreateBy;
     CreateOn      = vehicleType.CreateOn;
     UpdateBy      = vehicleType.UpdateBy;
     UpdateOn      = vehicleType.UpdateOn;
 }
コード例 #8
0
        public IEnumerable <R_VehicleType> GetVehicleTypes()
        {
            IEnumerable <R_VehicleType> results = null;

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

            ;

            results = R_VehicleType.Query(sql);

            return(results);
        }
コード例 #9
0
        public static R_VehicleType ConvertDTOtoEntity(VehicleTypeDTO dto)
        {
            R_VehicleType vehicleType = new R_VehicleType();

            vehicleType.VehicleTypeId = dto.VehicleTypeId;
            vehicleType.Name          = dto.Name;
            vehicleType.Description   = dto.Description;
            vehicleType.Active        = dto.Active;
            vehicleType.IsDeleted     = dto.IsDeleted;
            vehicleType.CreateBy      = dto.CreateBy;
            vehicleType.CreateOn      = dto.CreateOn;
            vehicleType.UpdateBy      = dto.UpdateBy;
            vehicleType.UpdateOn      = dto.UpdateOn;

            return(vehicleType);
        }
コード例 #10
0
        public IList <R_VehicleType> GetVehicleTypes(string searchTerm, int pageIndex, int pageSize)
        {
            IList <R_VehicleType> results = null;

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

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

            return(results);
        }
コード例 #11
0
        public IEnumerable <R_VehicleType> GetVehicleTypeListAdvancedSearch(
            string name
            , string description
            , bool?active
            )
        {
            IEnumerable <R_VehicleType> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_VehicleType")
                      .Where("IsDeleted = 0"
                             + (name != null ? " and Name like '%" + name + "%'" : "")
                             + (description != null ? " and Description like '%" + description + "%'" : "")
                             + (active != null ? " and Active = " + (active == true ? "1" : "0") : "")
                             )
            ;

            results = R_VehicleType.Query(sql);

            return(results);
        }
コード例 #12
0
        public void DeleteVehicleType(VehicleTypeDTO dto)
        {
            try
            {
                log.Debug(VehicleTypeDTO.FormatVehicleTypeDTO(dto));

                R_VehicleType t = VehicleTypeDTO.ConvertDTOtoEntity(dto);

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

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

                throw;
            }
        }
コード例 #13
0
        public void GetVehicleType_Success_Test()
        {
            // Arrange
            int           id          = 1;
            R_VehicleType vehicleType = SampleVehicleType(id);

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

            mock.Setup(s => s.GetVehicleType(Moq.It.IsAny <int>())).Returns(vehicleType);

            // service
            VehicleTypeService vehicleTypeService = new VehicleTypeService();

            VehicleTypeService.Repository = mock.Object;

            // Act
            VehicleTypeDTO result = vehicleTypeService.GetVehicleType(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.VehicleTypeId);
        }
コード例 #14
0
        public void UpdateVehicleType(VehicleTypeDTO dto)
        {
            try
            {
                //Requires.NotNull(t);
                //Requires.PropertyNotNegative(t, "VehicleTypeId");

                log.Debug(VehicleTypeDTO.FormatVehicleTypeDTO(dto));

                R_VehicleType t = VehicleTypeDTO.ConvertDTOtoEntity(dto);

                // update
                Repository.UpdateVehicleType(t);

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

                throw;
            }
        }
コード例 #15
0
 public void DeleteVehicleType(R_VehicleType t)
 {
     t.IsDeleted = true;
     t.Update();
 }
コード例 #16
0
        public int AddVehicleType(R_VehicleType t)
        {
            int id = (int)t.Insert();

            return(id);
        }