Ejemplo n.º 1
0
 public static User castUserTableToUser(UsersTable userTable)
 {
     try
     {
         User user = new User()
         {
             id           = userTable.id,
             cityCode     = LookupBL.getLookupByCode(Constants.CitiesTableName, userTable.cityCode),
             address      = userTable.address,
             birthDate    = DateTime.Parse(userTable.birthDate.ToString()),
             email        = userTable.email,
             firstName    = userTable.firstName,
             genderId     = LookupBL.getLookupByCode(Constants.GenderTableName, int.Parse(userTable.genderId.ToString())),
             houseNumber  = userTable.houseNumber,
             lastName     = userTable.lastName,
             neighborhood = userTable.neighborhood,
             password     = userTable.password,
             phone        = userTable.phone
         };
         return(user);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Ejemplo n.º 2
0
        public UsersTable UseLogin(LoginTable login)
        {
            // String pass = "******";
            //String email ="*****@*****.**";
            SqlConn();
            conn.Open();
            Response   response = new Response();
            SqlCommand cmd      = new SqlCommand("Select * From UsersTable Where Email=@UEmail And Password=@UPass ", conn);

            cmd.Parameters.AddWithValue("@UEmail", login.Email);
            cmd.Parameters.AddWithValue("@UPass", login.Password);

            SqlDataReader rdr     = cmd.ExecuteReader();
            UsersTable    NewUser = new UsersTable();

            if (rdr.Read())
            {
                NewUser.Id       = Convert.ToInt32(rdr["Id"]);
                NewUser.Name     = rdr["Name"].ToString();
                NewUser.Surname  = rdr["Surname"].ToString();
                NewUser.Address  = rdr["Address"].ToString();
                NewUser.Email    = rdr["Email"].ToString();
                NewUser.Mobile   = rdr["Mobile"].ToString();
                NewUser.Password = rdr["Password"].ToString();

                return(NewUser);

                conn.Close();
            }
            else
            {
            }
            conn.Close();
            return(NewUser);
        }
Ejemplo n.º 3
0
        public IHttpActionResult PutUsersTable(string id, UsersTable usersTable)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != usersTable.userid)
            {
                return(BadRequest());
            }

            db.Entry(usersTable).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UsersTableExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 4
0
        public ActionResult Registered([Bind(Include = "UserID,UserName, Password")] UsersTable _usersTable)
        {
            using (SqlConnection Conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["CGH"].ConnectionString))
            {
                Conn.Open();
                if ((_usersTable != null) && (ModelState.IsValid))
                // ModelState.IsValid,通過表單驗證(Server-side validation)需搭配 Model底下類別檔的 [驗證]
                {
                    string hash = GetSHA1.GetSHA1Hash(_usersTable.Password);

                    _usersTable.Password = hash;
                    string sqlstr = "INSERT INTO [UsersTable] (	[UserID],[UserName],[Password])";
                    sqlstr += " VALUES (@UserID,@UserName,@Password)";
                    int affectedRows = Conn.Execute(sqlstr, new
                    {
                        UserID   = _usersTable.UserID,
                        UserName = _usersTable.UserName,
                        Password = _usersTable.Password
                    });


                    return(RedirectToAction("Index"));
                }

                else
                {                                                      // 搭配 ModelState.IsValid,如果驗證沒過,就出現錯誤訊息。
                    ModelState.AddModelError("Value1", " 自訂錯誤訊息(1) "); // 第一個輸入值是 key,第二個是錯誤訊息(字串)
                    ModelState.AddModelError("Value2", " 自訂錯誤訊息(2) ");
                    return(View());                                    // 將錯誤訊息,返回並呈現在「新增」的檢視畫面上
                }
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// get a single user from the Db acording to User name and password
 /// </summary>
 /// <param name="Usernameparam"></param>
 /// <param name="passwordparam"></param>
 /// <returns>A single User model object</returns>
 public static UserModel GetSpesificUser(string Usernameparam, string passwordparam)
 {
     try
     {
         using (CarRentalDbV2Entities db = new CarRentalDbV2Entities())
         {
             UsersTable dbUser = db.UsersTables.SingleOrDefault(a => a.UserName == Usernameparam && a.UserPassword == passwordparam);
             if (dbUser == null)
             {
                 return(null);
             }
             return(new UserModel
             {
                 UserID = dbUser.ID,
                 FullName = dbUser.FullName,
                 UserIdNumber = dbUser.UserIdNumber,
                 UserAuthorization = dbUser.UserAuthorization,
                 UserBirthDate = dbUser.UserBirthDate,
                 UserEmail = dbUser.UserEmail,
                 UserName = dbUser.UserName,
                 UserPassword = dbUser.UserPassword,
                 UserSex = dbUser.UserSex,
                 UserImg = dbUser.UserImg
             });
         }
     }
     catch
     {
         return(null);
     }
 }
Ejemplo n.º 6
0
        public UsersTable userget(int EmpID)
        {
            UsersTable NewUser = new UsersTable();

            try
            {
                SqlConn();
                SqlCommand cmd = new SqlCommand("Select * From UsersTable Where Id=@UId ", conn);
                cmd.Parameters.AddWithValue("@UId", EmpID);
                conn.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                rdr.Read();

                NewUser.Id       = Convert.ToInt32(rdr["Id"]);
                NewUser.Name     = rdr["Name"].ToString();
                NewUser.Surname  = rdr["Surname"].ToString();
                NewUser.Address  = rdr["Address"].ToString();
                NewUser.Email    = rdr["Email"].ToString();
                NewUser.Mobile   = rdr["Mobile"].ToString();
                NewUser.Password = rdr["Password"].ToString();
                rdr.Close();

                conn.Close();
                return(NewUser);
            }
            catch
            {
                return(NewUser);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var userId = Session["UserID"];

            if (userId == null)
            {
                FormsAuthentication.SignOut();
                Session.Abandon();
                Response.Redirect("~/Account/Login.aspx");
            }
            CompetitionDataContext competitionDataBase = new CompetitionDataContext();
            UsersTable             user = (from usersTables in competitionDataBase.UsersTable
                                           where usersTables.ID == (int)userId
                                           select usersTables).FirstOrDefault();

            if (user != null)
            {
                Session["UserID"] = user.ID;
                Directions(user);
            }
            else
            {
                FormsAuthentication.SignOut();
                Session.Abandon();
                Response.Redirect("~/Account/Login.aspx");
            }
        }
        /// <summary>
        /// set a new rent to the DB
        /// </summary>
        /// <param name="newrentparam">a rent model object</param>
        /// <returns>true if the actions secseed false if it didnt</returns>
        public static bool AddNewRent(RentModel newrentparam)
        {
            try
            {
                using (CarRentalDbV2Entities db = new CarRentalDbV2Entities())
                {
                    UsersTable dbUser = db.UsersTables.FirstOrDefault(a => a.UserName == newrentparam.UserInfo.UserName);
                    CarsTable  dbCar  = db.CarsTables.FirstOrDefault(a => a.CarlicenseNumber == newrentparam.CarInfo.CarlicenseNumber);
                    if (dbUser == null || dbCar == null)
                    {
                        return(false);
                    }
                    RentTable NewRent = new RentTable
                    {
                        StartDate  = newrentparam.StartDate,
                        EndDate    = newrentparam.EndDate,
                        ReturnDate = newrentparam.ReturnDate,
                        UserID     = dbUser.ID,
                        CarID      = dbCar.ID
                    };

                    db.RentTables.Add(NewRent);
                    db.SaveChanges();
                    return(true);
                }
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 9
0
        public ActionResult Delete(string id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                using (VC_LMSEntities d = new VC_LMSEntities())
                {
                    var row = d.UsersTables.Where(x => x.EMPLOYEE_ID == id && x.ROLES == "Admin").FirstOrDefault();
                    if (row != null)
                    {
                        ViewBag.Message = "Cannot delete Admin";
                        return(View());
                    }
                    foreach (var item in d.Leaves)
                    {
                        if (item.Employee_Id == id)
                        {
                            d.Leaves.Remove(item);
                        }
                    }
                    UsersTable usertable = d.UsersTables.Where(x => x.EMPLOYEE_ID == id).FirstOrDefault();
                    d.UsersTables.Remove(usertable);
                    d.SaveChanges();
                }

                return(RedirectToAction("view"));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Insert an instance of User into storage
        /// </summary>
        /// <param name="iUser">The instance of user to insert</param>
        /// <returns>True if the insert was successful</returns>
        public Boolean InsertUser(User iUser)
        {
            Boolean pBlnCreatedTable = UsersTable.CreateIfNotExists();

            try
            {
                TableOperation pTOnInsert = TableOperation.Insert(iUser);
                TableResult    pTRtResult = UsersTable.Execute(pTOnInsert);
                switch (pTRtResult.HttpStatusCode)
                {
                case 200:
                case 204:
                {
                    Boolean pBlnRetVal;
                    pBlnRetVal = CreateDefaultUserProfile(iUser);
                    return(pBlnRetVal);
                }

                default:
                {
                    return(false);
                }
                }
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 11
0
 public static string[] AccountNotAcceptedUsers(int id)
 {
     UsersTable table = new UsersTable();
     string[] users = table.GetNotAcceptedUsers(id);
     table.Dispose();
     return(users);
 }
Ejemplo n.º 12
0
        public static bool confirmBorrow(int idBorrow)
        {
            bool res = LenderData.confirmBorrow(idBorrow);

            if (res == true)
            {
                LendsTable lendTable = LenderData.getLendsByIdBorrow(idBorrow);
                //השואל
                UsersTable borrow = UserData.getUserById(lendTable.borrowerId);
                BooksTable bt     = BooksData.getBookById(lendTable.bookId);
                //המשאיל
                UsersTable ut       = UserData.getUserById(bt.lenderId);
                string     bookName = LookupBL.getLookupByCode(Constants.BooksNameTableName, bt.nameId).Desc;
                string     message  = "הספר " + bookName + " שביקשת אושר על ידי בעל הספר   : ";
                message += " פרטי בעל הספר ליצירת קשר  : ";
                message += ut.firstName + " " + ut.lastName + ", ";
                message += "טלפון: " + ut.phone + " מייל " + ut.email;
                message += "<br/>  מיקום הספר: רחוב " + ut.address + " " + ut.houseNumber + " " + ut.neighborhood + " " +
                           LookupBL.getLookupByCode(Constants.CitiesTableName, ut.cityCode).Desc;
                //פניה לפונקציה ששולחת מייל על אישור השאלת הספר
                sendEmailFunc.sendEmailAsync(borrow.email, borrow.firstName +
                                             " " + borrow.lastName, message, "אישור השאלת ספר " + bookName);
            }
            return(false);
        }
Ejemplo n.º 13
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string guid = Request["confirm"];

        if (guid == null)
        {
            angryLabel.Text = "Confirmation Failed, no ID provided.  Please use the link contained in your confirmation email.";
        }
        else
        {
            UsersTable userTable = new UsersTable(new DatabaseConnection());
            int        userID    = userTable.authenticateConfirmationID(guid);
            if (userID == 0)
            {
                angryLabel.Text = "Confirmation ID not found. Please use the link contained in your confirmation email.";
                return;
            }
            else
            {
                userTable.confirmUser(userID);
                userTable.deleteConfirmationID(guid);

                angryLabel.Text = "Congratulations, your account is now confirmed and you may login.";
            }
        }
    }
Ejemplo n.º 14
0
        public List <UsersTable> GetUser(int EmpID)
        {
            List <UsersTable> UserData = new List <UsersTable>();

            SqlConn();
            SqlCommand cmd = new SqlCommand("Select * From UsersTable Where Id=@UId ", conn);

            cmd.Parameters.AddWithValue("@UId", EmpID);
            conn.Open();
            SqlDataReader rdr = cmd.ExecuteReader();

            if (rdr.Read())
            {
                UsersTable NewUser = new UsersTable();
                NewUser.Id       = Convert.ToInt32(rdr["Id"]);
                NewUser.Name     = rdr["Name"].ToString();
                NewUser.Surname  = rdr["Surname"].ToString();
                NewUser.Address  = rdr["Address"].ToString();
                NewUser.Email    = rdr["Email"].ToString();
                NewUser.Mobile   = rdr["Mobile"].ToString();
                NewUser.Password = rdr["Password"].ToString();
                UserData.Add(NewUser);
            }
            else
            {
            }
            conn.Close();
            return(UserData);
        }
Ejemplo n.º 15
0
    //Sends email to dungeonbuddy inbox
    protected void sendMessageButton_Click(object sender, EventArgs e)
    {
        UsersTable userTable = new UsersTable(new DatabaseConnection());
        string     username  = "******";

        if (messageTextField.Text == "")
        {
            angryLabel.ForeColor = System.Drawing.Color.Red;
            angryLabel.Text      = "No message provided.";
            return;
        }

        string contactType = contactTypeList.SelectedValue;
        string message     = $"Username: {userID.ToString()}\n" +
                             $"User Email: Not Done Yet.\n" +
                             $"Contact Type: {contactType}\n\n" +
                             $"Message:\n";

        message += messageTextField.Text;

        bool isSuccessful = Email.sendEmail("*****@*****.**", "New Contact Form Submission", message, username);

        if (isSuccessful)
        {
            angryLabel.ForeColor  = System.Drawing.Color.Green;
            angryLabel.Text       = "Message Sent!";
            messageTextField.Text = "";
        }
        else
        {
            angryLabel.ForeColor = System.Drawing.Color.Red;
            angryLabel.Text      = "Uh oh, something went wrong.  I'd tell you to contact the administrator but that's what you just failed to do...";
        }
    }
Ejemplo n.º 16
0
 public ActionResult LogIn([FromForm] User model)
 {
     try
     {
         bool result = CheckIfLoginAndPasswordAreCorrect(model);
         if (result)
         {
             var logins = UsersTable.GetDataByLogin(model.Login);
             var data   = GetIdAndRole(logins[0].Login);
             Properties.UserId   = data.Item1;
             Properties.UserRole = data.Item2;
             if (data.Item2 == 1)
             {
                 return(RedirectToAction("DoctorIndex", "Doctor"));
             }
             else
             {
                 return(RedirectToAction("PatientView", "Patient"));
             }
         }
         else
         {
             return(View());
         }
     }
     catch
     {
         return(View());
     }
 }
        public ActionResult Register(UserModel objectuser)
        {
            if (ModelState.IsValid)
            {
                if (objectUserEntities.UsersTables.Where(m1 => m1.Email == objectuser.Email).FirstOrDefault() == null)
                {
                    UsersTable UserTable1 = new UsersTable();
                    UserTable1.CreatedOn = (DateTime.Now);
                    UserTable1.FirstName = objectuser.FirstName;
                    UserTable1.LastName  = objectuser.LastName;
                    UserTable1.Email     = objectuser.Email;
                    UserTable1.PassWord  = objectuser.PassWord;
                    objectUserEntities.UsersTables.Add(UserTable1);
                    objectUserEntities.SaveChanges();
                    objectuser.successmessage = "User Registered successfully";

                    return(RedirectToAction("Login", "Account"));
                }
                else
                {
                    ModelState.AddModelError("Error", "Email Already exists");
                    return(View());
                }
            }

            return(View());
        }
Ejemplo n.º 18
0
        //  POST: api/UsersTable
        //[ResponseType(typeof(UsersTable))]
        public HttpResponseMessage PostUsersTable(UsersTable usersTable)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            db.userTables.Add(usersTable);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (UsersTableExists(usersTable.userid))
                {
                    return(Request.CreateResponse(HttpStatusCode.Conflict, "User Already Exist"));
                }
                else
                {
                    throw;
                }
            }

            //return CreatedAtRoute("DefaultApi", new { id = usersTable.userid }, usersTable);
            return(Request.CreateResponse(HttpStatusCode.OK, "Success..."));
        }
Ejemplo n.º 19
0
    //Quits the game on behalf of the player
    protected void leaveGameButton_Click(object sender, EventArgs e)
    {
        PartyMembersTable partyMembersTable = new PartyMembersTable(new DatabaseConnection());
        UsersTable        userTable         = new UsersTable(new DatabaseConnection());

        foreach (PartyMember pc in party.PartyMembers.Keys)
        {
            if (pc.UserID == (int)Session["userID"])
            {
                partyMembersTable.deletePartyMember(pc);
            }
        }

        userTable.deleteUserPlayerGame((int)Session["userID"], game.GameID);

        Session.Remove("savedContent");
        Session.Remove("activeGame");

        //Load Home page and eat cookie so no error from controls not existing
        this.Page.Session.Remove("gameLinkID");
        this.Page.Session.Remove("gameCategoryID");
        this.Page.Session.Remove("gamePanelID");
        this.Page.Session.Remove("gameTypePanelID");

        this.Page.Session.Remove("page");

        Response.Redirect("~/Home");
    }
Ejemplo n.º 20
0
        public IEnumerable <UsersTable> GetUsersList()
        {
            List <UsersTable> UserData = new List <UsersTable>();

            SqlConn();
            SqlCommand cmd = new SqlCommand("Select * From UsersTable", conn);

            conn.Open();
            SqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                UsersTable user = new UsersTable();
                user.Id       = Convert.ToInt32(rdr["Id"]);
                user.Name     = rdr["Name"].ToString();
                user.Surname  = rdr["Surname"].ToString();
                user.Email    = rdr["Email"].ToString();
                user.Mobile   = rdr["Mobile"].ToString();
                user.Address  = rdr["Address"].ToString();
                user.Password = rdr["Password"].ToString();
                UserData.Add(user);
            }
            conn.Close();
            return(UserData);
        }
Ejemplo n.º 21
0
 public static Books CastBookTableToBook(BooksTable bookTable)
 {
     try
     {
         Books book = new Books()
         {
             numberOfViewers = bookTable.numberOfViewers,
             picNAme         = bookTable.picNAme,
             //שליפת פרטי מחבר לפי קוד מחבר
             autherId = LookupBL.getLookupByCode(Constants.AutherTableName, bookTable.autherId),
             //שליפת פרטי קטגורית ספר לפי קוד קטגוריה
             categoryId  = LookupBL.getLookupByCode(Constants.BooksCategoryTableName, bookTable.categoryId),
             id          = bookTable.id,
             description = bookTable.description,
             numOfPages  = bookTable.numOfPages,
             isBorrowed  = bookTable.isBorrowed,
             lenderId    = bookTable.lenderId,
             //שליפת פרטי שם ספר לפי קוד שם
             nameId = LookupBL.getLookupByCode(Constants.BooksNameTableName, bookTable.nameId),
             //שליפת פרטי מוציא לאור לפי קוד מוציא לאור
             publishingId = LookupBL.getLookupByCode(Constants.PuplishingTableName, bookTable.publishingId)
                            // city=LookupBL.getLookupByCode(Constants.CitiesTableName,bookTable.UsersTable.cityCode)
         };
         UsersTable lender = UserData.getUserById(bookTable.lenderId);
         book.city = LookupBL.getLookupByCode(Constants.CitiesTableName, lender.cityCode);
         return(book);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Get a user from storage by its given user principal
        /// </summary>
        /// <param name="iUserPrincipal">User principal of the user to get</param>
        /// <returns>The requested user, if found in storage, otherwise null</returns>
        public User GetUser(ClaimsPrincipal iUserPrincipal)
        {
            Boolean     pBlnCreatedTable = UsersTable.CreateIfNotExists();
            TableResult pTRtResult       = new TableResult()
            {
                HttpStatusCode = 404
            };

            if (pBlnCreatedTable)
            {
                return(null);
            }
            else
            {
                String         pStrPartitionKey = iUserPrincipal.GetUserPartitionKey(ClaimsPrincipalExtensions.KeySource.email);
                String         pStrRowKey       = iUserPrincipal.GetUserRowKey(ClaimsPrincipalExtensions.KeySource.email);
                TableOperation pTOnRetrieve     = TableOperation.Retrieve <User>(pStrPartitionKey, pStrRowKey);
                pTRtResult = UsersTable.Execute(pTOnRetrieve);
                switch (pTRtResult.HttpStatusCode)
                {
                case 200:
                {
                    return((User)pTRtResult.Result);
                }
                }
                return(null);
            }
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Edit a user Info
 /// </summary>
 /// <param name="Usernameparam">the User name</param>
 /// <param name="userparam">the User model object</param>
 /// <returns>true if the actions secseed false if it didnt</returns>
 public static bool EditUser(string Usernameparam, UserModel userparam)
 {
     try
     {
         using (CarRentalDbV2Entities db = new CarRentalDbV2Entities())
         {
             UsersTable dbUser = db.UsersTables.SingleOrDefault(a => a.UserName == Usernameparam);
             if (dbUser == null)
             {
                 return(false);
             }
             dbUser.UserAuthorization = userparam.UserAuthorization;
             dbUser.FullName          = userparam.FullName;
             dbUser.UserIdNumber      = userparam.UserIdNumber;
             dbUser.UserBirthDate     = userparam.UserBirthDate;
             dbUser.UserEmail         = userparam.UserEmail;
             dbUser.UserName          = userparam.UserName;
             dbUser.UserPassword      = userparam.UserPassword;
             dbUser.UserSex           = userparam.UserSex;
             dbUser.UserImg           = userparam.UserImg;
             db.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
        public void Directions(UsersTable user)
        {
            FormsAuthentication.SetAuthCookie(user.Email, true);

            int accessLevel = (int)user.AccessLevel;

            if (accessLevel == 0)
            {
                Response.Redirect("~/User/UserMainPage.aspx");
            }
            else if (accessLevel == 10)
            {
                Response.Redirect("~/Admin/Main.aspx");
            }
            else if (accessLevel == 5)
            {
                Response.Redirect("~/Expert/Main.aspx");
            }
            else if (accessLevel == 15)
            {
                Response.Redirect("~/Curator/CuratorMainPage.aspx");
            }
            else //если входим сюда то что то не так) скорей всего пользователю не присвоен уровень в UsersTable
            {
                FormsAuthentication.SignOut();
                Session.Abandon();
                Response.Redirect("~/Account/Login.aspx");
            }
        }
Ejemplo n.º 25
0
 /// <summary>
 /// Add a new User to the DB
 /// </summary>
 /// <param name="NewUser">A User model object</param>
 /// <returns>true if the actions secseed false if it didnt</returns>
 public static bool AddNewUser(UserModel NewUser)
 {
     try
     {
         using (CarRentalDbV2Entities db = new CarRentalDbV2Entities())
         {
             UsersTable dbUser = new UsersTable
             {
                 FullName          = NewUser.FullName,
                 UserIdNumber      = NewUser.UserIdNumber,
                 UserAuthorization = NewUser.UserAuthorization,
                 UserBirthDate     = NewUser.UserBirthDate,
                 UserEmail         = NewUser.UserEmail,
                 UserName          = NewUser.UserName,
                 UserPassword      = NewUser.UserPassword,
                 UserSex           = NewUser.UserSex,
                 UserImg           = NewUser.UserImg
             };
             db.UsersTables.Add(dbUser);
             db.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 26
0
 /// <summary>
 /// edit a rent acording to a rent id sent by the cient
 /// </summary>
 /// <param name="RentId">the rent id sent by the client</param>
 /// <param name="rentparam">a rent model contains all the rent data</param>
 /// <returns>true if the actions secseed false if it didnt</returns>
 public static bool EditRent(int RentId, RentModel rentparam)
 {
     try
     {
         using (CarRentalDbV2Entities db = new CarRentalDbV2Entities())
         {
             RentTable  dbrent = db.RentTables.SingleOrDefault(a => a.ID == RentId);
             UsersTable dbuser = db.UsersTables.SingleOrDefault(a => a.UserName == rentparam.UserInfo.UserName);
             CarsTable  dbcar  = db.CarsTables.SingleOrDefault(a => a.CarlicenseNumber == rentparam.CarInfo.CarlicenseNumber);
             if (dbrent == null || dbuser == null || dbcar == null)
             {
                 return(false);
             }
             dbrent.CarID      = dbcar.ID;
             dbrent.UserID     = dbuser.ID;
             dbrent.EndDate    = rentparam.EndDate;
             dbrent.ReturnDate = rentparam.ReturnDate;
             dbrent.StartDate  = rentparam.StartDate;
             db.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 27
0
        public async Task <string> UpdateUserById(UsersTable model)
        {
            try
            {
                UsersTable user = await db.Users.FindAsync(model.UserId);

                if (user != null)
                {
                    user.DisplayName  = model.DisplayName;
                    user.EmailAddress = model.EmailAddress;
                    user.FirstName    = model.FirstName;
                    user.LastName     = model.LastName;
                    user.JobTitle     = model.JobTitle;
                    await db.SaveChangesAsync();

                    return("Succesfully edit " + model.DisplayName);
                }
                else
                {
                    return("Cannot find detail user with ID " + model.UserId);
                }
            }
            catch (Exception x)
            {
                return(x.Message.ToString());
            }
        }
Ejemplo n.º 28
0
        public override async Task <IdentityResult> DeleteAsync(ApplicationUser <TKey> user, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            user.ThrowIfNull(nameof(user));

            return(await UsersTable.DeleteAsync(user));
        }
Ejemplo n.º 29
0
        /// <inheritdoc/>
        public override async Task <TUser> FindByNameAsync(string normalizedUserName, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            var user = await UsersTable.FindByNameAsync(normalizedUserName);

            return(user);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            UsersTable usersTable = db.UsersTables.Find(id);

            db.UsersTables.Remove(usersTable);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 31
0
        /// <inheritdoc/>
        protected override async Task <TUser> FindUserAsync(TKey userId, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            var user = await UsersTable.FindByIdAsync(userId);

            return(user);
        }
        public async Task InsertedUserToDb()
        {
            var googleAuthenticatorService = new AuthenticationGoogle();
            var userTable = new UsersTable();

            await googleAuthenticatorService.LoginGoogle(_testUsername);
            var user = userTable.GetRow(_testUsername);
            
            Assert.AreEqual(user.name, _testUsername);
        }
        public async Task UpdateSpecificUser()
        {
            var googleAuthenticatorService = new AuthenticationGoogle();
            var userTable = new UsersTable();
            await googleAuthenticatorService.LoginGoogle(_testUsername);
            var user = googleAuthenticatorService.GetCurrentUser();
            userTable.InsertRow(user);
            var updatedUser = AuthenticationGoogle.GetSpecificUser(_testUsername);

            Assert.AreNotEqual(user.expireDate, updatedUser.expireDate);
        }
 //[TestMethod]
 public void DeleteSpecificUserFromDb()
 {
     var userTable = new UsersTable();
     userTable.DeleteRow(_testUsername);
     GetSpecificUser();
 }
 //TODO: Check if DB is cleared
 public void ClearUserDb()
 {
     var userTable = new UsersTable();
     userTable.ClearUserDatabase(true);
 }
Ejemplo n.º 36
0
 public static void AddUser(int id, string username, bool accept)
 {
     UsersTable table = new UsersTable();
     table.Insert(id, username, accept);
     table.Dispose();
 }
Ejemplo n.º 37
0
 public static bool UserIsInList(int id, string username)
 {
     UsersTable table = new UsersTable();
     bool present = table.IsPresent(id, username);
     table.Dispose();
     return(present);
 }
Ejemplo n.º 38
0
        private AcceptUserType OnAcceptUser(PeerSocket peer, UserInfo userInfo)
        {
            if (userInfo.SecureAuthentication == false)
                return(AcceptUserType.Ask);

            UsersTable usersDb = new UsersTable();

            // If User isn't into DB
            if (usersDb.IsPresent(myAccountId, userInfo.Name) == false) {
                usersDb.Dispose();
                return(AcceptUserType.Ask);
            }

            // Get User Accept Status
            bool acceptUser = usersDb.GetAccept(myAccountId, userInfo.Name);

            usersDb.Dispose();
            return(acceptUser ? AcceptUserType.Yes : AcceptUserType.No);
        }