// 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 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); } }
// Method for creating user profile at signup. public void SignUpUser(string email, string firstName, string lastName) { if (_userName == "maestro") { Roles.AddUserToRole(_userName, "Managers"); } using (CreditMaestroEntities myEnt = new CreditMaestroEntities()) { var newEntry = new ProfileProperty(); newEntry.EMail = email; newEntry.UserId = _userId; newEntry.UserName = _userName; newEntry.FirstName = firstName; newEntry.LastName = lastName; newEntry.BookActivated = true; Roles.AddUserToRole(_userName, "BookValidatedUsers"); 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!"); sndEmail.SendHtmlFormattedEmail(email, "New message from creditscoremaestro.com customer care.", body); } }
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 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); } } }