Esempio n. 1
0
 public bool AddUser(Register userModel)
 {
     try
     {
         using (TestAppDbEntities context = new TestAppDbEntities())
         {
             UserInfo objUser = new UserInfo()
             {
                 Name     = userModel.Name,
                 Email    = userModel.Email,
                 Password = userModel.Password,
                 DOB      = userModel.DOB,
                 Location = userModel.Location,
                 UsrType  = userModel.UsrType
             };
             context.UserInfoes.Add(objUser);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw;
     }
     return(true);
 }
        public IHttpActionResult AddUser(Register regModel)
        {
            bool retVal = false;

            if (!ModelState.IsValid)
            {
                var getMessage = ModelState.Values.SelectMany(v => v.Errors.Select(d => d.ErrorMessage)).ToList()
                                 .LastOrDefault();
                _httpResponse = _commonRules.SetResponse(bool.FalseString, "DC1000:Failed.");
                _httpResponse.Add(bool.FalseString, getMessage);

                return(Ok(_httpResponse));
            }
            try
            {
                using (TestAppDbEntities context = new TestAppDbEntities())
                {
                    if (context.UserInfoes.Any(o => o.Email == regModel.Email))
                    {
                        _httpResponse = _commonRules.SetResponse(bool.FalseString, "DC2000:Email already in use.");
                        return(Ok(_httpResponse));
                    }
                }
                retVal = _userBusiness.AddUser(regModel);
                if (retVal)
                {
                    _httpResponse = _commonRules.SetResponse(bool.TrueString, "DC1000:Success.");
                }
            }
            catch (Exception ex)
            {
            }
            return(Ok(_httpResponse));
        }
Esempio n. 3
0
        public UsersList GetUser(int id)
        {
            UsersList        _result   = null;
            List <UserSkill> skill     = new List <UserSkill>();
            UserInfo         data      = null;
            List <UserData>  skillList = null;

            try
            {
                using (TestAppDbEntities context = new TestAppDbEntities())
                {
                    var query = from st in context.UserInfoes where st.UserId == id select st;
                    data = query.FirstOrDefault <UserInfo>();

                    skillList = context.UserDatas.Where(a => a.UserId == id).ToList();
                }
                _result = new UsersList()
                {
                    Name     = data.Name,
                    Email    = data.Email,
                    DOB      = data.DOB,
                    Location = data.Location,
                };

                UserSkill us = null;
                foreach (var x in skillList)
                {
                    us               = new UserSkill();
                    us.UserId        = x.UserId;
                    us.Skill         = x.Skill;
                    us.Experience    = x.Experience;
                    us.Certification = x.Certification;
                    us.id            = x.id;

                    skill.Add(us);
                    us = null;
                }
                if (skill.Count > 0)
                {
                    _result.userSkills = skill;
                }
            }
            catch (Exception Ex)
            {
                throw;
            }
            return(_result);
        }
Esempio n. 4
0
        public bool DeleteUser(int id)
        {
            using (TestAppDbEntities context = new TestAppDbEntities())
            {
                try
                {
                    var user       = context.UserInfoes.Where(x => x.UserId == id);
                    var userDetail = context.UserDatas.Where(x => x.UserId == id);

                    context.UserInfoes.RemoveRange(user);
                    context.UserDatas.RemoveRange(userDetail);

                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
            return(true);
        }
Esempio n. 5
0
        public bool UpdateUser(UpdateUser viewModel)
        {
            using (TestAppDbEntities context = new TestAppDbEntities())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        UserInfo _userInfo = new UserInfo();
                        _userInfo          = context.UserInfoes.First(a => a.UserId == viewModel.UserId);
                        _userInfo.Email    = viewModel.Email;
                        _userInfo.Name     = viewModel.Name;
                        _userInfo.DOB      = viewModel.DOB;
                        _userInfo.Location = viewModel.Location;

                        context.SaveChanges();
                        UserData _userData;
                        foreach (var item in viewModel.userSkills)
                        {
                            _userData = context.UserDatas.First(a => a.id == item.id);

                            _userData.Skill         = item.Skill;
                            _userData.Experience    = item.Experience;
                            _userData.Certification = item.Certification;

                            context.SaveChanges();
                        }

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                    }
                }
            }
            return(true);
        }
Esempio n. 6
0
        public List <UsersList> GetUsersList()
        {
            using (TestAppDbEntities context = new TestAppDbEntities())
            {
                List <UsersList> result = new List <UsersList>();
                UsersList        _list  = new UsersList();
                List <UserInfo>  data   = context.UserInfoes.Where(a => a.UsrType == "User").ToList();

                foreach (var x in data)
                {
                    _list          = new UsersList();
                    _list.UserId   = x.UserId;
                    _list.Name     = x.Name;
                    _list.Email    = x.Email;
                    _list.DOB      = x.DOB;
                    _list.Location = x.Location;

                    result.Add(_list);
                    _list = null;
                }
                return(result);
            };
        }
Esempio n. 7
0
 public bool AddUserSkills(UserData userModel)
 {
     try
     {
         using (TestAppDbEntities context = new TestAppDbEntities())
         {
             UserData objUser = new UserData()
             {
                 Skill         = userModel.Skill,
                 Experience    = userModel.Experience,
                 Certification = userModel.Certification,
                 UserId        = userModel.UserId
             };
             context.UserDatas.Add(objUser);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw;
     }
     return(true);
 }
Esempio n. 8
0
 public UserInfo Login(Login loginModel)
 {
     using (TestAppDbEntities context = new TestAppDbEntities())
     {
         UserInfo result = null;
         var      data   = context.UserInfoes
                           .Where(o => o.Email == loginModel.Email && o.Password == loginModel.Password)
                           .FirstOrDefault();
         if (data != null)
         {
             result = new UserInfo()
             {
                 Name     = data.Name,
                 Email    = data.Email,
                 UserId   = data.UserId,
                 Age      = data.Age,
                 DOB      = data.DOB,
                 Location = data.Location,
                 UsrType  = data.UsrType
             };
         }
         return(result);
     }
 }