Example #1
0
    protected void VeEditListView_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        string[] commandArgs = e.CommandArgument.ToString().Split(new char[] { ',' });
        string   veId        = commandArgs[0];
        string   veImgId     = commandArgs[1];

        Guid veGuid  = Guid.Parse(veId);
        Guid imgGuid = Guid.Parse(veImgId);

        if (e.CommandName == "SetAsMain")
        {
            CarClass cc = new CarClass(Profile.UserName);
            cc.SetMainImage(imgGuid, veGuid);

            UserControl ucx      = (UserControl)LoadControl("~/Controls/UserNoticeModal.ascx");
            Label       txtLabel = (Label)ucx.FindControl("TextLabel");
            txtLabel.Text = "Success!";
            Form.Controls.Add(ucx);
        }
        if (e.CommandName == "DeleteImg")
        {
            using (SwapEntities ent = new SwapEntities())
            {
                var delImg = (from tbl in ent.VeImages
                              where tbl.Id == imgGuid
                              select tbl).SingleOrDefault();

                if (delImg != null)
                {
                    string imgPath    = delImg.ImageUrl;
                    string serverPath = Server.MapPath(imgPath);
                    try
                    {
                        System.IO.File.Delete(serverPath);
                    }
                    catch
                    {
                    }

                    ent.DeleteObject(delImg);
                    ent.SaveChanges();

                    UserControl ucx      = (UserControl)LoadControl("~/Controls/UserNoticeModal.ascx");
                    Label       txtLabel = (Label)ucx.FindControl("TextLabel");
                    txtLabel.Text = "Success!";
                    Form.Controls.Add(ucx);
                }
            }
        }
        CarsGridView.DataSourceID = "CarsDataSource";
        CarsGridView.DataBind();
    }
Example #2
0
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int         rowIndex = Convert.ToInt32(e.CommandArgument);
        GridViewRow myRow    = GridView1.Rows[rowIndex];
        Label       veIdLbl  = (Label)myRow.FindControl("VeId");
        Label       veImgLbl = (Label)myRow.FindControl("ImgId");

        Guid veGuid  = Guid.Parse(veIdLbl.Text);
        Guid imgGuid = Guid.Parse(veImgLbl.Text);

        if (e.CommandName == "SetAsMain")
        {
            CarClass cc = new CarClass(Profile.UserName);
            cc.SetMainImage(imgGuid, veGuid);
            BindPage(veGuid);
            UserControl ucx      = (UserControl)LoadControl("~/Controls/UserNoticeModal.ascx");
            Label       txtLabel = (Label)ucx.FindControl("TextLabel");
            txtLabel.Text = "Success!";
            Form.Controls.Add(ucx);
        }
        if (e.CommandName == "DeleteImg")
        {
            using (SwapEntities ent = new SwapEntities())
            {
                var delImg = (from tbl in ent.VeImages
                              where tbl.Id == imgGuid
                              select tbl).SingleOrDefault();

                if (delImg != null)
                {
                    string imgPath    = delImg.ImageUrl;
                    string serverPath = Server.MapPath(imgPath);
                    try
                    {
                        System.IO.File.Delete(serverPath);
                    }
                    catch
                    {
                    }

                    ent.DeleteObject(delImg);
                    ent.SaveChanges();
                    BindPage(veGuid);

                    UserControl ucx      = (UserControl)LoadControl("~/Controls/UserNoticeModal.ascx");
                    Label       txtLabel = (Label)ucx.FindControl("TextLabel");
                    txtLabel.Text = "Success!";
                    Form.Controls.Add(ucx);
                }
            }
        }
    }
Example #3
0
// Method for cancelling a scheduled swap.
//
    public void CancelSwap(Guid swapGuid, string userFrom)
    {
        MessageClass mc = new MessageClass();
        string       userTo;

        using (SwapEntities ent = new SwapEntities())
        {
            var getSwap = (from tbl in ent.ScheduledSwaps
                           where tbl.Id == swapGuid
                           select tbl).SingleOrDefault();

            if (getSwap != null)
            {
                string myMsg;
                if (getSwap.UserMain == userFrom)
                {
                    userTo = getSwap.UserOther;
                }
                else
                {
                    userTo = getSwap.UserMain;
                }
                try
                {
                    ent.DeleteObject(getSwap);
                    ent.SaveChanges();

                    myMsg = "Sorry, unfortunately I am unable to commit to our scheduled swap on " + getSwap.DateFrom.ToShortDateString()
                            + ". I have cancelled the swap, I apologize for the inconvenience.";
                    mc.SendMsg(userFrom, userTo, myMsg, "QM");
                }
                catch
                {
                    myMsg = "I attempted to cancel our scheduled swap on " + getSwap.Date.ToShortDateString() +
                            ", but an error occurred. Unfortunately, I am unable to commit to this swap, sorry for the inconvenience.";
                    mc.SendMsg(userFrom, userTo, myMsg, "QM");
                }
            }
        }
    }
Example #4
0
    protected void CarsGridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "EditCar")
        {
            int      rowIndex = Convert.ToInt32(e.CommandArgument);
            CarClass cc       = new CarClass(Profile.UserName);
            int      miles    = 0;
            string   desc     = "";
            string   imgUrl   = "";

            GridViewRow myRow    = CarsGridView.Rows[rowIndex];
            TextBox     boxMiles = (TextBox)myRow.FindControl("EditMiles");
            TextBox     boxDesc  = (TextBox)myRow.FindControl("EditDesc");
            FileUpload  newImg   = (FileUpload)myRow.FindControl("FileUpload2");
            Label       myId     = (Label)myRow.FindControl("CarId");
            Guid        id       = Guid.Parse(myId.Text);

            if (boxMiles.Text != "")
            {
                miles = Convert.ToInt32(boxMiles.Text);
            }
            if (boxDesc.Text != "")
            {
                desc = boxDesc.Text;
            }

            cc.EditCarInfo(id, miles, desc);

            UserControl ucx      = (UserControl)LoadControl("~/Controls/UserNoticeModal.ascx");
            Label       txtLabel = (Label)ucx.FindControl("TextLabel");

            if (newImg.FileName != "")
            {
                string ext = System.IO.Path.GetExtension(newImg.FileName);
                if (ext == ".jpg" || ext == ".jpeg")
                {
                    string virtualPath  = "~/Images/";
                    string physicalPath = Server.MapPath(virtualPath);
                    Guid   fileName     = Guid.NewGuid();

                    newImg.SaveAs(System.IO.Path.Combine(physicalPath, fileName + ext));
                    imgUrl = System.IO.Path.Combine(virtualPath, fileName + ext);

                    if (cc.AddVehicleImage(imgUrl, id, false))
                    {
                        txtLabel.Text = "Success!";
                        Form.Controls.Add(ucx);
                    }
                    else
                    {
                        txtLabel.Text = "3 Images max.";
                        Form.Controls.Add(ucx);
                    }
                }
                else
                {
                    txtLabel.Text = "Image must be .jpg or .jpeg";
                    Form.Controls.Add(ucx);
                }
            }
            else
            {
                txtLabel.Text = "Success!";
                Form.Controls.Add(ucx);
            }

            CarsGridView.DataSourceID = "CarsDataSource";
            CarsGridView.DataBind();
        }
        if (e.CommandName == "DeleteVehicle")
        {
            using (SwapEntities myEnt = new SwapEntities())
            {
                string userName = Profile.UserName;
                string strId    = Convert.ToString(e.CommandArgument);
                Guid   veGuid   = Guid.Parse(strId);

                var checkSwaps = from tbl in myEnt.ScheduledSwaps
                                 where tbl.UserMain == userName &
                                 tbl.MainRated == false & tbl.VeMain == veGuid ||
                                 tbl.UserMain == userName &
                                 tbl.MainRated == false & tbl.VeOther == veGuid ||
                                 tbl.UserOther == userName &
                                 tbl.OtherRated == false & tbl.VeMain == veGuid ||
                                 tbl.UserOther == userName &
                                 tbl.OtherRated == false & tbl.VeOther == veGuid
                                 select tbl;

                if (checkSwaps.Count() >= 1)
                {
                    UserControl ucx      = (UserControl)LoadControl("~/Controls/UserNoticeModal.ascx");
                    Label       txtLabel = (Label)ucx.FindControl("TextLabel");
                    txtLabel.Text = "You cannot delete a vehicle with a scheduled swap pending.";
                    Form.Controls.Add(ucx);
                }
                else
                {
                    var getVe = (from vetbl in myEnt.UserVehicles
                                 where vetbl.Id == veGuid
                                 select vetbl).SingleOrDefault();

                    if (getVe != null)
                    {
                        myEnt.DeleteObject(getVe);
                        myEnt.SaveChanges();
                    }

                    var getImgs = from tbl in myEnt.VeImages
                                  where tbl.VehicleId == veGuid
                                  select tbl;

                    foreach (var item in getImgs)
                    {
                        string imgPath    = item.ImageUrl;
                        string serverPath = Server.MapPath(imgPath);
                        try
                        {
                            System.IO.File.Delete(serverPath);
                        }
                        catch
                        {
                        }
                    }

                    var validCheck = (from vetbl in myEnt.UserVehicles
                                      where vetbl.UserName == userName
                                      select vetbl).SingleOrDefault();

                    if (validCheck == null)
                    {
                        Profile.IsValidated = false;
                    }

                    Response.Redirect("~/MyProfile/EditProfile.aspx");
                }
            }
        }
    }