public dynamic Init_Admin() { try { DataClassesDataContext db = new DataClassesDataContext(); if (IsExists(db, "*****@*****.**")) { return(ReturnData.MessageFailed("Email is already registered", null)); } TBEmployee emp = new TBEmployee(); emp.IDRole = 1; emp.Name = "Admin WIT"; emp.Email = "*****@*****.**"; emp.Active = true; emp.Password = EncryptPassword("asdasd"); emp.DateInsert = DateTime.Now; emp.DateLastUpdate = DateTime.Now; db.TBEmployees.InsertOnSubmit(emp); db.SubmitChanges(); return(ReturnData.MessageSuccess("New employee was added", null)); } catch (Exception ex) { Class_Log_Error log = new Class_Log_Error(); log.Insert(ex.Message, ex.StackTrace); return(ReturnData.MessageFailed(ex.Message, null)); } }
public ReturnData AJAX_BE_Update_MyProfile_With_Token(string token, string name, string email, string password) { try { DataClassesDataContext db = new DataClassesDataContext(); var key = System.Configuration.ConfigurationManager.AppSettings["key"].ToString(); var result = JWT.JsonWebToken.DecodeToObject(token, key) as IDictionary <string, object>; TBEmployee emp = db.TBEmployees.Where(x => !x.Deflag && x.Email == result["email"] && x.Password == EncryptPassword(result["password"].ToString())).FirstOrDefault(); emp.Name = name; if (emp.Email != email) { if (IsExists(db, email)) { return(ReturnData.MessageFailed("Email is already registered", null)); } } emp.Email = email; if (password != "") { emp.Password = EncryptPassword(password); } emp.DateLastUpdate = DateTime.Now; db.SubmitChanges(); var _newToken = EncryptToken(email, password); HttpContext.Current.Response.Cookies.Add(new HttpCookie(System.Configuration.ConfigurationManager.AppSettings["cookieAdmin"].ToString(), _newToken)); return(ReturnData.MessageSuccess("OK", null)); } catch (JWT.SignatureVerificationException) { return(ReturnData.MessageFailed("token is invalid", null)); } }
public ReturnData AJAX_BE_Insert(int idRole, string name, string email, string password) { try { DataClassesDataContext db = new DataClassesDataContext(); if (IsExists(db, email)) { return(ReturnData.MessageFailed("Email is already registered", null)); } TBEmployee emp = new TBEmployee(); emp.IDRole = idRole; emp.Name = name; emp.Email = email; emp.Active = true; emp.Password = EncryptPassword(password); emp.DateInsert = DateTime.Now; emp.DateLastUpdate = DateTime.Now; db.TBEmployees.InsertOnSubmit(emp); db.SubmitChanges(); return(ReturnData.MessageSuccess("New employee was added", null)); } catch (Exception ex) { Class_Log_Error log = new Class_Log_Error(); log.Insert(ex.Message, ex.StackTrace); return(ReturnData.MessageFailed(ex.Message, null)); } }
public ReturnData AJAX_BE_Updates(int idEmployee, int idrole, string name, string email, string password) { try { DataClassesDataContext db = new DataClassesDataContext(); TBEmployee emp = db.TBEmployees.Where(x => !x.Deflag && x.IDEmployee == idEmployee).FirstOrDefault(); if (emp == null) { return(ReturnData.MessageFailed("Employee not found", null)); } emp.IDRole = idrole; emp.Name = name; if (emp.Email != email) { if (IsExists(db, email)) { return(ReturnData.MessageFailed("Email is already registered", null)); } } emp.Email = email; if (password != "") { emp.Password = EncryptPassword(password); } emp.DateLastUpdate = DateTime.Now; db.SubmitChanges(); return(ReturnData.MessageSuccess("Data updated successfully", null)); } catch (Exception ex) { Class_Log_Error log = new Class_Log_Error(); log.Insert(ex.Message, ex.StackTrace); return(ReturnData.MessageFailed(ex.Message, null)); } }
public ReturnData AJAX_BE_ChangeStatus(int idEmployee, bool status) { try { DataClassesDataContext db = new DataClassesDataContext(); TBEmployee emp = db.TBEmployees.Where(x => !x.Deflag && x.IDEmployee == idEmployee).FirstOrDefault(); if (emp == null) { return(ReturnData.MessageFailed("Employee not found", null)); } emp.Active = status; emp.DateLastUpdate = DateTime.Now; db.SubmitChanges(); return(ReturnData.MessageSuccess("Status changed successfully", null)); } catch (Exception ex) { Class_Log_Error log = new Class_Log_Error(); log.Insert(ex.Message, ex.StackTrace); return(ReturnData.MessageFailed(ex.Message, null)); } }