Exemplo n.º 1
0
 protected void btnRegister_Click(object sender, EventArgs e)
 {
     try
     {
         if (password.Text == confirmPassword.Text)
         {
             Helper helper  = new Helper();
             var    context = new ClayEntities();
             var    user    = new User()
             {
                 FullName   = name.Text,
                 Username   = username.Text,
                 Password   = helper.Encrypt(password.Text.Trim()),
                 PropertyID = Convert.ToInt32(propertyList.SelectedValue)
             };
             context.Users.Add(user);
             context.SaveChanges();
             ScriptManager.RegisterStartupScript(this, GetType(), "error", "alert('New user is added!');", true);
         }
         else
         {
             ScriptManager.RegisterStartupScript(this, GetType(), "error", "alert('Passwords do not match!');", true);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 2
0
 public void FillLogs()
 {
     using (var context = new ClayEntities())
     {
         var logs = context.CP_GetHistoryLogs();
         gvHistoryLogs.DataSource = logs;
         gvHistoryLogs.DataBind();
     }
 }
Exemplo n.º 3
0
 public void FillDoorList()
 {
     using (ClayEntities context = new ClayEntities())
     {
         var door = (from d in context.Doors
                     select new { d.DoorID, d.Description }).ToList();
         GridView1.DataSource = door;
         GridView1.DataBind();
     }
 }
Exemplo n.º 4
0
        public void FillPropertyList()
        {
            using (ClayEntities context = new ClayEntities())
            {
                var property = (from c in context.Properties
                                select new { c.PropertyID, c.PropertyName }).ToList();

                propertyList.DataValueField = "PropertyID";
                propertyList.DataTextField  = "PropertyName";
                propertyList.DataSource     = property;
                propertyList.DataBind();
            }
        }
Exemplo n.º 5
0
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                if (e.CommandName == "OpenDoor")
                {
                    // Retrieve the row index stored in the CommandArgument property.
                    int rowIndex = Convert.ToInt32(e.CommandArgument);

                    //Reference the GridView Row.
                    GridViewRow row = GridView1.Rows[rowIndex];

                    //Fetch value of Door ID
                    int doorId = Convert.ToInt32((row.FindControl("txtID") as TextBox).Text);

                    // Code to access the door
                    ClayEntities db   = new ClayEntities();
                    var          door = (from doorslist in db.Doors
                                         where doorslist.DoorID == doorId
                                         select new
                    {
                        doorslist.PropertyID
                    }).ToList();

                    if (door.FirstOrDefault().PropertyID == Convert.ToInt32(Session["PropertyID"]))
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), "error", "alert('You have access to this door');", true);

                        //Code to save the log
                        var context = new ClayEntities();
                        var log     = new HistoryLog()
                        {
                            UserID = Convert.ToInt32(Session["UserID"]),
                            DoorID = doorId,
                            Time   = DateTime.Now
                        };
                        context.HistoryLogs.Add(log);
                        context.SaveChanges();
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), "error", "alert('ACCESS DENIED');", true);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 6
0
 protected void btnAddDoor_Click(object sender, EventArgs e)
 {
     try
     {
         var context = new ClayEntities();
         var door    = new Door()
         {
             Description = doorDescription.Text,
             PropertyID  = Convert.ToInt32(propertyList.SelectedValue)
         };
         context.Doors.Add(door);
         context.SaveChanges();
         ScriptManager.RegisterStartupScript(this, GetType(), "error", "alert('Door is added to a property!');", true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 7
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         var context  = new ClayEntities();
         var property = new Property()
         {
             PropertyName  = name.Text,
             NumberOfDoors = Convert.ToInt32(numberOfDoors.Text)
         };
         context.Properties.Add(property);
         context.SaveChanges();
         ScriptManager.RegisterStartupScript(this, GetType(), "error", "alert('New Prpoerty is added!');", true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 8
0
        protected void btn_signin_Click(object sender, EventArgs e)
        {
            try
            {
                Helper       helper = new Helper();
                ClayEntities db     = new ClayEntities();
                var          user   = (from userlist in db.Users
                                       where userlist.Username == sign_username.Text //&& helper.Decrypt(userlist.Password) == sign_password.Text
                                       select new
                {
                    userlist.UserID,
                    userlist.Username,
                    userlist.Password,
                    userlist.FullName,
                    userlist.PropertyID
                }).ToList();

                if (user.FirstOrDefault() != null && helper.Decrypt(user.FirstOrDefault().Password) == sign_password.Text)
                {
                    //if login is successful
                    Session["UserName"]   = user.FirstOrDefault().Username;
                    Session["FullName"]   = user.FirstOrDefault().FullName;
                    Session["UserID"]     = user.FirstOrDefault().UserID;
                    Session["PropertyID"] = user.FirstOrDefault().PropertyID;
                    Response.Redirect("OpenDoor.aspx");
                }
                else
                {
                    //Invalid login credentials
                    ScriptManager.RegisterStartupScript(this, GetType(), "error", "alert('Invalid login credentials!');", true);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }