public ActionResult BookingsByUsers() { SussexDBEntities db = new SussexDBEntities(); List <UserEvent> events = db.UserEvents.ToList(); return(View(events)); }
private List <User> GetFriendRequestsByUser(int userId) { SussexDBEntities db = new SussexDBEntities(); // find friends var Friends = new List <User>(); var userFriendMatches = db.UserMatches .Where(w => (w.UserMatchRequestUserId == userId || w.UserMatchRecievedUserId == userId) && !w.UserMatchIsAccepted) .ToList(); List <int> userFriendMatchIds = new List <int>(); foreach (var item in userFriendMatches) { if (item.UserMatchRequestUserId == userId) { userFriendMatchIds.Add(item.UserMatchRecievedUserId); } else { userFriendMatchIds.Add(item.UserMatchRequestUserId); } } // remove duplicates var friendsRemoveDuplicateIds = userFriendMatchIds.Distinct().ToList(); // add if (friendsRemoveDuplicateIds != null) { foreach (int id in friendsRemoveDuplicateIds) { Friends.Add(db.Users.Where(w => w.UserId == id).FirstOrDefault()); } } return(Friends); }
public ActionResult Users() { SussexDBEntities db = new SussexDBEntities(); List <User> users = db.Users.ToList(); return(View(users)); }
public ActionResult AddPersonality(int Id, int?UserId, bool IsDelete = false) { if (UserId == null) { UserId = Int32.Parse(Session["UserId"].ToString()); } int roleId = Int32.Parse(Session["RoleId"].ToString()); using (SussexDBEntities db = new SussexDBEntities()) { if (IsDelete) { UserPersonality userPersonality = db.UserPersonalities.Where(w => w.UserId == UserId && w.PersonalityId == Id).FirstOrDefault(); db.UserPersonalities.Remove(userPersonality); db.SaveChanges(); } else { UserPersonality personality = new UserPersonality(); personality.UserId = (int)UserId; personality.PersonalityId = Id; db.UserPersonalities.Add(personality); db.SaveChanges(); } } if (roleId == RoleTypes.CUSTOMER_ID) { return(Redirect("/User/MyProfile")); } return(Redirect("/Admin/HobbiesAndPersonalities/" + UserId)); }
// new changes public static void StartMonthlySubscription(int UserId) { using (SussexDBEntities db = new SussexDBEntities()) { var user = db.Users.Where(w => w.UserId == UserId).FirstOrDefault(); // check whether the subscription is exist var subscription = db.BillingHistories.Where(w => w.UserId == UserId).FirstOrDefault(); if (subscription != null || user == null) { return; } BillingHistory billing = new BillingHistory(); billing.BillingHistoryDate = DateTime.Now.AddMonths(1); billing.BillingHistoryIsPayed = false; billing.BillingHistoryIsOverdue = false; billing.UserId = UserId; // Currency is in Euros if (user.UserType == UserTypes.LOCAL) { billing.BillingHistoryAmount = 12; } else { billing.BillingHistoryAmount = 5; } db.BillingHistories.Add(billing); db.SaveChanges(); } }
public ActionResult Edit(NewPaymentViewModel viewModel) { PaymentCard paymentCard = new PaymentCard(); using (SussexDBEntities db = new SussexDBEntities()) { if (viewModel.PaymentCardId != 0) { paymentCard = db.PaymentCards.Where(w => w.PaymentCardId == viewModel.PaymentCardId).FirstOrDefault(); } paymentCard.PaymentCardIsDefault = true; paymentCard.PaymentCardHolderName = viewModel.PaymentCardHolderName; paymentCard.PaymentCardNumber = viewModel.PaymentCardNumber; paymentCard.PaymentCardExpireDate = viewModel.PaymentCardExpireDate; paymentCard.PaymentCardSecurityCode = viewModel.PaymentCardSecurityCode; paymentCard.UserId = viewModel.UserId; if (viewModel.PaymentCardId == 0) { db.PaymentCards.Add(paymentCard); } db.SaveChanges(); } return(Redirect(viewModel.ReturnUrl)); }
public ActionResult Payment(int Id) { SussexDBEntities db = new SussexDBEntities(); BillingHistory billing = db.BillingHistories.Where(w => w.BillingHistoryId == Id).FirstOrDefault(); return(View(billing)); }
protected override bool AuthorizeCore(HttpContextBase httpContext) { bool authorize = false; try { int userId = int.Parse(Convert.ToString(httpContext.Session["UserId"])); if (userId != 0) { using (var context = new SussexDBEntities()) { var userRole = (from u in context.Users join r in context.Roles on u.RoleId equals r.RoleId where u.UserId == userId select new { r.RoleDescription }).FirstOrDefault(); foreach (var role in allowedroles) { if (role == userRole.RoleDescription) { return(true); } } } } } catch { }; return(authorize); }
public ActionResult ConfirmBooking(int UserId, int EventId, int By, bool IsPayed = true) { String message = "Booking Successfull"; using (SussexDBEntities db = new SussexDBEntities()) { UserEvent userEvent = db.UserEvents.Where(w => w.UserId == UserId && w.EventId == EventId).FirstOrDefault(); if (userEvent != null) { message = "User already has booking for this event"; } else { userEvent = new UserEvent(); userEvent.UserId = UserId; userEvent.EventId = EventId; userEvent.UserEventRegisteredDate = DateTime.Now; userEvent.IsAccepted = false; db.UserEvents.Add(userEvent); db.SaveChanges(); PaymentHelper.AddEventPaymentForUser(UserId, EventId, IsPayed); } } return(Redirect("/Event/BookSuccessfullMessage/" + By + "?Message=" + message + "&EventId=" + EventId + "&UserId=" + UserId)); }
public ActionResult HobbiesAndPersonalities(int Id) { SussexDBEntities db = new SussexDBEntities(); MyProfileViewModel viewModel = new MyProfileViewModel(); viewModel.User = db.Users.Where(w => w.UserId == Id).FirstOrDefault(); return(View(viewModel)); }
public static void UpdateMonthlySubscription(int UserId) { using (SussexDBEntities db = new SussexDBEntities()) { int monthlyFee = 0; var user = db.Users.Where(w => w.UserId == UserId).FirstOrDefault(); if (user == null) { return; } // Currency is in Euros if (user.UserType == UserTypes.LOCAL) { monthlyFee = 12; } else { monthlyFee = 5; } // check whether the subscription is exist var subscription = db.BillingHistories .Where(w => w.UserId == UserId && w.BillingHistoryAmount == monthlyFee) .OrderByDescending(o => o.BillingHistoryDate) .FirstOrDefault(); DateTime nextPaymentDate; if (subscription != null) { // if the next billing date is not met if (subscription.BillingHistoryDate > DateTime.Now) { return; } // if payment is not recieved for last month if (!subscription.BillingHistoryIsPayed && subscription.BillingHistoryDate.AddMonths(1) < DateTime.Now) { subscription.BillingHistoryIsOverdue = true; db.SaveChanges(); SendOverdueEmail(user, subscription); } nextPaymentDate = subscription.BillingHistoryDate.AddMonths(1); BillingHistory billing = new BillingHistory(); billing.BillingHistoryDate = nextPaymentDate; billing.BillingHistoryAmount = monthlyFee; billing.BillingHistoryIsPayed = false; billing.BillingHistoryIsOverdue = false; billing.UserId = UserId; db.BillingHistories.Add(billing); db.SaveChanges(); } } }
public ActionResult AddMeetingToEvent(MeetingSchedule MeetingSchedule) { using (SussexDBEntities db = new SussexDBEntities()) { db.MeetingSchedules.Add(MeetingSchedule); db.SaveChanges(); } return(Redirect("/Event/Edit/" + MeetingSchedule.EventId)); }
public ActionResult Index() { BookingViewModel viewModel = new BookingViewModel(); SussexDBEntities db = new SussexDBEntities(); viewModel.Events = db.Events.Where(w => w.EventIsDeleted != true).ToList(); viewModel.Users = db.Users.Where(w => w.UserIsActivated).ToList(); return(View(viewModel)); }
public ActionResult Calendar() { using (SussexDBEntities db = new SussexDBEntities()) { List <Event> items = db.Events.Where(w => !w.EventIsDeleted).ToList(); List <ScheduleItem> scheduleItems = new List <ScheduleItem>(); foreach (var item in items) { try { var meetings = db.MeetingSchedules.Where(w => w.EventId == item.EventId).ToList(); DateTime startDate = DateTime.Now.AddMonths(-1); DateTime endDate = DateTime.Now.AddMonths(6); if (meetings != null && meetings.Count > 0) { foreach (var meeting in meetings) { try { var schedule = CrontabSchedule.Parse(meeting.MeetingScheduleRepeatCronExpression); var occurrences = schedule.GetNextOccurrences(startDate, endDate); foreach (var occurence in occurrences) { ScheduleItem si1 = new ScheduleItem(); si1.Start = occurence; si1.End = occurence.AddHours(2); si1.Description = "Meeting - " + item.EventTitle; si1.Event = item.EventTitle; si1.Categories = item.EventCategories.Select(s => s.Category.CategoryDescription).ToList(); si1.EventId = item.EventId; scheduleItems.Add(si1); } } catch (Exception) { } } } ScheduleItem si = new ScheduleItem(); si.Start = item.EventDate; si.End = item.EventDate.AddHours(2); si.Description = item.EventTitle; si.Event = item.EventTitle; si.Categories = item.EventCategories.Select(s => s.Category.CategoryDescription).ToList(); si.EventId = item.EventId; scheduleItems.Add(si); } catch (Exception) { } } return(View(scheduleItems)); } }
public ActionResult Subscription() { int userId = Int32.Parse(Session["UserId"].ToString()); SussexDBEntities db = new SussexDBEntities(); UserPaymentsViewModel viewModel = new UserPaymentsViewModel(); viewModel.BillingHistories = db.BillingHistories.Where(w => w.UserId == userId).ToList(); return(View(viewModel)); }
//[CustomAuthorize("Admin", "Customer", "Receptionist", "Client Service Agent")] public ActionResult EditUser(int?Id) { UserEditViewModel viewModel = new UserEditViewModel(); int roleId = 0; if (Session["RoleId"] != null && Session["RoleId"].ToString() != "") { roleId = Int32.Parse(Session["RoleId"].ToString()); } if (roleId == RoleTypes.CUSTOMER_ID) { viewModel.UserType = UserTypes.ONLINE; if (Id == null) { return(Redirect("/")); } } else { viewModel.UserType = UserTypes.LOCAL; } if (roleId == 0) { viewModel.UserType = UserTypes.ONLINE; } if (Id == null) { return(View(viewModel)); } using (SussexDBEntities db = new SussexDBEntities()) { User user = db.Users.Where(w => w.UserId == Id).FirstOrDefault(); if (user == null) { return(View(viewModel)); } UserDetail userDetail = db.UserDetails.Where(w => w.UserId == Id).FirstOrDefault(); if (userDetail != null) { viewModel.Bio = userDetail.UserDetailBio; viewModel.Profession = userDetail.UserDetailProfession; viewModel.Age = userDetail.UserDetailAge; viewModel.Gender = userDetail.UserDetailGender; viewModel.UserDetailId = userDetail.UserDetailId; } viewModel.FirstName = user.UserFirstName; viewModel.LastName = user.UserLastName; viewModel.Email = user.UserEmail; viewModel.Password = user.UserPassword; viewModel.ContactNo = user.UserContactNo; viewModel.UserType = user.UserType; viewModel.UserId = user.UserId; } return(View(viewModel)); }
public ActionResult MyProfile() { int userId = Int32.Parse(Session["UserId"].ToString()); SussexDBEntities db = new SussexDBEntities(); MyProfileViewModel viewModel = new MyProfileViewModel(); viewModel.User = db.Users.Where(w => w.UserId == userId).FirstOrDefault(); return(View(viewModel)); }
public ActionResult RemoveCategoryFromEvent(int EventId, int CategoryId) { using (SussexDBEntities db = new SussexDBEntities()) { EventCategory eventCategory = db.EventCategories.Where(w => w.EventId == EventId && w.CategoryId == CategoryId).FirstOrDefault(); db.EventCategories.Remove(eventCategory); db.SaveChanges(); } return(Redirect("/Event/Edit/" + EventId)); }
public ActionResult Delete(int Id) { using (SussexDBEntities db = new SussexDBEntities()) { Event eventToDelete = db.Events.Where(w => w.EventId == Id).FirstOrDefault(); eventToDelete.EventIsDeleted = true; db.SaveChanges(); } return(Redirect("/Event/")); }
public ActionResult AddCategoryToEvent(int EventId, int CategoryId) { using (SussexDBEntities db = new SussexDBEntities()) { EventCategory eventCategory = new EventCategory(); eventCategory.EventId = EventId; eventCategory.CategoryId = CategoryId; db.EventCategories.Add(eventCategory); db.SaveChanges(); } return(Redirect("/Event/Edit/" + EventId)); }
public ActionResult AcceptBookingsByUsers(int Id) { SussexDBEntities db = new SussexDBEntities(); UserEvent e = db.UserEvents.Where(w => w.UserEventId == Id).FirstOrDefault(); if (e != null) { e.IsAccepted = true; } db.SaveChanges(); return(Redirect("/Event/BookingsByUsers")); }
public ActionResult AcceptRequest(int Id) { int userId = Int32.Parse(Session["UserId"].ToString()); using (SussexDBEntities db = new SussexDBEntities()) { UserMatch match = db.UserMatches .Where(w => w.UserMatchRequestUserId == Id && w.UserMatchRecievedUserId == userId).FirstOrDefault(); match.UserMatchIsAccepted = true; db.SaveChanges(); } return(Redirect("/User/MyFriends")); }
public ActionResult UserPayments() { SussexDBEntities db = new SussexDBEntities(); foreach (var user in db.Users.ToList()) { PaymentHelper.StartMonthlySubscription(user.UserId); PaymentHelper.UpdateMonthlySubscription(user.UserId); } UserPaymentsViewModel viewModel = new UserPaymentsViewModel(); viewModel.BillingHistories = db.BillingHistories.Where(w => !w.BillingHistoryIsPayed).ToList(); return(View(viewModel)); }
public ActionResult Bookings() { BookingViewModel viewModel = new BookingViewModel(); SussexDBEntities db = new SussexDBEntities(); viewModel.Events = db.Events.Where(w => w.EventIsDeleted != true).ToList(); foreach (var eve in viewModel.Events) { foreach (var user in eve.UserEvents) { User a = user.User; } } viewModel.Users = db.Users.Where(w => w.UserIsActivated).ToList(); return(View(viewModel)); }
public ActionResult Edit(int?Id) { EventEditViewModel viewModel = new EventEditViewModel(); using (SussexDBEntities db = new SussexDBEntities()) { viewModel.EventCategories = db.Categories.ToList(); if (Id != null) { viewModel.Event = db.Events.Where(w => w.EventId == Id).FirstOrDefault(); viewModel.MeetingSchedules = db.MeetingSchedules.Where(w => w.EventId == Id).ToList(); viewModel.SelectedEventCategories = db.EventCategories.Where(w => w.EventId == Id).Select(s => s.Category).ToList(); } } return(View(viewModel)); }
public ActionResult EditUser(int Id = 0) { EditUserViewModel viewModel = new EditUserViewModel(); if (Id != 0) { using (SussexDBEntities db = new SussexDBEntities()) { viewModel.User = db.Users.Where(w => w.UserId == Id).FirstOrDefault(); if (User != null) { viewModel.UserDetail = db.UserDetails.Where(w => w.UserId == viewModel.User.UserId).FirstOrDefault(); } } } return(View(viewModel)); }
public ActionResult DemandLetter(int Id) { SussexDBEntities db = new SussexDBEntities(); DemandLetterViewModel viewModel = new DemandLetterViewModel(); viewModel.User = db.Users.Where(w => w.UserId == Id).FirstOrDefault(); DateTime temp = DateTime.Now.AddMonths(-1); viewModel.BillingHistories = db.BillingHistories .Where(w => w.UserId == Id && w.BillingHistoryDate < temp) .ToList(); foreach (var bill in viewModel.BillingHistories) { PaymentHelper.SendOverdueEmail(viewModel.User, bill); } return(View(viewModel)); }
public ActionResult ConfirmPayment(int Id) { int roleId = Int32.Parse(Session["RoleId"].ToString()); SussexDBEntities db = new SussexDBEntities(); BillingHistory billing = db.BillingHistories.Where(w => w.BillingHistoryId == Id).FirstOrDefault(); if (billing != null) { billing.BillingHistoryIsPayed = true; db.SaveChanges(); } if (roleId == RoleTypes.CUSTOMER_ID) { return(Redirect("/User/Subscription")); } return(Redirect("/Payment/UserPayments")); }
public ActionResult AddFriend(int Id) { int userId = Int32.Parse(Session["UserId"].ToString()); using (SussexDBEntities db = new SussexDBEntities()) { UserMatch match = new UserMatch(); match.UserMatchRequestUserId = userId; match.UserMatchRecievedUserId = Id; match.UserMatchDate = DateTime.Now; match.UserMatchIsAccepted = false; match.UserMatchIsDeleted = false; db.UserMatches.Add(match); db.SaveChanges(); } return(Redirect("/User/MyFriends")); }
public ActionResult BookSuccessfullMessage(int Id, int UserId, int EventId, string Message) { if (Id == RoleTypes.CUSTOMER_ID) { ViewBag.ReturnUrl = "/Home/Events"; } else { ViewBag.ReturnUrl = "/Home/EventBookings"; } using (SussexDBEntities db = new SussexDBEntities()) { ViewBag.User = db.Users.Where(w => w.UserId == UserId).FirstOrDefault(); ViewBag.Event = db.Events.Where(w => w.EventId == EventId).FirstOrDefault(); } ViewBag.Message = Message; return(View()); }