Exemplo n.º 1
0
        public SupplierDTO GetSupplier(int supplierId)
        {
            try
            {
                //Requires.NotNegative("supplierId", supplierId);

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

                // get
                R_Supplier t = Repository.GetSupplier(supplierId);

                SupplierDTO dto = new SupplierDTO(t);

                log.Debug(SupplierDTO.FormatSupplierDTO(dto));

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

                throw;
            }
        }
Exemplo n.º 2
0
        public int AddSupplier(SupplierDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(SupplierDTO.FormatSupplierDTO(dto));

                R_Supplier t = SupplierDTO.ConvertDTOtoEntity(dto);

                // add
                id             = Repository.AddSupplier(t);
                dto.SupplierId = id;

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

                throw;
            }

            return(id);
        }
Exemplo n.º 3
0
        public void GetSuppliers_Success_Test()
        {
            // Arrange
            R_Supplier supplier = SampleSupplier(1);

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

            list.Add(supplier);

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

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

            // service
            SupplierService supplierService = new SupplierService();

            SupplierService.Repository = mock.Object;

            // Act
            var         resultList = supplierService.GetSuppliers();
            SupplierDTO result     = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.SupplierId);
        }
Exemplo n.º 4
0
        public void UpdateSupplier(R_Supplier t)
        {
            //Requires.NotNull(t);
            //Requires.PropertyNotNegative(t, "SupplierId");

            t.Update();
        }
Exemplo n.º 5
0
        public IEnumerable <R_Supplier> GetSupplierListAdvancedSearch(
            string name
            , int?supplierTypeId
            , string phone
            , string email
            , double?latitude
            , double?longitude
            , string description
            , string website
            , int?addressId
            )
        {
            IEnumerable <R_Supplier> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_Supplier")
                      .Where("IsDeleted = 0"
                             + (name != null ? " and Name like '%" + name + "%'" : "")
                             + (supplierTypeId != null ? " and SupplierTypeId = " + supplierTypeId : "")
                             + (phone != null ? " and Phone like '%" + phone + "%'" : "")
                             + (email != null ? " and Email like '%" + email + "%'" : "")
                             + (latitude != null ? " and Latitude like '%" + latitude + "%'" : "")
                             + (longitude != null ? " and Longitude like '%" + longitude + "%'" : "")
                             + (description != null ? " and Description like '%" + description + "%'" : "")
                             + (website != null ? " and Website like '%" + website + "%'" : "")
                             + (addressId != null ? " and AddressId like '%" + addressId + "%'" : "")
                             )
            ;

            results = R_Supplier.Query(sql);

            return(results);
        }
Exemplo n.º 6
0
        public R_Supplier GetSupplier(int supplierId)
        {
            //Requires.NotNegative("supplierId", supplierId);

            R_Supplier t = R_Supplier.SingleOrDefault(supplierId);

            return(t);
        }
Exemplo n.º 7
0
        public IEnumerable <R_Supplier> GetSuppliers()
        {
            IEnumerable <R_Supplier> results = null;

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

            ;

            results = R_Supplier.Query(sql);

            return(results);
        }
Exemplo n.º 8
0
 public SupplierDTO(R_Supplier supplier)
 {
     SupplierId     = supplier.SupplierId;
     Name           = supplier.Name;
     SupplierTypeId = supplier.SupplierTypeId;
     Phone          = supplier.Phone;
     Email          = supplier.Email;
     Latitude       = supplier.Latitude;
     Longitude      = supplier.Longitude;
     Description    = supplier.Description;
     Website        = supplier.Website;
     AddressId      = supplier.AddressId;
     IsDeleted      = supplier.IsDeleted;
     CreateBy       = supplier.CreateBy;
     CreateOn       = supplier.CreateOn;
     UpdateBy       = supplier.UpdateBy;
     UpdateOn       = supplier.UpdateOn;
 }
Exemplo n.º 9
0
        public IList <R_Supplier> GetSuppliers(string searchTerm, int pageIndex, int pageSize)
        {
            IList <R_Supplier> results = null;

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

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

            return(results);
        }
Exemplo n.º 10
0
        public void DeleteSupplier(SupplierDTO dto)
        {
            try
            {
                log.Debug(SupplierDTO.FormatSupplierDTO(dto));

                R_Supplier t = SupplierDTO.ConvertDTOtoEntity(dto);

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

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

                throw;
            }
        }
Exemplo n.º 11
0
        public static R_Supplier ConvertDTOtoEntity(SupplierDTO dto)
        {
            R_Supplier supplier = new R_Supplier();

            supplier.SupplierId     = dto.SupplierId;
            supplier.Name           = dto.Name;
            supplier.SupplierTypeId = dto.SupplierTypeId;
            supplier.Phone          = dto.Phone;
            supplier.Email          = dto.Email;
            supplier.Latitude       = dto.Latitude;
            supplier.Longitude      = dto.Longitude;
            supplier.Description    = dto.Description;
            supplier.Website        = dto.Website;
            supplier.AddressId      = dto.AddressId;
            supplier.IsDeleted      = dto.IsDeleted;
            supplier.CreateBy       = dto.CreateBy;
            supplier.CreateOn       = dto.CreateOn;
            supplier.UpdateBy       = dto.UpdateBy;
            supplier.UpdateOn       = dto.UpdateOn;

            return(supplier);
        }
Exemplo n.º 12
0
        public void GetSupplier_Success_Test()
        {
            // Arrange
            int        id       = 1;
            R_Supplier supplier = SampleSupplier(id);

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

            mock.Setup(s => s.GetSupplier(Moq.It.IsAny <int>())).Returns(supplier);

            // service
            SupplierService supplierService = new SupplierService();

            SupplierService.Repository = mock.Object;

            // Act
            SupplierDTO result = supplierService.GetSupplier(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.SupplierId);
        }
Exemplo n.º 13
0
        // example data

        public static R_Supplier SampleSupplier(int id = 1)
        {
            R_Supplier supplier = new R_Supplier();

            // int
            supplier.SupplierId = id;
            // string
            supplier.Name = "NameTestValue";
            // int
            supplier.SupplierTypeId = 1;
            // string
            supplier.Phone = "PhoneTestValue";
            // string
            supplier.Email = "EmailTestValue";
            // double?
            supplier.Latitude = 1;
            // double?
            supplier.Longitude = 1;
            // string
            supplier.Description = "DescriptionTestValue";
            // string
            supplier.Website = "WebsiteTestValue";
            // int?
            supplier.AddressId = 1;
            // bool
            supplier.IsDeleted = false;
            // int?
            supplier.CreateBy = 1;
            // System.DateTime?
            supplier.CreateOn = new System.DateTime();
            // int?
            supplier.UpdateBy = 1;
            // System.DateTime?
            supplier.UpdateOn = new System.DateTime();

            return(supplier);
        }
Exemplo n.º 14
0
        public void UpdateSupplier(SupplierDTO dto)
        {
            try
            {
                //Requires.NotNull(t);
                //Requires.PropertyNotNegative(t, "SupplierId");

                log.Debug(SupplierDTO.FormatSupplierDTO(dto));

                R_Supplier t = SupplierDTO.ConvertDTOtoEntity(dto);

                // update
                Repository.UpdateSupplier(t);

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

                throw;
            }
        }
Exemplo n.º 15
0
 public void DeleteSupplier(R_Supplier t)
 {
     t.IsDeleted = true;
     t.Update();
 }
Exemplo n.º 16
0
        public int AddSupplier(R_Supplier t)
        {
            int id = (int)t.Insert();

            return(id);
        }