示例#1
0
        public object getAllUsers()
        {
            db.Configuration.ProxyCreationEnabled = false;
            dynamic toReturn = new ExpandoObject();


            try

            {
                List <dynamic> returnUsers = new List <dynamic>();
                List <User>    users       = db.Users.Include(x => x.User_Type).ToList();
                foreach (var user in users)
                {
                    User_Type type = db.User_Type.Where(x => x.UserTypeID == user.UserTypeID).FirstOrDefault();
                    dynamic   item = new ExpandoObject();
                    item.UserName    = user.UserName;
                    item.UserSurname = user.UserSurname;
                    item.UserCell    = user.UserCell;
                    item.UserEmail   = user.UserEmail;
                    item.UserType    = type;

                    returnUsers.Add(item);

                    toReturn = returnUsers;
                }
            }
            catch
            {
                toReturn.Error = "Search Interrupted. Retry";
            }

            return(toReturn);
        }
        public bool LogIn()
        {
            UserRepository ur   = new UserRepository(-1, "AccessModel", "LogIN");
            User_Type      user = ur.GetUser(UserName, Encrypt(UserPassword), HttpContext.Current.Request.UserHostAddress, RememberMe);
            bool           bRet = false;

            if (user != null)
            {
                if (user.UserID > 0)
                {
                    User = new UserType
                    {
                        Email        = user.Email,
                        FirstName    = user.FirstName,
                        IPAddress    = user.IPAddress,
                        LastName     = user.LastName,
                        RememberMe   = user.RememberMe,
                        RoleId       = user.RoleId,
                        RoleName     = user.RoleName,
                        UserID       = user.UserID,
                        UserName     = user.UserName,
                        Confirmed    = user.Confirmed,
                        SessionStart = DateTime.Now
                    };
                    ur.LogIn();
                    bRet = true;
                }
            }
            //record the login
            return(bRet);
        }
示例#3
0
        public bool SetNewPassword(string UserPassword)
        {
            bool   bRet = false;
            string sSQL = "UPDATE [dbo].[webpages_Membership] SET [Password] = @Password, [PasswordChangedDate] = getdate() WHERE [UserId]=@UserID";
            //see if this is the roleid needs to be changed
            User_Type user = new User_Type();

            using (Data DC = new Data("conn", Page, Process))
            {
                try
                {
                    DC.AddCommand(CommandType.Text, sSQL);
                    DC.AttachParameterByValue("Password", UserPassword);
                    DC.AttachParameterByValue("UserID", UserID);
                    int iRet = DC.ExecuteCommand();
                    if (iRet > 0)
                    {
                        bRet = true;
                    }
                }
                catch (Exception ex)
                {
                    DC.MakeError(ex, Process, sSQL);
                }

                finally
                {
                    DC.Dispose();
                }
            }
            return(bRet);
        }
示例#4
0
        public string GetPasswordToken()
        {
            string sRet = "";
            string sSQL = "SELECT [ConfirmationToken] FROM [dbo].[webpages_Membership] WHERE [UserId]=@UserID";
            //see if this is the roleid needs to be changed
            User_Type user = new User_Type();

            using (Data DC = new Data("conn", Page, Process))
            {
                try
                {
                    DC.AddCommand(CommandType.Text, sSQL);
                    DC.AttachParameterByValue("UserID", UserID);
                    sRet = DC.ExecuteScalar().StringSafe();
                }
                catch (Exception ex)
                {
                    DC.MakeError(ex, Process, sSQL);
                }

                finally
                {
                    DC.Dispose();
                }
            }
            return(sRet);
        }
        public int Register()
        {
            string plug   = EMail + DateTime.Today.ToShortDateString();
            string sToken = Encrypt(plug);

            sToken = Scrub(sToken);
            User_Type user = new User_Type
            {
                Email      = EMail,
                FirstName  = FirstName,
                LastName   = LastName,
                Pass       = Encrypt(UserPassword),
                UserName   = UserName,
                RememberMe = RememberMe,
                IPAddress  = HttpContext.Current.Request.UserHostAddress,
                Token      = sToken
            };

            int iRet = new UserRepository(-1, "AccessModel", "Register").CreateUser(user);

            if (iRet > 1)
            {
                SendConfirmationEmail(sToken, iRet);
            }

            return(iRet);
        }
示例#6
0
        public ActionResult AddUserType(User_Type userType)
        {
            try
            {
                if (userType.Id == 0)
                {
                    userType.Created_By       = Session["user"].ToString();
                    userType.Institution_Code = Session["Institution_Code"].ToString();

                    bussiness.Add <User_Type>(userType);
                }
                else
                {
                    userType.Modified_By = Session["user"].ToString();
                    userType.Modified_On = DateTime.Now;
                    bussiness.Update <User_Type>(userType);
                }

                ModelState.Clear();
                return(View("UserType"));
            }
            catch (Exception e)
            {
                return(View("Index"));
            }
        }
示例#7
0
        public bool RememberMe(string ipAddress)
        {
            UserRepository u    = new UserRepository(UserID, "ProcessLogin", "RememberMe");
            User_Type      user = u.FindUser(ipAddress);

            DatabaseDown = u.DatabaseDown;

            if (user != null && user.UserID > 0)
            {
                UserType _user = new UserType
                {
                    Confirmed    = user.Confirmed,
                    Email        = user.Email,
                    FirstName    = user.FirstName,
                    IPAddress    = user.IPAddress,
                    LastName     = user.LastName,
                    Pass         = true,
                    RoleId       = user.RoleId,
                    RoleName     = user.RoleName,
                    SessionStart = DateTime.Now,
                    UserID       = user.UserID,
                    UserName     = user.UserName
                };
                User = _user;
            }

            return(user.RememberMe);
        }
示例#8
0
        public async static void Initialize(IServiceProvider serviceProvider)
        {
            using var context = new App_Context(serviceProvider.GetRequiredService <DbContextOptions <App_Context> >());
            context.Database.EnsureCreated();
            if (await context.USER_TYPE.AnyAsync())
            {
                return;   // DB has been seeded
            }
            var userTypes = new User_Type[]
            {
                new User_Type {
                    Id = 1, Active = true, Name = "Company User"
                },
                new User_Type {
                    Id = 2, Active = true, Name = "Applicant"
                }
            };

            foreach (User_Type userType in userTypes)
            {
                context.Add(userType);
            }
            context.Database.OpenConnection();
            context.Database.ExecuteSqlRaw(@"SET IDENTITY_INSERT dbo.USER_TYPE ON;");
            await context.SaveChangesAsync();

            context.Database.ExecuteSqlRaw(@"SET IDENTITY_INSERT dbo.USER_TYPE OFF;");
            context.Database.CloseConnection();
        }
示例#9
0
        public bool VerifyLogin(string UserName, string Password, bool RememberMe)
        {
            bool bRet = false;

            UserRepository u    = new UserRepository(UserID, "ProcessLogin", "VerifyLogin");
            User_Type      user = u.GetUser(UserName, Password, IPAddress, RememberMe);

            if (user != null && user.UserID > 0)
            {
                UserType _user = new UserType
                {
                    Confirmed    = user.Confirmed,
                    Email        = user.Email,
                    FirstName    = user.FirstName,
                    IPAddress    = user.IPAddress,
                    LastName     = user.LastName,
                    Pass         = true,
                    RememberMe   = user.RememberMe,
                    RoleId       = user.RoleId,
                    RoleName     = user.RoleName,
                    SessionStart = DateTime.Now,
                    UserID       = user.UserID,
                    UserName     = user.UserName
                };
                User = _user;
                UserCache.RemoveFromCache(0, IPAddress);
                UserCache.AddToCache(_user);
                bRet = true;
            }

            return(bRet);
        }
示例#10
0
        public bool SavePasswordToken(int UserID, string sToken)
        {
            bool   bRet = false;
            string sSQL = "UPDATE [dbo].[webpages_Membership] SET [ConfirmationToken] = @Token WHERE [UserId]=@UserID";
            //see if this is the roleid needs to be changed
            User_Type user = new User_Type();

            using (Data DC = new Data("conn", Page, Process))
            {
                try
                {
                    DC.AddCommand(CommandType.Text, sSQL);
                    DC.AttachParameterByValue("Token", sToken);
                    DC.AttachParameterByValue("UserID", UserID);
                    int iRet = DC.ExecuteCommand();
                    if (iRet > 0)
                    {
                        bRet = true;
                    }
                }
                catch (Exception ex)
                {
                    DC.MakeError(ex, Process, sSQL);
                }

                finally
                {
                    DC.Dispose();
                }
            }
            return(bRet);
        }
示例#11
0
        public User_Type GetUser(string UserName, string Password, string ipAddress, bool RememberMe)
        {
            string sSQL = "SELECT u.[UserID], [UserName], [IPAddress], [FirstName], [LastName], [Email], r.RoleID, RoleName, RememberMe, [IsConfirmed] FROM [dbo].[UserProfile] u " +
                          "LEFT JOIN [dbo].[webpages_Membership] m ON m.UserID = u.UserID " +
                          "LEFT JOIN [dbo].[webpages_UsersInRoles] r ON r.UserID = u.UserID " +
                          "LEFT JOIN [dbo].[webpages_Roles] wr ON wr.RoleID = r.RoleID " +
                          "WHERE u.[UserName] = @UserName AND (u.[Password] = @Password OR m.Password=@Password)";

            User_Type user = new User_Type();

            using (Data DC = new Data("conn", Page, Process))
            {
                try
                {
                    DC.AddCommand(CommandType.Text, sSQL);
                    DC.AttachParameterByValue("UserName", UserName);
                    DC.AttachParameterByValue("Password", Password);

                    DataTable dt = DC.ExecuteCommandForDT();

                    if (dt != null)
                    {
                        if (dt.Rows.Count > 0)
                        {
                            DataRow dr       = dt.Rows[0];
                            int     ID       = (int)Utils.ParseNumControlledReturn(dr["UserID"]);
                            bool    remember = Utils.ParseBoolSafe(dr["RememberMe"]);
                            if (remember != RememberMe)
                            {
                                UpdateRemember(ID, RememberMe, DC);
                            }

                            user = new User_Type
                            {
                                Confirmed  = Utils.ParseBoolSafe(dr["isConfirmed"]),
                                Email      = dr["Email"].StringSafe(),
                                FirstName  = dr["FirstName"].StringSafe(),
                                IPAddress  = CompareIP(ID, dr["IPAddress"].StringSafe(), ipAddress, DC),
                                LastName   = dr["LastName"].StringSafe(),
                                Pass       = "",
                                RoleId     = (int)Utils.ParseNumControlledReturn(dr["RoleID"]),
                                RoleName   = dr["RoleName"].StringSafe(),
                                UserID     = ID,
                                UserName   = UserName,
                                RememberMe = RememberMe
                            };
                        }
                    }
                }
                catch (Exception ex)
                {
                    DC.MakeError(ex, Process, sSQL);
                }
                finally
                {
                    DC.Dispose();
                }
            }
            return(user);
        }
        public void UpdateUserType(int idUser, User_Type user_Type)
        {
            string SQLcommand = $"UPDATE [User] SET id_user_type={(int)user_Type+1} WHERE id_user={idUser};";

            DataBaseI.Instance.Connect();
            DataBaseI.Instance.ExecuteCommand(SQLcommand);
            DataBaseI.Instance.Disconnect();
        }
示例#13
0
        public async Task <ActionResult <BaseResponse> > Post(User_Type ut)
        {
            _context.User_Types.Add(ut);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("Get", new { id = ut.Id }, new BaseResponse {
                data = ut
            }));
        }
示例#14
0
        public dynamic createManager(Manager manager)
        {
            db.Configuration.ProxyCreationEnabled = false;
            dynamic toReturn = new ExpandoObject();

            try
            {
                //Get User Details From Input Parameter
                User user = db.Users.Where(x => x.UserID == manager.UserID).FirstOrDefault();

                //get user type of manager
                User_Type usertype = db.User_Type.Where(x => x.UTypeDescription == "Manager").FirstOrDefault();

                //set usertype to manager
                user.User_Type = usertype;
                db.SaveChanges();

                //Get Lists 0f Contains To Set In Create Dynamic Object From Input Parameter
                List <Container> containers        = manager.Containers.ToList();
                List <Container> managedContainers = new List <Container>();

                foreach (var con in containers)
                {
                    Container container = db.Containers.Where(x => x.ContainerID == con.ContainerID).SingleOrDefault();
                    managedContainers.Add(container);
                }

                //Set Manager Details To add
                Manager managerDetails = new Manager();
                if (manager != null)
                {
                    managerDetails.User               = user;
                    managerDetails.ManQualification   = manager.ManQualification;
                    managerDetails.ManNationality     = manager.ManNationality;
                    managerDetails.ManIDNumber        = manager.ManIDNumber;
                    managerDetails.ManNextOfKeenFName = manager.ManNextOfKeenFName;
                    managerDetails.ManNextOfKeenCell  = manager.ManNextOfKeenCell;
                    managerDetails.Containers         = managedContainers;

                    db.Managers.Add(managerDetails);
                    db.SaveChanges();

                    toReturn.Message = "Manager Profile Succesfully Created";
                }
                else
                {
                    toReturn.Message = "Manager Profile Not Found";
                }
            }
            catch
            {
                toReturn.Message = "Search Interrupted.Retry";
            }

            return(toReturn);
        }
示例#15
0
        public User_Type VerifyUserByEmail(string EMail)
        {
            string sSQL = "SELECT * FROM [dbo].[UserProfile] prof " +
                          "LEFT JOIN [dbo].[webpages_UsersInRoles] uir on uir.UserID = prof.UserID " +
                          "LEFT JOIN [dbo].[webpages_Roles] web on web.RoleId = uir.RoleId " +
                          "WHERE prof.Email = @Email";
            //see if this is the roleid needs to be changed
            User_Type user = new User_Type();

            using (Data DC = new Data("conn", Page, Process))
            {
                try
                {
                    DC.AddCommand(CommandType.Text, sSQL);
                    DC.AttachParameterByValue("Email", EMail);
                    DataTable dt = DC.ExecuteCommandForDT();
                    if (dt != null)
                    {
                        if (dt.Rows.Count > 0)
                        {
                            DataRow dr = dt.Rows[0];
                            user = new User_Type
                            {
                                UserID    = (int)Utils.ParseNumControlledReturn(dr["UserID"]),
                                FirstName = dr["FirstName"].StringSafe(),
                                LastName  = dr["LastName"].StringSafe(),
                                UserName  = dr["UserName"].StringSafe(),
                                Email     = dr["Email"].StringSafe(),
                                IPAddress = dr["IPAddress"].StringSafe(),
                                RoleId    = (int)Utils.ParseNumControlledReturn(dr["RoleID"]),
                                RoleName  = dr["RoleName"].StringSafe()
                            };
                        }
                    }
                    //now register this person
                    sSQL = "UPDATE [dbo].[webpages_Membership] SET [IsConfirmed] =1 WHERE UserID = " + user.UserID;
                    DC.AddCommand(CommandType.Text, sSQL);
                    DC.ExecuteCommand();

                    sSQL = "UPDATE [dbo].[webpages_UsersInRoles] SET RoleID =2 WHERE UserID = " + user.UserID;
                    DC.AddCommand(CommandType.Text, sSQL);
                    DC.ExecuteCommand();
                }
                catch (Exception ex)
                {
                    DC.MakeError(ex, Process, sSQL);
                }

                finally
                {
                    DC.Dispose();
                }
            }
            return(user);
        }
示例#16
0
        public dynamic deleteManager(int id)
        {
            db.Configuration.ProxyCreationEnabled = false;
            dynamic toReturn = new ExpandoObject();
            Manager manager  = new Manager();

            // Containers containers = new Container();

            try
            {
                manager = db.Managers.Include(x => x.Containers).Include(x => x.User).Where(x => x.ManagerID == id).FirstOrDefault();

                if (manager == null)
                {
                    toReturn.Message = "Manager Profile Not Found";
                }
                else
                {
                    List <Container> containers        = manager.Containers.ToList();
                    List <Container> managedContainers = new List <Container>();

                    foreach (var con in containers)
                    {
                        Container container = db.Containers.Where(x => x.ContainerID == con.ContainerID).FirstOrDefault();
                        manager.Containers.Remove(container);
                        db.SaveChanges();
                    }

                    User user = db.Users.Where(x => x.UserID == manager.UserID).FirstOrDefault();
                    //get user type of employee
                    User_Type usertype = db.User_Type.Where(x => x.UserTypeID == 2).FirstOrDefault();


                    //set usertype to employee
                    user.UserTypeID = usertype.UserTypeID;
                    user.User_Type  = usertype;
                    db.SaveChanges();


                    manager = db.Managers.Where(x => x.ManagerID == id).FirstOrDefault();
                    db.Managers.Remove(manager);
                    db.SaveChanges();
                    toReturn.Message = "Manager Profile Delete Successful";
                }
            }
            catch
            {
                toReturn.Message = "Manager Profile Delete Unsuccessful";
            }

            return(toReturn);
        }
        public ActionResult Edit(User_Type u)
        {
            var data = db.User_Type.Where(a => a.user_type_name == u.user_type_name && a.user_type_isDeleted != true && a.user_type_id != u.user_type_id).SingleOrDefault();

            if (data != null)
            {
                ViewBag.errMsg = Languages.Language.This_type_already_exist;
                return(View(u));
            }
            db.Entry(u).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#18
0
 public JsonResult DeleteUserType(string Id)
 {
     try
     {
         User_Type c = new User_Type();
         c.Id = Convert.ToInt16(Id);
         bussiness.Delete <User_Type>(c);
         return(Json("", JsonRequestBehavior.AllowGet));
     }catch (Exception e)
     {
         return(Json("", JsonRequestBehavior.AllowGet));
     }
 }
        public int Add(UsertypeViewModel newItem)
        {
            User_Type user = new User_Type()
            {
                id     = newItem.id,
                name   = newItem.name,
                active = newItem.active,
            };

            context.User_Type.Add(user);
            context.SaveChanges();
            return(1);
        }
示例#20
0
        private List <object> RunQuery(string data)
        {
            using (CHUMDB context = new CHUMDB())
            {
                DBGeneric <User> Users = new DBGeneric <User>(context);
                var test = Users.Read();

                List <object> returnvalue = null;

                User_Type UT = (from ut in context.User_Type
                                where ut.Label == data
                                select ut).FirstOrDefault();
                if (UT == null)
                {
                    throw new Exception("Can't Find User Type Paramater in DB: " + data);
                }

                if (UT.Label == "Teacher")
                {
                    returnvalue = (from usr in Users.Read()
                                   where usr.User_Type_ID == UT.ID &&
                                   usr.UserName != null &&
                                   !string.IsNullOrWhiteSpace(usr.UserName)
                                   orderby usr.User_Type_ID, usr.Year_Level
                                   select new
                    {
                        First_Name = usr.Preferred_First_Name,
                        Surname = usr.Preferred_Last_Name,
                        Email = usr.UserName + "@eq.edu.au"
                    }).ToList <object>();
                }

                if (data == "Student")
                {
                    returnvalue = (from usr in Users.Read()
                                   where usr.User_Type_ID == UT.ID &&
                                   usr.Exit_Date == null &&
                                   usr.UserName != null &&
                                   !string.IsNullOrWhiteSpace(usr.UserName)
                                   orderby usr.User_Type_ID, usr.Year_Level
                                   select new
                    {
                        First_Name = usr.Preferred_First_Name,
                        Surname = usr.Preferred_Last_Name,
                        Email = usr.UserName + "@eq.edu.au",
                        YearGroup = "Year " + usr.Year_Level
                    }).ToList <object>();
                }
                return(returnvalue ?? new List <object>());
            }
        }
        public ActionResult Create(User_Type u)
        {
            var data = db.User_Type.Where(a => a.user_type_name == u.user_type_name && a.user_type_isDeleted != true).SingleOrDefault();

            if (data != null)
            {
                ViewBag.errMsg = Languages.Language.This_type_already_exist;
                return(View(u));
            }
            db.User_Type.Add(u);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
示例#22
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            User_Type user_Type = db.User_Type.Find(id);

            if (user_Type == null)
            {
                return(HttpNotFound());
            }
            return(Json(user_Type));
        }
示例#23
0
        public User_Type GetUserByIPAddress(string IPAddress)
        {
            User_Type user = new User_Type();

            using (Data DC = new Data("conn", Page, Process))
            {
                string sSQL = "SELECT IsConfirmed, prof.UserID, FirstName, LastName, UserName, Email, IPAddress, web.RoleID, RoleName, RememberMe FROM [dbo].[UserProfile] prof " +
                              "LEFT JOIN [dbo].[webpages_Membership] m on m.UserID = prof.UserID " +
                              "LEFT JOIN [dbo].[webpages_UsersInRoles] uir on uir.UserID = prof.UserID " +
                              "LEFT JOIN [dbo].[webpages_Roles] web on web.RoleId = uir.RoleId " +
                              "WHERE prof.IPAddress = @IPAddress";
                //see if this is the roleid needs to be changed

                try
                {
                    DC.AddCommand(CommandType.Text, sSQL);
                    DC.AttachParameterByValue("IPAddress", IPAddress);
                    DataTable dt = DC.ExecuteCommandForDT();
                    if (dt != null)
                    {
                        if (dt.Rows.Count > 0)
                        {
                            DataRow dr = dt.Rows[0];
                            user = new User_Type
                            {
                                Confirmed  = Utils.ParseBoolSafe(dr["IsConfirmed"]),
                                UserID     = (int)Utils.ParseNumControlledReturn(dr["UserID"]),
                                FirstName  = dr["FirstName"].StringSafe(),
                                LastName   = dr["LastName"].StringSafe(),
                                UserName   = dr["UserName"].StringSafe(),
                                Email      = dr["Email"].StringSafe(),
                                IPAddress  = dr["IPAddress"].StringSafe(),
                                RoleId     = (int)Utils.ParseNumControlledReturn(dr["RoleID"]),
                                RoleName   = dr["RoleName"].StringSafe(),
                                RememberMe = Utils.ParseBoolSafe(dr["RememberMe"])
                            };
                        }
                    }
                }
                catch (Exception ex)
                {
                    DC.MakeError(ex, Process, sSQL);
                }
                finally
                {
                    DC.Dispose();
                }
            }
            return(user);
        }
        public bool UpdateUser()
        {
            User_Type user = new User_Type
            {
                Email      = EMail,
                FirstName  = FirstName,
                LastName   = LastName,
                UserName   = UserName,
                RememberMe = RememberMe,
                IPAddress  = HttpContext.Current.Request.UserHostAddress,
                UserID     = UserID
            };

            return(new UserRepository(UserID, "AccessModel", "UpdateUser").UpdateUser(user));
        }
示例#25
0
        public void LoadData()
        {
            using (CHUMDB context = new CHUMDB())
            {
                DBGeneric <User> Users = new DBGeneric <User>(context);

                List <object> returnvalue = null;
                string        paramavalue = this._Paramaters["User_Type"];

                User_Type UT = (from ut in context.User_Type
                                where ut.Label == paramavalue
                                select ut).FirstOrDefault();


                if (paramavalue == "Teacher")
                {
                    returnvalue = (from usr in Users.Read()
                                   where usr.User_Type_ID == UT.ID &&
                                   usr.Exit_Date == null &&
                                   usr.UserName != null
                                   select new
                    {
                        First_Name = usr.Preferred_First_Name,
                        Last_Name = usr.Preferred_Last_Name,
                        Email = usr.UserName + "@eq.edu.au"
                    }).ToList <object>();
                }

                if (paramavalue == "Student")
                {
                    returnvalue = (from usr in Users.Read()
                                   where usr.User_Type_ID == UT.ID &&
                                   usr.Exit_Date == null &&
                                   usr.UserName != null
                                   select new
                    {
                        First_Name = usr.Preferred_First_Name,
                        Last_Name = usr.Preferred_Last_Name,
                        Email = usr.UserName + "@eq.edu.au",
                        YearGroup = usr.Year_Level
                    }).ToList <object>();
                }

                this._Data = returnvalue ?? new List <object>();;
            }
        }
示例#26
0
        public object addUserTypeAccess(int accessid, int usertypeid)
        {
            db.Configuration.ProxyCreationEnabled = false;
            dynamic toReturn = new ExpandoObject();

            try
            {
                if (accessid == 0)
                {
                    return(toReturn.Message = "Add Unsuccesful: Access Not Selected");
                }
                if (usertypeid == 0)
                {
                    return(toReturn.Message = "Add Unsuccesful: User Type Not Selected");
                }
                Access    access    = db.Accesses.Where(x => x.AccessID == accessid).FirstOrDefault();
                User_Type user_Type = db.User_Type.Where(x => x.UserTypeID == usertypeid).FirstOrDefault();
                if (access != null && user_Type != null)
                {
                    User_Type_Access newaccess = new User_Type_Access();
                    newaccess.UserTypeID    = user_Type.UserTypeID;
                    newaccess.AccessID      = access.AccessID;
                    newaccess.AccessGranted = DateTime.Now;
                    newaccess.Access        = access;
                    newaccess.User_Type     = user_Type;

                    User_Type_Access found = db.User_Type_Access.Where(x => x.AccessID == newaccess.AccessID && x.UserTypeID == newaccess.AccessID).FirstOrDefault();
                    if (found == null)
                    {
                        db.User_Type_Access.Add(newaccess);
                        db.SaveChanges();
                        toReturn.Message = "User Type Access Added";
                    }
                    else
                    {
                        toReturn.Message = "User Type Access Is Already Set";
                    }
                }
            }
            catch
            {
                toReturn.Error = "Adding Access Unsuccesful ";
            }

            return(toReturn);
        }
示例#27
0
        public async Task <ActionResult <User_Type> > Put(long id, User_Type ut)
        {
            var utDB = await _context.User_Types.FindAsync(id);

            if (utDB == null)
            {
                return(NotFound());
            }
            utDB.USETNAME    = ut.USETNAME;
            utDB.USETISADMIN = ut.USETISADMIN;
            utDB.USETNOTE    = ut.USETNOTE;

            await _context.SaveChangesAsync();

            return(Ok(new BaseResponse {
                data = ut
            }));
        }
示例#28
0
        public object updateUserType(int id, string description)
        {
            db.Configuration.ProxyCreationEnabled = false;
            dynamic toReturn = new ExpandoObject();

            try
            {
                User_Type newType = db.User_Type.Where(x => x.UserTypeID == id).FirstOrDefault();
                newType.UTypeDescription = description;
                db.SaveChanges();

                toReturn.Message = "Update User Type Successful";
            }
            catch
            {
                toReturn.Error = "User Type Update Unsuccessful";
            }

            return(toReturn);
        }
        public User GetUser(int user_id)
        {
            User        user       = new User(0, User_Type.customer, null, null, null, null, null, null, 0, null, null);
            string      SQLcommand = $"SELECT * FROM [User] WHERE id_user={user_id}";
            List <User> usersHelp  = new List <User>();

            DataBaseI.Instance.Connect();
            IDataReader dataReader = DataBaseI.Instance.GetDataReader(SQLcommand);

            while (dataReader.Read())
            {
                int    id_user  = (int)dataReader["id_user"];
                int    type     = (int)dataReader["id_user_type"];
                string name     = dataReader["name"].ToString();
                string surname  = dataReader["surname"].ToString();
                string username = dataReader["username"].ToString();
                string password = dataReader["password"].ToString();
                string email    = dataReader["email"].ToString();
                string city     = dataReader["city"].ToString();
                int    zipcode  = (int)dataReader["zipcode"];
                string address  = dataReader["address"].ToString();
                int    id_image = (int)dataReader["id_image"];

                User_Type user_Type = User_Type.customer;
                if (type == 1)
                {
                    user_Type = User_Type.admin;
                }
                if (type == 2)
                {
                    user_Type = User_Type.worker;
                }

                Image imageH = GetImage(id_image);

                user = new User(id_user, user_Type, name, surname, username, password, email, city, zipcode, address, imageH);
            }
            dataReader.Close();
            DataBaseI.Instance.Disconnect();
            return(user);
        }
示例#30
0
        private static List <User_Model> ConvertToUserList(DataTable table)
        {
            var usertList = new List <User_Model>();

            foreach (DataRow row in table.Rows)
            {
                var user = new User_Model()
                {
                    ID         = (int)row[0],
                    Email      = (string)row[1],
                    Password   = (string)(row[2] ?? ""),
                    User_Name  = (string)(row[3] ?? ""),
                    Birth_Date = (DateTime)row[4],
                    UserType   = (User_Type)User_Type.ToObject(typeof(User_Type), row[5]),
                    Creat_Date = (DateTime)row[6]
                };

                usertList.Add(user);
            }
            return(usertList);
        }