Exemple #1
0
        public LoginViewModel Insert(LoginViewModel loginViewModel)
        {
            try
            {
                var user = _db.ONNET_USER.FirstOrDefault(u => u.Username == loginViewModel.Username && u.Password == loginViewModel.Password);

                if (user == null)
                {
                    var newuser = new ONNET_USER
                    {
                        Username = loginViewModel.Username,
                        //Password = Encrypt(new  LoginViewModel
                        //{
                        Password = loginViewModel.Password,
                        //}),
                        Email      = null,
                        Mobile     = null,
                        Department = null,
                        Title      = null,
                        Status     = null,
                        RoleId     = 3
                    };
                    using (MaxisEntities _db = new MaxisEntities())
                    {
                        _db.ONNET_USER.Add(newuser);
                        _db.SaveChanges();
                    }
                    var role = (from ep in _db.ONNET_USER
                                join e in _db.ONNET_USERROLE on ep.RoleId equals e.RoleId
                                where loginViewModel.Username == ep.Username
                                select new LoginViewModel()
                    {
                        Roles = e.RoleName,
                        RoleId = e.RoleId
                    }).Single();

                    return(role);
                }
                else
                {
                    var role = (from ep in _db.ONNET_USER
                                join e in _db.ONNET_USERROLE on ep.RoleId equals e.RoleId
                                where loginViewModel.Username == ep.Username
                                select new LoginViewModel()
                    {
                        Roles = e.RoleName,
                        RoleId = e.RoleId
                    }).Single();
                    return(role);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #2
0
 public void OnException(ExceptionContext filterContext)
 {
     if (!filterContext.ExceptionHandled)
     {
         var exceptionDetails = new EXCEPTIONLOG
         {
             EXCEPTION_MESSAGE = filterContext.Exception.Message,
             CONTROLLER_NAME   = filterContext.RouteData.Values["Controller"].ToString(),
             ACTION_NAME       = filterContext.RouteData.Values["Action"].ToString(),
             STACKTRACE        = "Inner Exception: " + filterContext.Exception.InnerException + "\nStacktrace: " + filterContext.Exception.StackTrace,
             LOG_TIME          = DateTime.Now,
             USERNAME          = HttpContext.Current.User.Identity.Name
         };
         _db.EXCEPTIONLOGs.Add(exceptionDetails);
         _db.SaveChanges();
     }
 }
Exemple #3
0
 public void Update(EditUserViewModel editViewModel)
 {
     try
     {
         var entity = _db.ONNET_USER.FirstOrDefault(u => u.UserId == editViewModel.UserId);
         if (entity != null)
         {
             entity.UserId     = editViewModel.UserId;
             entity.Username   = editViewModel.Username;
             entity.Email      = editViewModel.Email;
             entity.Mobile     = editViewModel.Mobile;
             entity.Department = editViewModel.Department;
             entity.Title      = editViewModel.Title;
             entity.Status     = editViewModel.Status;
         }
         _db.SaveChanges();
     }
     catch (Exception)
     {
         throw;
     }
 }