예제 #1
0
        public ActionResult BookingsByUsers()
        {
            SussexDBEntities db     = new SussexDBEntities();
            List <UserEvent> events = db.UserEvents.ToList();

            return(View(events));
        }
예제 #2
0
        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);
        }
예제 #3
0
        public ActionResult Users()
        {
            SussexDBEntities db    = new SussexDBEntities();
            List <User>      users = db.Users.ToList();

            return(View(users));
        }
예제 #4
0
        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));
        }
예제 #5
0
        // 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();
            }
        }
예제 #6
0
        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));
        }
예제 #7
0
        public ActionResult Payment(int Id)
        {
            SussexDBEntities db      = new SussexDBEntities();
            BillingHistory   billing = db.BillingHistories.Where(w => w.BillingHistoryId == Id).FirstOrDefault();

            return(View(billing));
        }
예제 #8
0
        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);
        }
예제 #9
0
        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));
        }
예제 #10
0
        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));
        }
예제 #11
0
        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();
                }
            }
        }
예제 #12
0
 public ActionResult AddMeetingToEvent(MeetingSchedule MeetingSchedule)
 {
     using (SussexDBEntities db = new SussexDBEntities())
     {
         db.MeetingSchedules.Add(MeetingSchedule);
         db.SaveChanges();
     }
     return(Redirect("/Event/Edit/" + MeetingSchedule.EventId));
 }
예제 #13
0
        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));
        }
예제 #14
0
        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));
            }
        }
예제 #15
0
        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));
        }
예제 #16
0
        //[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));
        }
예제 #17
0
        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));
        }
예제 #18
0
 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));
 }
예제 #19
0
 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/"));
 }
예제 #20
0
 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));
 }
예제 #21
0
        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"));
        }
예제 #22
0
        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"));
        }
예제 #23
0
        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));
        }
예제 #24
0
        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));
        }
예제 #25
0
        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));
        }
예제 #26
0
        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));
        }
예제 #27
0
        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));
        }
예제 #28
0
        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"));
        }
예제 #29
0
        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"));
        }
예제 #30
0
 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());
 }