// 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); } } }
// 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 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 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 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); } } }
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 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); } } } }
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(); }
// 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(); } } }
// 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(); } }
// 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(); } }
// 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"); } } } }
// Method for denying a request. public bool DeclineRequest(Guid id) { using (SwapEntities ent = new SwapEntities()) { var getRequest = (from tbl in ent.RequestEvents where tbl.Id == id select tbl).SingleOrDefault(); if (getRequest != null) { getRequest.DateAccepted = DateTime.Now; getRequest.Accept = false; ent.SaveChanges(); string notifyUser = getRequest.RequestFrom; UserClass uc = new UserClass(notifyUser); MessageClass mc = new MessageClass(); string newMsg = "Sorry, your request to swap with " + PublicFirstName + " " + "on " + getRequest.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"); //EmailUsersClass sndEmail = new EmailUsersClass("veswap"); //string body = sndEmail.PopulateBody(uc.PublicFirstName, "Sorry, your request to swap with " + PublicFirstName + " " + // "on " + getRequest.DateFrom.ToShortDateString() + " has been denied. Please " + // "feel free to contact us at [email protected] with any questions or concerns. Thanks again, and happy swapping!"); //sndEmail.SendHtmlFormattedEmail(PublicEmail, "New message from veSwap.com customer care.", body); return(true); } else { return(false); } } }
protected void MessengerListView_ItemDataBound(object sender, ListViewItemEventArgs e) { ListViewItem myItem = (ListViewItem)e.Item; Label isFrom = (Label)myItem.FindControl("MsgIsFrom"); Label lblMessage = (Label)myItem.FindControl("LblMsg"); Label isRead = (Label)myItem.FindControl("IsRead"); Panel messageDiv = (Panel)myItem.FindControl("MsgPanel"); if (isRead.Text == "False" && isFrom.Text != Profile.UserName) { Label msgId = (Label)myItem.FindControl("MsgId"); Guid msgGuid = Guid.Parse(msgId.Text); using (SwapEntities ent = new SwapEntities()) { var setRead = (from m in ent.MsgEvents where m.UId == msgGuid select m).SingleOrDefault(); setRead.IsRead = true; ent.SaveChanges(); } } if (isFrom.Text == Profile.UserName) { messageDiv.CssClass = "msgfrommebox"; if (lblMessage.Text == "You and I have a new scheduled swap! Please contact me when you can.") { messageDiv.Visible = false; } } else { messageDiv.CssClass = "msgfromotherbox"; } }
public string SendSwapRequest(string userFrom, string userTo, string fromVeId, string toVeId, string dtFrom, string dtTo) { using (SwapEntities ent = new SwapEntities()) { // Check if any swap request has already been accepted for either of these vehicles // within this date range. Also check if current requesting user has already sent a request // for this vehicle. Guid fromVeGuid = Guid.Parse(fromVeId); Guid toVeGuid = Guid.Parse(toVeId); DateTime dateFrom = DateTime.Parse(dtFrom); DateTime dateTo = DateTime.Parse(dtTo); var checkSwap = (from tbl in ent.RequestEvents where tbl.RequestFrom == userFrom & tbl.RequestTo == userTo & tbl.FromVeId == fromVeGuid & tbl.ToVeId == toVeGuid & tbl.Accept == null & tbl.DateFrom >= DateTime.Now || tbl.RequestFrom == userFrom & tbl.RequestTo == userTo & tbl.ToVeId == toVeGuid & tbl.FromVeId == fromVeGuid & tbl.Accept == null & tbl.DateFrom >= DateTime.Now || tbl.RequestFrom == userTo & tbl.RequestTo == userFrom & tbl.ToVeId == fromVeGuid & tbl.ToVeId == fromVeGuid & tbl.Accept == null & tbl.DateFrom >= DateTime.Now || tbl.RequestFrom == userTo & tbl.RequestTo == userFrom & tbl.ToVeId == fromVeGuid & tbl.FromVeId == toVeGuid & tbl.Accept == null & tbl.DateFrom >= DateTime.Now select tbl).SingleOrDefault(); if (checkSwap == null) { // This query checks if any scheduled swaps already exist within given date range // for either user's vehicle. // var checkList = from tbl in ent.ScheduledSwaps where tbl.VeMain == fromVeGuid & tbl.DateFrom >= dateFrom & tbl.DateFrom <= dateTo || tbl.VeMain == fromVeGuid & tbl.DateTo >= dateFrom & tbl.DateTo <= dateTo || tbl.VeMain == toVeGuid & tbl.DateFrom >= dateFrom & tbl.DateFrom <= dateTo || tbl.VeMain == toVeGuid & tbl.DateTo >= dateFrom & tbl.DateTo <= dateTo || tbl.VeOther == fromVeGuid & tbl.DateFrom >= dateFrom & tbl.DateFrom <= dateTo || tbl.VeOther == fromVeGuid & tbl.DateTo >= dateFrom & tbl.DateTo <= dateTo || tbl.VeOther == toVeGuid & tbl.DateFrom >= dateFrom & tbl.DateFrom <= dateTo || tbl.VeOther == toVeGuid & tbl.DateTo >= dateFrom & tbl.DateTo <= dateTo select tbl; if (checkList.FirstOrDefault() == null) { UserClass uc = new UserClass(userFrom); RequestEvent newRequest = new RequestEvent(); Guid newGuid = Guid.NewGuid(); newRequest.Id = newGuid; newRequest.RequestFrom = userFrom; newRequest.RequestTo = userTo; newRequest.FromVeId = fromVeGuid; newRequest.ToVeId = toVeGuid; newRequest.DateFrom = dateFrom; newRequest.DateTo = dateTo; newRequest.RequestDate = DateTime.Now; ent.AddToRequestEvents(newRequest); ent.SaveChanges(); string strMsg = "Just so you know, I sent you a new swap request!"; MessageClass mc = new MessageClass(); mc.SendMsg(userFrom, userTo, strMsg, "QM"); return("true"); } else { bool isRequester = false; // Determine which user has commited to a swap within this timeframe, and notify // client script accordingly. // foreach (var item in checkList) { if (item.VeMain == fromVeGuid || item.VeOther == fromVeGuid) { isRequester = true; } } if (isRequester == true) { return("falsescheduledswapyou"); } else { return("falsescheduledswapother"); } } } else { if (checkSwap.RequestFrom == userFrom) { return("falsesentrequest"); } else if (checkSwap.RequestFrom == userTo) { return("falseothersent"); } else { return("error"); } } } }
public void SendMsg(string userFrom, string userTo, string newMsg, string Type) { using (SwapEntities msgEnt = new SwapEntities()) { string msgFrom = userFrom; string msgTo = userTo; string msg = newMsg; string msgType = Type; Guid newId; if (msgTo != "") { if (msg != null && msg != "") { if (msgType == "QM") { var checkMsgnum = (from tbl in msgEnt.MsgEvents where tbl.UserFrom == msgFrom & tbl.UserTo == msgTo & tbl.IsRead == false select tbl).Count(); if (checkMsgnum == 0) { var checkLastMsgDate = (from tbl in msgEnt.MsgEvents orderby tbl.When descending where tbl.UserFrom == msgFrom & tbl.UserTo == msgTo & tbl.IsRead == true select tbl).FirstOrDefault(); if (checkLastMsgDate != null) { string today = DateTime.Now.ToShortDateString(); string lastMsgdate = checkLastMsgDate.When.ToShortDateString(); if (today != lastMsgdate) { UserClass uc = new UserClass(msgTo); UserClass ucm = new UserClass(msgFrom); string recipEmail = uc.PublicEmail; EmailUsersClass sndEmail = new EmailUsersClass(msgFrom); string body = sndEmail.PopulateBody(uc.PublicFirstName, "You have a new message from <b>" + ucm.PublicFirstName + "</b>, login at veSwap.com to" + " view and respond to this message!"); sndEmail.SendHtmlFormattedEmail(recipEmail, "New message from " + ucm.PublicFirstName + " at veSwap.com", body); } } } SentMessage msgSent = new SentMessage(); MsgEvent msgEvent = new MsgEvent(); newId = Guid.NewGuid(); msgEvent.UId = newId; msgEvent.When = DateTime.Now; msgEvent.UserFrom = msgFrom; msgEvent.UserTo = msgTo; msgEvent.MsgType = msgType; msgEvent.IsRead = false; msgSent.UId = newId; msgSent.IsRead = false; msgSent.Message = msg; msgEnt.AddToSentMessages(msgSent); msgEnt.AddToMsgEvents(msgEvent); msgEnt.SaveChanges(); } MsgEvent msgEventrec = new MsgEvent(); RecMessage msgRec = new RecMessage(); newId = Guid.NewGuid(); msgEventrec.UId = newId; msgEventrec.When = DateTime.Now; msgEventrec.UserFrom = msgFrom; msgEventrec.UserTo = msgTo; msgEventrec.MsgType = msgType; msgEventrec.IsRead = false; msgRec.UId = newId; msgRec.IsRead = false; msgRec.Message = msg; msgEnt.AddToRecMessages(msgRec); msgEnt.AddToMsgEvents(msgEventrec); msgEnt.SaveChanges(); if (msgType != "NM") { var updateContact = (from cnt in msgEnt.Contacts where cnt.UserTo == msgTo && cnt.UserFrom == msgFrom select cnt).SingleOrDefault(); if (updateContact == null) { Contact addContact = new Contact(); Guid contGuid = Guid.NewGuid(); addContact.Id = contGuid; addContact.UserTo = msgTo; addContact.UserFrom = msgFrom; addContact.LastReceived = DateTime.Now; msgEnt.AddToContacts(addContact); msgEnt.SaveChanges(); } else { updateContact.LastReceived = DateTime.Now; msgEnt.SaveChanges(); } var updateSntContact = (from snt in msgEnt.SentContacts where snt.UserTo == msgTo && snt.UserFrom == msgFrom select snt).SingleOrDefault(); if (updateSntContact == null) { SentContact addSntContact = new SentContact(); Guid sntcontGuid = Guid.NewGuid(); addSntContact.Id = sntcontGuid; addSntContact.UserTo = msgTo; addSntContact.UserFrom = msgFrom; addSntContact.LastSent = DateTime.Now; msgEnt.AddToSentContacts(addSntContact); msgEnt.SaveChanges(); } else { updateSntContact.LastSent = DateTime.Now; msgEnt.SaveChanges(); } } } } } }
// Method for accepting a request. //public bool AcceptRequest(Guid id) //{ // using (SwapEntities ent = new SwapEntities()) // { // var getRequest = (from tbl in ent.RequestEvents // where tbl.Id == id // select tbl).SingleOrDefault(); // if (getRequest != null) // { // getRequest.DateAccepted = DateTime.Now; // getRequest.Accept = true; // ent.SaveChanges(); // return true; // } // else // { // return false; // } // } //} // Method for submitting a swap rating. public bool SubmitNewRating(Guid swapIdGuid, string userTo, DateTime dtFrom, DateTime dtTo, byte rating, string comment) { using (SwapEntities ent = new SwapEntities()) { var acceptRequest = (from tbl in ent.RequestEvents where tbl.RequestTo == PublicUserName & tbl.DateFrom == dtFrom & tbl.DateTo == dtTo select tbl).SingleOrDefault(); if (acceptRequest != null && acceptRequest.Accept == null && acceptRequest.DateAccepted == null) { acceptRequest.DateAccepted = DateTime.Now; acceptRequest.Accept = true; } var check = (from tbl in ent.SwapRatings where tbl.UserName == userTo & tbl.DateFrom == dtFrom & tbl.DateTo == dtTo select tbl).SingleOrDefault(); if (check == null) { Guid newGuid = Guid.NewGuid(); var rateRequest = new SwapRating(); rateRequest.Id = newGuid; rateRequest.SwapId = swapIdGuid; rateRequest.Date = DateTime.Now; rateRequest.DateFrom = dtFrom; rateRequest.DateTo = dtTo; rateRequest.TradedWith = PublicUserName; rateRequest.UserName = userTo; rateRequest.Rating = rating; rateRequest.Comment = comment; ent.AddToSwapRatings(rateRequest); ent.SaveChanges(); var isNowRated = (from tbl in ent.ScheduledSwaps where tbl.Id == swapIdGuid select tbl).SingleOrDefault(); if (isNowRated != null) { if (isNowRated.UserMain == PublicUserName) { isNowRated.MainRated = true; } else { isNowRated.OtherRated = true; } ent.SaveChanges(); } string strMsg = PublicFirstName + " has given you a rating of " + rating + ". If this rating seems unfair " + "or disagreeable to you, please let us know and we will take a look. Thanks!"; MessageClass msg = new MessageClass(); msg.SendMsg(PublicUserName, userTo, strMsg, "QM"); return(true); } else { return(false); } } }
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"); } } } }
// Method for accepting a swap request. public bool AcceptSwapRequest(Guid requestId) { using (SwapEntities ent = new SwapEntities()) { try { var getSwap = (from tbl in ent.RequestEvents where tbl.Id == requestId select tbl).SingleOrDefault(); DateTime dateFrom = getSwap.DateFrom; DateTime dateTo = getSwap.DateTo; Guid veMain = getSwap.FromVeId; Guid veOther = getSwap.ToVeId; string userMain = getSwap.RequestFrom; string userOther = getSwap.RequestTo; string emailUser; string userwhoAccepts; getSwap.Accept = true; getSwap.DateAccepted = DateTime.Now; ent.SaveChanges(); Guid swapId = Guid.NewGuid(); ScheduledSwap newSwap = new ScheduledSwap(); newSwap.Id = swapId; newSwap.OtherRated = false; newSwap.MainRated = false; newSwap.Date = DateTime.Now; newSwap.DateFrom = dateFrom; newSwap.DateTo = dateTo; newSwap.UserMain = userMain; newSwap.UserOther = userOther; newSwap.VeMain = veMain; newSwap.VeOther = veOther; ent.AddToScheduledSwaps(newSwap); ent.SaveChanges(); string strMsg = "You and I have a new scheduled swap! Please contact me when you can."; MessageClass msg = new MessageClass(); msg.SendMsg(userMain, userOther, strMsg, "QM"); msg.SendMsg(userOther, userMain, strMsg, "QM"); CleanRequestsAndNotify(requestId, dateFrom, dateTo, userMain, userOther); if (userMain == PublicUserName) { emailUser = userOther; userwhoAccepts = userMain; } else { emailUser = userMain; userwhoAccepts = userOther; } UserClass iAccepted = new UserClass(userwhoAccepts); string strEmsg = "Your swap request has been accepted! You have a new scheduled swap on " + dateFrom.ToShortDateString() + " with " + iAccepted.PublicFirstName + ". Please log in at veswap.com " + "in order to review " + iAccepted.PublicFirstName + "'s information, and arrange swap details with this user. Remember, the smoother " + "the swap the better your rating, so please be punctual!"; EmailUsersClass emu = new EmailUsersClass(emailUser); emu.SendHtmlFormattedEmail(emailUser, "Swap request accepted!", strEmsg); return(true); } catch { return(false); } } }
// Method for notifying a user that another user, who has a pending request for a swap, has // instead accepted another swap within the corresponding time frame. This method will also // cancel the pending request that is in conflict. // public void CleanRequestsAndNotify(Guid id, DateTime dateFrom, DateTime dateTo, string userOne, string userTwo) { string userToNotify, msg; MessageClass mc = new MessageClass(); using (SwapEntities ent = new SwapEntities()) { var checkOne = from tbl in ent.RequestEvents where tbl.RequestFrom == userOne & tbl.DateFrom >= dateFrom & tbl.DateFrom <= tbl.DateTo & tbl.Id != id & tbl.Accept != false || tbl.RequestFrom == userOne & tbl.DateTo >= dateFrom & tbl.DateTo <= dateTo & tbl.Id != id & tbl.Accept != false || tbl.RequestTo == userOne & tbl.DateFrom >= dateFrom & tbl.DateFrom <= dateTo & tbl.Id != id & tbl.Accept != false || tbl.RequestTo == userOne & tbl.DateTo >= dateFrom & tbl.DateTo <= dateTo & tbl.Id != id & tbl.Accept != false select tbl; foreach (var item in checkOne) { if (item.RequestFrom == userOne) { msg = userOne + " sent you a request to swap vehicles from " + item.DateFrom.ToShortDateString() + " to " + item.DateTo.ToShortDateString() + ". However, they have since committed to another swap within this time frame, so the request has been cancelled. " + "Log in frequently to avoid missing any more potentially great swaps!"; userToNotify = item.RequestTo; mc.SendMsg("veSwap", userToNotify, msg, "QM"); ent.RequestEvents.DeleteObject(item); } if (item.RequestTo == userOne) { msg = item.RequestFrom + " sent you a request to swap vehicles from " + item.DateFrom.ToShortDateString() + " to " + item.DateTo.ToShortDateString() + ". However, they have since committed to another swap within this time frame, so the request has been cancelled. " + "Log in frequently to avoid missing any more potentially great swaps!"; userToNotify = item.RequestTo; mc.SendMsg("veSwap", userToNotify, msg, "QM"); ent.RequestEvents.DeleteObject(item); } } var checkTwo = from tbl in ent.RequestEvents where tbl.RequestFrom == userTwo & tbl.DateFrom >= dateFrom & tbl.DateFrom <= tbl.DateTo & tbl.Id != id & tbl.Accept != false || tbl.RequestFrom == userTwo & tbl.DateTo >= dateFrom & tbl.DateTo <= dateTo & tbl.Id != id & tbl.Accept != false || tbl.RequestTo == userTwo & tbl.DateFrom >= dateFrom & tbl.DateFrom <= dateTo & tbl.Id != id & tbl.Accept != false || tbl.RequestTo == userTwo & tbl.DateTo >= dateFrom & tbl.DateTo <= dateTo & tbl.Id != id & tbl.Accept != false select tbl; foreach (var item in checkOne) { if (item.RequestFrom == userTwo) { msg = userTwo + " sent you a request to swap vehicles from " + item.DateFrom.ToShortDateString() + " to " + item.DateTo.ToShortDateString() + ". However, they have since committed to another swap within this time frame, so the request has been cancelled. " + "Log in frequently to avoid missing any more potentially great swaps!"; userToNotify = item.RequestTo; mc.SendMsg("veSwap", userToNotify, msg, "QM"); ent.RequestEvents.DeleteObject(item); } if (item.RequestTo == userTwo) { msg = item.RequestFrom + " sent you a request to swap vehicles from " + item.DateFrom.ToShortDateString() + " to " + item.DateTo.ToShortDateString() + ". However, they have since committed to another swap within this time frame, so the request has been cancelled. " + "Log in frequently to avoid missing any more potentially great swaps!"; userToNotify = item.RequestTo; mc.SendMsg("veSwap", userToNotify, msg, "QM"); ent.RequestEvents.DeleteObject(item); } } ent.SaveChanges(); } }