Exemplo n.º 1
0
        public void UpdateRefoodUser(R_RefoodUser t)
        {
            //Requires.NotNull(t);
            //Requires.PropertyNotNegative(t, "RefoodUserId");

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

        public static R_RefoodUser SampleRefoodUser(int id = 1)
        {
            R_RefoodUser refoodUser = new R_RefoodUser();

            // int
            refoodUser.RefoodUserId = id;
            // string
            refoodUser.Username = "******";
            // string
            refoodUser.Fullname = "FullnameTestValue";
            // string
            refoodUser.Email = "EmailTestValue";
            // bool
            refoodUser.Active = false;
            // bool
            refoodUser.IsDeleted = false;
            // int?
            refoodUser.CreateBy = 1;
            // System.DateTime?
            refoodUser.CreateOn = new System.DateTime();
            // int?
            refoodUser.UpdateBy = 1;
            // System.DateTime?
            refoodUser.UpdateOn = new System.DateTime();

            return(refoodUser);
        }
Exemplo n.º 3
0
        public RefoodUserDTO GetRefoodUser(int refoodUserId)
        {
            try
            {
                //Requires.NotNegative("refoodUserId", refoodUserId);

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

                // get
                R_RefoodUser t = Repository.GetRefoodUser(refoodUserId);

                RefoodUserDTO dto = new RefoodUserDTO(t);

                log.Debug(RefoodUserDTO.FormatRefoodUserDTO(dto));

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

                throw;
            }
        }
Exemplo n.º 4
0
        public void GetRefoodUsers_Success_Test()
        {
            // Arrange
            R_RefoodUser refoodUser = SampleRefoodUser(1);

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

            list.Add(refoodUser);

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

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

            // service
            RefoodUserService refoodUserService = new RefoodUserService();

            RefoodUserService.Repository = mock.Object;

            // Act
            var           resultList = refoodUserService.GetRefoodUsers();
            RefoodUserDTO result     = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.RefoodUserId);
        }
Exemplo n.º 5
0
        public int AddRefoodUser(RefoodUserDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(RefoodUserDTO.FormatRefoodUserDTO(dto));

                R_RefoodUser t = RefoodUserDTO.ConvertDTOtoEntity(dto);

                // add
                id = Repository.AddRefoodUser(t);
                dto.RefoodUserId = id;

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

                throw;
            }

            return(id);
        }
Exemplo n.º 6
0
        public R_RefoodUser GetRefoodUser(int refoodUserId)
        {
            //Requires.NotNegative("refoodUserId", refoodUserId);

            R_RefoodUser t = R_RefoodUser.SingleOrDefault(refoodUserId);

            return(t);
        }
Exemplo n.º 7
0
 public RefoodUserDTO(R_RefoodUser refoodUser)
 {
     RefoodUserId = refoodUser.RefoodUserId;
     Username     = refoodUser.Username;
     Fullname     = refoodUser.Fullname;
     Email        = refoodUser.Email;
     Active       = refoodUser.Active;
     IsDeleted    = refoodUser.IsDeleted;
     CreateBy     = refoodUser.CreateBy;
     CreateOn     = refoodUser.CreateOn;
     UpdateBy     = refoodUser.UpdateBy;
     UpdateOn     = refoodUser.UpdateOn;
 }
Exemplo n.º 8
0
        public IEnumerable <R_RefoodUser> GetRefoodUsers()
        {
            IEnumerable <R_RefoodUser> results = null;

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

            ;

            results = R_RefoodUser.Query(sql);

            return(results);
        }
Exemplo n.º 9
0
        public static R_RefoodUser ConvertDTOtoEntity(RefoodUserDTO dto)
        {
            R_RefoodUser refoodUser = new R_RefoodUser();

            refoodUser.RefoodUserId = dto.RefoodUserId;
            refoodUser.Username     = dto.Username;
            refoodUser.Fullname     = dto.Fullname;
            refoodUser.Email        = dto.Email;
            refoodUser.Active       = dto.Active;
            refoodUser.IsDeleted    = dto.IsDeleted;
            refoodUser.CreateBy     = dto.CreateBy;
            refoodUser.CreateOn     = dto.CreateOn;
            refoodUser.UpdateBy     = dto.UpdateBy;
            refoodUser.UpdateOn     = dto.UpdateOn;

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

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_RefoodUser")
                      .Where("IsDeleted = 0")
                      .Where(
                "Username like '%" + searchTerm + "%'"
                + " or " + "Fullname like '%" + searchTerm + "%'"
                + " or " + "Email like '%" + searchTerm + "%'"
                )
            ;

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

            return(results);
        }
Exemplo n.º 11
0
        public void DeleteRefoodUser(RefoodUserDTO dto)
        {
            try
            {
                log.Debug(RefoodUserDTO.FormatRefoodUserDTO(dto));

                R_RefoodUser t = RefoodUserDTO.ConvertDTOtoEntity(dto);

                // delete
                Repository.DeleteRefoodUser(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 GetRefoodUser_Success_Test()
        {
            // Arrange
            int          id         = 1;
            R_RefoodUser refoodUser = SampleRefoodUser(id);

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

            mock.Setup(s => s.GetRefoodUser(Moq.It.IsAny <int>())).Returns(refoodUser);

            // service
            RefoodUserService refoodUserService = new RefoodUserService();

            RefoodUserService.Repository = mock.Object;

            // Act
            RefoodUserDTO result = refoodUserService.GetRefoodUser(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.RefoodUserId);
        }
Exemplo n.º 13
0
        public IEnumerable <R_RefoodUser> GetRefoodUserListAdvancedSearch(
            string username
            , string fullname
            , string email
            , bool?active
            )
        {
            IEnumerable <R_RefoodUser> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_RefoodUser")
                      .Where("IsDeleted = 0"
                             + (username != null ? " and Username like '%" + username + "%'" : "")
                             + (fullname != null ? " and Fullname like '%" + fullname + "%'" : "")
                             + (email != null ? " and Email like '%" + email + "%'" : "")
                             + (active != null ? " and Active = " + (active == true ? "1" : "0") : "")
                             )
            ;

            results = R_RefoodUser.Query(sql);

            return(results);
        }
Exemplo n.º 14
0
        public void UpdateRefoodUser(RefoodUserDTO dto)
        {
            try
            {
                //Requires.NotNull(t);
                //Requires.PropertyNotNegative(t, "RefoodUserId");

                log.Debug(RefoodUserDTO.FormatRefoodUserDTO(dto));

                R_RefoodUser t = RefoodUserDTO.ConvertDTOtoEntity(dto);

                // update
                Repository.UpdateRefoodUser(t);

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

                throw;
            }
        }
Exemplo n.º 15
0
 public void DeleteRefoodUser(R_RefoodUser t)
 {
     t.IsDeleted = true;
     t.Update();
 }
Exemplo n.º 16
0
        public int AddRefoodUser(R_RefoodUser t)
        {
            int id = (int)t.Insert();

            return(id);
        }