Ejemplo 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;
     }
 }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
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;
     }
 }
Ejemplo n.º 4
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;
     }
 }