コード例 #1
0
ファイル: UserService.cs プロジェクト: vpj124/practicaltest
        public bool InsertOrUpdate(UserViewModel User)
        {
            bool isUpdated = false;

            using (PracticalTestEntities _context = new PracticalTestEntities())
            {
                if (User.Id == null || User.Id == Guid.Empty)
                {
                    // Insert
                    tbl_usermaster _RetObj = new tbl_usermaster();
                    _RetObj.Id         = Guid.NewGuid();
                    _RetObj.Name       = User.Name;
                    _RetObj.Birthdate  = Convert.ToDateTime(User.Birthdate);
                    _RetObj.Email      = User.Email;
                    _RetObj.Mobile     = User.Mobile;
                    _RetObj.Age        = User.Age;
                    _RetObj.Gender     = User.Gender;
                    _RetObj.RoleId     = User.RoleId;
                    _RetObj.ProfileUrl = User.ProfileUrl;
                    _RetObj.IsActive   = true;
                    _RetObj.CreatedAt  = DateTime.Now;
                    _RetObj.UpdatedAt  = DateTime.Now;
                    _context.tbl_usermaster.Add(_RetObj);
                }
                else
                {
                    // Update
                    tbl_usermaster _RetObj = _context.tbl_usermaster.AsEnumerable().FirstOrDefault(q => q.Id == User.Id);
                    _RetObj.Id         = User.Id;
                    _RetObj.Name       = User.Name;
                    _RetObj.Birthdate  = Convert.ToDateTime(User.Birthdate);
                    _RetObj.Email      = User.Email;
                    _RetObj.Mobile     = User.Mobile;
                    _RetObj.Age        = User.Age;
                    _RetObj.Gender     = User.Gender;
                    _RetObj.RoleId     = User.RoleId;
                    _RetObj.ProfileUrl = User.ProfileUrl;
                    _RetObj.UpdatedAt  = DateTime.Now;
                }
                _context.SaveChanges();
                isUpdated = true;
            }
            return(isUpdated);
        }
コード例 #2
0
ファイル: UserService.cs プロジェクト: vpj124/practicaltest
        public bool Exist(string Email, string id)
        {
            bool isUpdated = true;

            using (PracticalTestEntities _context = new PracticalTestEntities())
            {
                var            _id     = Guid.Parse(id);
                tbl_usermaster _RetObj = _context.tbl_usermaster.AsEnumerable().FirstOrDefault(q => q.Email == Email);

                if (_RetObj == null)
                {
                    isUpdated = false;
                }

                if (_id != Guid.Empty)
                {
                    isUpdated = _RetObj.Id != _id ? true : false;
                }
                return(isUpdated);
            }
        }
コード例 #3
0
ファイル: UserService.cs プロジェクト: vpj124/practicaltest
        public bool Delete(string Id)
        {
            bool isUpdated = false;

            using (PracticalTestEntities _context = new PracticalTestEntities())
            {
                var            _id     = Guid.Parse(Id);
                tbl_usermaster _RetObj = _context.tbl_usermaster.AsEnumerable().FirstOrDefault(q => q.Id == _id);
                if (_RetObj.IsActive == true)
                {
                    _RetObj.IsActive = false;
                }
                else
                {
                    _RetObj.IsActive = true;
                }
                _context.SaveChanges();
                isUpdated = true;
                return(isUpdated);
            }
        }
コード例 #4
0
        public static UserViewModel ToModel(this tbl_usermaster Entity)
        {
            if (Entity == null)
            {
                throw new ArgumentException("Entity");
            }

            return(new UserViewModel()
            {
                Id = Entity.Id,
                Name = Entity.Name,
                Birthdate = Entity.Birthdate.Value.ToString("yyyy-MM-dd"),
                Email = Entity.Email,
                Mobile = Entity.Mobile,
                Age = Entity.Age,
                Gender = Entity.Gender,
                RoleId = Entity.RoleId,
                ProfileUrl = Entity.ProfileUrl,
                IsActive = Entity.IsActive,
                CreatedAt = Entity.CreatedAt != null ? Entity.CreatedAt.Value : DateTime.Now,
                UpdatedAt = Entity.UpdatedAt != null ? Entity.UpdatedAt.Value : DateTime.Now
            });
        }