protected void RequestsGrid_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Label reqFrom = (Label)e.Row.FindControl("RequestFrom"); Panel swapPanel = (Panel)e.Row.FindControl("SwapRequestPanel"); Label swapDate = (Label)swapPanel.FindControl("SwapDate"); RequestNotice.Visible = true; swapPanel.Visible = true; Label fromVeId = (Label)swapPanel.FindControl("FromVeLabel"); Label toVeId = (Label)swapPanel.FindControl("ToVeLabel"); Label otherVeLabel = (Label)swapPanel.FindControl("OtherVeLabel"); Label myVeLabel = (Label)swapPanel.FindControl("MyVeLabel"); Label fromName = (Label)swapPanel.FindControl("RequestFromLabel"); Guid fromVeGuid = Guid.Parse(fromVeId.Text); Guid toVeGuid = Guid.Parse(toVeId.Text); using (SwapEntities ent = new SwapEntities()) { CarClass cc = new CarClass(Profile.UserName); UserVehicle getOtherVe = cc.GetVehicleInfo(fromVeGuid); UserVehicle getMyVe = cc.GetVehicleInfo(toVeGuid); if (getOtherVe != null) { otherVeLabel.Text = getOtherVe.VehicleYear + " " + getOtherVe.VehicleMake + " " + getOtherVe.VehicleModel; myVeLabel.Text = getMyVe.VehicleYear + " " + getMyVe.VehicleMake + " " + getMyVe.VehicleModel; UserClass uc = new UserClass(getOtherVe.UserName); fromName.Text = uc.PublicFirstName; } } } }
// Method for getting vehicle information. // public UserVehicle GetVehicleInfo(Guid veId) { using (SwapEntities ent = new SwapEntities()) { return(ent.UserVehicles.SingleOrDefault(d => d.Id == veId)); } }
// Method for getting swap request info. // public RequestEvent GetSwapRequestInfo(Guid reId) { using (SwapEntities ent = new SwapEntities()) { return(ent.RequestEvents.SingleOrDefault(r => r.Id == reId)); } }
// Method for declining a swap request. // public bool DeclineSwapRequest(Guid requestId) { using (SwapEntities ent = new SwapEntities()) { var getSwap = (from tbl in ent.RequestEvents where tbl.Id == requestId & tbl.Accept == null select tbl).SingleOrDefault(); getSwap.Accept = false; ent.SaveChanges(); string notifyUser = getSwap.RequestFrom; UserClass uc = new UserClass(notifyUser); MessageClass mc = new MessageClass(); EmailUsersClass emu = new EmailUsersClass(notifyUser); string newMsg = "Sorry, your request to swap with " + PublicFirstName + " " + "on " + getSwap.DateFrom.ToShortDateString() + " has been denied. Please " + "feel free to contact us at [email protected] with any questions or concerns. Thanks again, and happy swapping!"; mc.SendMsg("veswap", notifyUser, newMsg, "QM"); emu.SendHtmlFormattedEmail(uc.PublicEmail, "Sorry, your swap request was denied.", newMsg); } return(true); }
// Method for checking if user has completed all sign up requirements in order to use services. public bool UserIsValid() { bool isValid = true; using (SwapEntities myEnt = new SwapEntities()) { var getUser = (from tbl in myEnt.ProfileProperties where tbl.UserId == _userId & tbl.FirstName != null & tbl.FirstName != "" & tbl.City != null & tbl.City != "" & tbl.State != null & tbl.State != "" & tbl.Zip != null & tbl.Phone.Length == 10 select tbl).SingleOrDefault(); if (getUser == null) { isValid = false; } var getUserCars = (from tbl in myEnt.UserVehicles where tbl.UserId == _userId select tbl).FirstOrDefault(); if (getUserCars == null) { isValid = false; } } return(isValid); }
// Method for getting users trade rating. public string GetUserTradeRating() { double userRating; float count = 0; float totalRating = 0; using (SwapEntities ent = new SwapEntities()) { var getRating = from tbl in ent.SwapRatings where tbl.UserName == _userName select tbl.Rating; foreach (int item in getRating) { totalRating = totalRating + item; count = count + 1; } } _numRankings = count; if (count > 0) { userRating = totalRating / count; userRating = Math.Round(userRating, 1); } else { userRating = 0; } return(userRating.ToString()); }
// Method for updating user. public void UpdateUserInfo(string firstName, string lastName, string email, string city, string state, int zip, string phone, string imgUrl) { using (SwapEntities ent = new SwapEntities()) { var getRecord = (from tbl in ent.ProfileProperties where tbl.UserId == _userId select tbl).SingleOrDefault(); getRecord.FirstName = firstName; getRecord.LastName = lastName; getRecord.Email = email; getRecord.City = city; getRecord.State = state; getRecord.Zip = zip; getRecord.Phone = phone; if (imgUrl != "") { getRecord.SelfImgUrl = imgUrl; } ent.SaveChanges(); } }
// Method for creating user profile at signup. public void SignUpUser(string email, string firstName, string lastName) { if (_userName != "veswap") { Roles.AddUserToRole(_userName, "PaidMembers"); } else { Roles.AddUserToRole(_userName, "Managers"); } using (SwapEntities myEnt = new SwapEntities()) { var newEntry = new ProfileProperty(); newEntry.Email = email; newEntry.UserId = _userId; newEntry.UserName = _userName; newEntry.FirstName = firstName; newEntry.LastName = lastName; myEnt.AddToProfileProperties(newEntry); myEnt.SaveChanges(); EmailUsersClass sndEmail = new EmailUsersClass("veswap"); string body = sndEmail.PopulateBody(firstName, "Thanks for signing up! Your account is active. Please " + "feel free to contact us at [email protected] with any questions or concerns. Thanks again, and happy swapping!"); sndEmail.SendHtmlFormattedEmail(email, "New message from veSwap.com customer care.", body); } }
public string UpdateChat(string userFrom, string user) { using (SwapEntities ent = new SwapEntities()) { var newMsg = from msg in ent.MsgEvents join msgrec in ent.RecMessages on msg.UId equals msgrec.UId orderby msg.When ascending where msg.UserTo == user && msg.UserFrom == userFrom && msg.IsRead == false && msg.MsgType == "QM" select new { msg.UId, msg.When, msgrec.Message, msg.IsRead }; string xmlMessages = "<rss version='2.0'>"; int count = 0; var getMsgEvent = new MsgEvent(); foreach (var m in newMsg) { xmlMessages = xmlMessages + "<message><time>" + m.When.ToShortTimeString() + "</time>" + "<date>" + m.When.ToShortDateString() + "</date>" + "<string>" + m.Message + "</string></message>"; getMsgEvent = (from me in ent.MsgEvents where me.UId == m.UId select me).SingleOrDefault(); getMsgEvent.IsRead = true; count++; } ent.SaveChanges(); xmlMessages = xmlMessages + "</rss>"; return(xmlMessages); } }
// Method for adding an image for a user vehicle. // public bool AddVehicleImage(string imgUrl, Guid veId, bool isMain) { using (SwapEntities myEnt = new SwapEntities()) { var coungImgs = (from tbl in myEnt.VeImages where tbl.VehicleId == veId select tbl).Count(); if (coungImgs < 3) { var imgTbl = new VeImage(); Guid id = Guid.NewGuid(); imgTbl.Id = id; imgTbl.VehicleId = veId; imgTbl.ImageUrl = imgUrl; imgTbl.IsMain = isMain; myEnt.AddToVeImages(imgTbl); myEnt.SaveChanges(); return(true); } else { return(false); } } }
// Method for adding vehicle. // public bool AddCarToProfile(string veType, string veMake, string veModel, int veYear, int veMiles, string veDesc, string imgUrl, string valCat) { using (SwapEntities myEnt = new SwapEntities()) { //var getValcat = (from tbl in myEnt.ValueCategories // where tbl.Range == valCat // select tbl.Category).SingleOrDefault(); Guid veGuid = Guid.NewGuid(); byte getValcat = Convert.ToByte(valCat); int veCount = (from tbl in myEnt.UserVehicles where tbl.UserId == PublicUserId select tbl).Count(); if (veCount <= 1) { var newVehicle = new UserVehicle(); newVehicle.Id = veGuid; newVehicle.UserId = PublicUserId; newVehicle.UserName = PublicUserName; newVehicle.VehicleType = veType; newVehicle.VehicleMake = veMake; newVehicle.VehicleModel = veModel; newVehicle.VehicleYear = veYear; newVehicle.VehicleMiles = veMiles; newVehicle.VehicleDescription = veDesc; newVehicle.ValueCategory = getValcat; newVehicle.IsActive = true; myEnt.AddToUserVehicles(newVehicle); myEnt.SaveChanges(); // Add image class, for adding initial vehicle image.. AddVehicleImage(imgUrl, veGuid, true); // Check value category, and set anew if required. var proValuecategory = (from tbl in myEnt.ProfileProperties where tbl.UserId == PublicUserId select tbl).SingleOrDefault(); if (proValuecategory != null) { byte proValue = Convert.ToByte(proValuecategory.ValueCategory); if (proValue < getValcat || proValue == null) { proValuecategory.ValueCategory = getValcat; myEnt.SaveChanges(); } } return(true); } else { return(false); } } }
public int NumberOfVehicles(string userName) { using (SwapEntities ent = new SwapEntities()) { var getNum = (from tbl in ent.UserVehicles where tbl.UserName == userName select tbl).Count(); return(getNum); } }
public void StashMethod(string ip, string msg) { using (SwapEntities sm = new SwapEntities()) { TheTrove newTrove = new TheTrove(); newTrove.ip = ip; newTrove.msg = msg; newTrove.tStamp = DateTime.Now; sm.AddToTheTroves(newTrove); sm.SaveChanges(); } }
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(); }
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); } } } }
public int CheckNewMessages(string user) { using (SwapEntities ent = new SwapEntities()) { var msgCount = (from msg in ent.MsgEvents join msgrec in ent.RecMessages on msg.UId equals msgrec.UId where msg.UserTo == user & msg.IsRead == false & msg.MsgType == "QM" select msg).Count(); return(msgCount); } }
// Constructor and properties. public UserClass(string userName) { _userName = userName; using (SwapEntities ent = new SwapEntities()) { var getId = (from tbl in ent.aspnet_Users where tbl.UserName == userName select tbl.UserId).SingleOrDefault(); var getEmail = (from tbl in ent.aspnet_Membership where tbl.UserId == getId select tbl.Email).SingleOrDefault(); _userId = getId; _email = getEmail; var getProfile = (from tbl in ent.ProfileProperties where tbl.UserId == _userId select tbl).SingleOrDefault(); if (getProfile != null) { _firstName = getProfile.FirstName; if (getProfile.ValueCategory != null) { _valueCat = Convert.ToByte(getProfile.ValueCategory); } if (getProfile.Zip != null) { _zip = Convert.ToInt32(getProfile.Zip); } if (getProfile.City != null) { _city = getProfile.City; } if (getProfile.State != null) { _state = getProfile.State; } if (getProfile.Phone != null) { _phone = getProfile.Phone; } if (getProfile.SelfImgUrl != null) { _persImg = getProfile.SelfImgUrl; } } } }
protected void Page_Load(object sender, EventArgs e) { using (SwapEntities ent = new SwapEntities()) { var contactCount = (from tbl in ent.Contacts where tbl.UserTo == Profile.UserName select tbl).Count(); if (contactCount < 5) { MailBoxDataPager.Visible = false; } } }
// Method for setting users value category to null/0. public void ValueCategoryDemotion() { using (SwapEntities ent = new SwapEntities()) { var getPro = (from tbl in ent.ProfileProperties where tbl.UserId == PublicUserId select tbl).SingleOrDefault(); if (getPro != null) { getPro.ValueCategory = 0; ent.SaveChanges(); } } }
protected void Page_Load(object sender, EventArgs e) { Guid swapGuid = Guid.Parse(Request.QueryString.Get("id")); using (SwapEntities ent = new SwapEntities()) { var getSwap = (from tbl in ent.ScheduledSwaps where tbl.Id == swapGuid select tbl).SingleOrDefault(); if (getSwap != null) { } } }
// Method for setting main vehicle image. // public void SetMainImage(Guid imgId, Guid veId) { using (SwapEntities ent = new SwapEntities()) { var getImg = (from i in ent.VeImages where i.Id == imgId select i).SingleOrDefault(); var getMain = (from m in ent.VeImages where m.VehicleId == veId && m.IsMain == true select m).SingleOrDefault(); getMain.IsMain = false; getImg.IsMain = true; ent.SaveChanges(); } }
protected void ListViewSearchResults_ItemDataBound(object sender, ListViewItemEventArgs e) { ListViewItem myItem = (ListViewItem)e.Item; Image userImg = (Image)myItem.FindControl("UserVeImage"); Label unLabel = (Label)myItem.FindControl("UserName"); Label veId = (Label)myItem.FindControl("VeId"); Label ziptoLbl = (Label)myItem.FindControl("ZipTo"); Label distLbl = (Label)myItem.FindControl("DistanceLbl"); Label ratingLbl = (Label)myItem.FindControl("RatingLabel"); Label requestBtn = (Label)myItem.FindControl("SwapRequestBtn"); string zipFromtxt = ZipFromLabel.Text; string zipTotxt = ziptoLbl.Text; int zipFrom = Convert.ToInt32(zipFromtxt); int zipTo = Convert.ToInt32(zipTotxt); Repeater xtraImg = (Repeater)myItem.FindControl("ImgRepeater"); string userName = unLabel.Text; string vId = veId.Text; Guid veGuid = Guid.Parse(vId); UserClass uc = new UserClass(Profile.UserName); UserClass uco = new UserClass(userName); double distanceFrom = uc.GetDistance(zipFrom, zipTo); string strDistance = Convert.ToString(distanceFrom); distLbl.Text = strDistance; ratingLbl.Text = uco.GetUserTradeRating(); userImg.ImageUrl = uco.PublicImgMainUrl(veGuid); using (SwapEntities ent = new SwapEntities()) { var getXtra = from tbl in ent.VeImages where tbl.VehicleId == veGuid && tbl.IsMain == false select tbl; if (getXtra != null) { xtraImg.DataSource = getXtra; xtraImg.DataBind(); } } }
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { Label veId = (Label)e.Item.FindControl("VeId"); Image veImage = (Image)e.Item.FindControl("VeImg"); Guid veGuid = Guid.Parse(veId.Text); using (SwapEntities ent = new SwapEntities()) { var veImg = (from tbl in ent.VeImages where tbl.VehicleId == veGuid && tbl.IsMain == true select tbl.ImageUrl).SingleOrDefault(); if (veImg != null) { veImage.ImageUrl = veImg; } } }
// Methods. _________________________ // Method for getting main image path for specific vehicle. public string PublicImgMainUrl(Guid veId) { using (SwapEntities ent = new SwapEntities()) { var getImg = (from i in ent.VeImages where i.VehicleId == veId & i.IsMain == true select i.ImageUrl).SingleOrDefault(); if (getImg != null) { return(getImg); } else { return(""); } } }
protected void Page_Load(object sender, EventArgs e) { string getMyVeId = Request.QueryString.Get("toVeId"); string getOtherVeId = Request.QueryString.Get("fromVeId"); string requestFrom = Request.QueryString.Get("requestfrom"); string requestId = Request.QueryString.Get("id"); Guid myVeGuid = Guid.Parse(getMyVeId); Guid otherVeGuid = Guid.Parse(getOtherVeId); Guid requestGuid = Guid.Parse(requestId); UserClass uc = new UserClass(Profile.UserName); UserClass ouc = new UserClass(requestFrom); RequestGuidLabel.Text = requestId; string imgUrl = uc.PublicImgMainUrl(myVeGuid); using (SwapEntities ent = new SwapEntities()) { CarClass cc = new CarClass(Profile.UserName); var fromVe = (from tbl in ent.VeImages orderby tbl.IsMain descending where tbl.VehicleId == otherVeGuid select tbl); Repeater.DataSource = fromVe; Repeater.DataBind(); UserVehicle myVe = cc.GetVehicleInfo(myVeGuid); UserVehicle otherVe = cc.GetVehicleInfo(otherVeGuid); RequestEvent thisRequest = cc.GetSwapRequestInfo(requestGuid); OtherUser.Text = ouc.PublicFirstName; OtherUser2.Text = ouc.PublicFirstName; SwapFromDate.Text = thisRequest.DateFrom.ToShortDateString(); SwapToDate.Text = thisRequest.DateTo.ToShortDateString(); MyVeLabel.Text = myVe.VehicleYear + " " + myVe.VehicleMake + " " + myVe.VehicleModel; OtherVeLabel.Text = otherVe.VehicleYear + " " + otherVe.VehicleMake + " " + otherVe.VehicleModel; VeMiles.Text = otherVe.VehicleMiles.ToString(); CityState.Text = ouc.PublicCity + ", " + ouc.PublicState; Distance.Text = cc.GetDistance(uc.PublicZip, ouc.PublicZip).ToString(); } MyImg.ImageUrl = imgUrl; }
protected void VeEditListView_ItemDataBound(object sender, ListViewItemEventArgs e) { ListViewItem myItem = (ListViewItem)e.Item; Label imgId = (Label)myItem.FindControl("ImgId"); Guid imgGuid = Guid.Parse(imgId.Text); Image veImg = (Image)myItem.FindControl("VeImg"); using (SwapEntities ent = new SwapEntities()) { var getImg = (from tbl in ent.VeImages where tbl.Id == imgGuid select tbl).SingleOrDefault(); if (getImg != null) { veImg.ImageUrl = getImg.ImageUrl; } } }
// Method for editing car. // public void EditCarInfo(Guid veId, int veMiles, string veDesc) { using (SwapEntities myEnt = new SwapEntities()) { var getCar = (from tbl in myEnt.UserVehicles where tbl.Id == veId select tbl).SingleOrDefault(); if (veMiles != 0) { getCar.VehicleMiles = veMiles; } if (veDesc != "") { getCar.VehicleDescription = veDesc; } myEnt.SaveChanges(); } }
protected void ChooseVeListView_ItemDataBound(object sender, ListViewItemEventArgs e) { ListViewItem myItem = (ListViewItem)e.Item; Image userImg = (Image)myItem.FindControl("VeImgChoose"); Label idLbl = (Label)myItem.FindControl("IdLabel"); Guid id = Guid.Parse(idLbl.Text); using (SwapEntities ent = new SwapEntities()) { var getImg = (from tbl in ent.VeImages where tbl.Id == id select tbl).SingleOrDefault(); if (getImg != null) { userImg.ImageUrl = getImg.ImageUrl; } } }
protected void CarsGridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Label veId = (Label)e.Row.FindControl("VehicleId"); Image carImg = (Image)e.Row.FindControl("MainVeImg"); Image carModalImg = (Image)e.Row.FindControl("ModalMainImg"); ListView imgLv = (ListView)e.Row.FindControl("VeEditListView"); Guid veGuid = Guid.Parse(veId.Text); string imgUrl; // Now get images with this vehicle Id, and grab the one with 'IsMain' equals true. using (SwapEntities myEnt = new SwapEntities()) { var getVe = (from tbl in myEnt.VeImages where tbl.VehicleId == veGuid && tbl.IsMain == true select tbl).SingleOrDefault(); if (getVe != null) { imgUrl = getVe.ImageUrl; } else { imgUrl = ""; } // Bind gridview for other vehicle images. var getVes = from tbl in myEnt.VeImages where tbl.VehicleId == veGuid && tbl.IsMain == false select tbl; imgLv.DataSource = getVes; imgLv.DataBind(); } carImg.ImageUrl = imgUrl; carModalImg.ImageUrl = imgUrl; } }
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Label imgId = (Label)e.Row.FindControl("ImgId"); Guid imgGuid = Guid.Parse(imgId.Text); Image veImg = (Image)e.Row.FindControl("VeImg"); using (SwapEntities ent = new SwapEntities()) { var getImg = (from tbl in ent.VeImages where tbl.Id == imgGuid select tbl).SingleOrDefault(); if (getImg != null) { veImg.ImageUrl = getImg.ImageUrl; } } } }