Exemple #1
0
        public IActionResult EditWedding(NewWedding newWedding)
        {
            if (newWedding.UserId != Loginuser.GetUserID(HttpContext))
            {
                ViewBag.message = "You can not edit thie Wedding!";
                return(View("Warning"));
            }

            if (!ModelState.IsValid)
            {
                return(View("ShowEditWedding", newWedding));
            }
            else
            {
                DateTime now = DateTime.Today;
                if (DateTime.Compare(newWedding.DateofWeeding, now) < 0)
                {
                    ModelState.AddModelError("DateofWeeding", "The Wedding Date must be in the future!");
                    return(View("ShowEditWedding", newWedding));
                }
                else
                {
                    // newWedding.UserId = Loginuser.GetUserID(HttpContext);
                    Wedding editWedding = dbContext.Weddings.FirstOrDefault(wed => wed.WeddingId == newWedding.WeddingId);
                    editWedding.WedderOne     = newWedding.WedderOne;
                    editWedding.WedderTwo     = newWedding.WedderTwo;
                    editWedding.DateofWeeding = newWedding.DateofWeeding;
                    editWedding.Address       = newWedding.Address;
                    dbContext.SaveChanges();
                    return(Redirect("ViewWedding/" + editWedding.WeddingId));
                }
            }
        }
Exemple #2
0
        public IActionResult NewActivity(NewActivity addActivity)
        {
            int UserId = Loginuser.GetUserID(HttpContext);

            if (UserId == 0)
            {
                ViewBag.message = " Session time out. Need Register or login first!";
                return(View("Warning"));
            }

            if (!ModelState.IsValid)
            {
                return(View("NewActivity"));
            }

            DateTime startTime = addActivity.GetStartTime();
            DateTime now       = DateTime.Now;

            if (DateTime.Compare(startTime, now) < 0)
            {
                ModelState.AddModelError("StartDate", "The Activity  must be start in the future!");
                return(View("NewActivity"));
            }

            Activity NewActivity = GetNewActivity(addActivity);

            dbContext.Activitys.Add(NewActivity);
            dbContext.SaveChanges();

            return(Redirect("/dashboard"));
        }
        public IActionResult ShowUserAccount(int userId)
        {
            int logedUserID = Loginuser.GetUserID(HttpContext);

            if (logedUserID == userId)
            {
                User UserwithTransactions = dbContext.Users
                                            .Include(user => user.Transactions)
                                            .FirstOrDefault(user => user.UserId == userId);

                decimal currentBalane = dbContext.Users
                                        .Include(user => user.Transactions)
                                        .FirstOrDefault(user => user.UserId == userId)
                                        .Transactions.Sum(trans => trans.Amount);
                UserAccount newUserAcount = new UserAccount();
                newUserAcount.ShowUser     = UserwithTransactions;
                newUserAcount.ShownBalance = currentBalane.ToString("C2");
                return(View("UserAccount", newUserAcount));
            }
            else
            {
                ViewBag.message = "You Can not access this page!!!!!!";
                return(View("Warning"));
            }
        }
Exemple #4
0
 public IActionResult NewWeeding(NewWedding newweeding)
 {
     // Console.WriteLine("into newWedding controller");
     if (!ModelState.IsValid)
     {
         return(View("NewWedding"));
     }
     else
     {
         DateTime now = DateTime.Today;
         if (DateTime.Compare(newweeding.DateofWeeding, now) < 0)
         {
             ModelState.AddModelError("DateofWeeding", "The Wedding Date must be in the future!");
             return(View("NewWedding"));
         }
         else
         {
             newweeding.UserId = Loginuser.GetUserID(HttpContext);
             Wedding addWeeding = newweeding.GetNewWedding();
             dbContext.Weddings.Add(addWeeding);
             dbContext.SaveChanges();
             return(Redirect("ViewWedding/" + addWeeding.WeddingId));
         }
     }
 }
        public IActionResult DeleteComment(int commentId)
        {
            int UserId = Loginuser.GetUserID(HttpContext);

            if (UserId == 0)
            {
                ViewBag.message = " Need Register or login first!";
                return(View("Warning"));
            }
            Comment thisComment = dbContext.Comments.FirstOrDefault(com => com.CommentId == commentId);

            if (thisComment.UserId != UserId)
            {
                ViewBag.message = " You only could delete the commet that created by yourself!";
                return(View("Warning"));
            }
            if (DateTime.Now.Subtract(thisComment.CreatedAt).TotalMinutes >= 30)
            {
                ViewBag.message = " You only could delete the commet that  was made in the last 30 minutes.!";
                return(View("Warning"));
            }
            dbContext.Comments.Remove(thisComment);
            dbContext.SaveChanges();
            return(Redirect("/Dashboard"));
        }
Exemple #6
0
        public IActionResult ViewActivity(int activityId)
        {
            int UserId = Loginuser.GetUserID(HttpContext);

            if (UserId == 0)
            {
                ViewBag.message = " Session time out. Need Register or login first!";
                return(View("Warning"));
            }
            var viewActivity = dbContext.Activitys
                               .Include(act => act.Creator)
                               .Include(act => act.Attandences)
                               .ThenInclude(att => att.User)
                               .FirstOrDefault(act => act.ActivityId == activityId);

            if (viewActivity.UserId == UserId)
            {
                ViewBag.join = "owner";
            }
            if (dbContext.Attandences.Where(att => ((att.UserId == UserId) && (att.ActivityId == activityId))).ToList().Count() == 0)
            {
                ViewBag.join = "joinale";
            }
            else
            {
                ViewBag.join = "notjoinale";
            }
            ViewBag.UserId = UserId;
            return(View(viewActivity));
        }
Exemple #7
0
        public IActionResult Index()
        {
            int UserId = Loginuser.GetUserID(HttpContext);

            if (UserId == 0)
            {
                ViewBag.message = " Need Register or login first!";
                return(View("Warning"));
            }

            return(View("NewActivity"));
        }
Exemple #8
0
        public IActionResult Dashboard()
        {
            int UserId = Loginuser.GetUserID(HttpContext);

            if (UserId == 0)
            {
                ViewBag.message = " Need Register or login first!";
                return(View("Warning"));
            }
            DashboardModel Dashboard = SetupDashboard(UserId);

            return(View(Dashboard));
        }
Exemple #9
0
        public Activity GetNewActivity(NewActivity addActivity)
        {
            Activity NewActivity = new Activity();

            NewActivity.Title       = addActivity.Title;
            NewActivity.Description = addActivity.Description;
            NewActivity.Duration    = addActivity.Duration;
            NewActivity.DurationInc = addActivity.DurationInc;
            NewActivity.StartTime   = addActivity.GetStartTime();
            NewActivity.EndTime     = addActivity.GetEndTime(NewActivity.StartTime);
            NewActivity.UserId      = Loginuser.GetUserID(HttpContext);

            return(NewActivity);
        }
Exemple #10
0
        public IActionResult LogedIn()
        {
            int logedUserID = Loginuser.GetUserID(HttpContext);

            if (logedUserID != 0)
            {
                ViewBag.message = "Welcome";
            }
            else
            {
                ViewBag.message = "You did not login yet!!!! Can not access this page!";
            }
            return(View("LogedIn"));
        }
Exemple #11
0
        public IActionResult DeleteWeeding(int weddingId)
        {
            int     currentUser = Loginuser.GetUserID(HttpContext);
            Wedding thisWedding = dbContext.Weddings.FirstOrDefault(Wedding => Wedding.WeddingId == weddingId);

            Console.WriteLine("current user is :", currentUser);
            Console.WriteLine("wedding.user is :", thisWedding.UserId);
            if (thisWedding.UserId != currentUser)
            {
                ViewBag.message = "Can not delete a weeding  that not created by yourself!";
                return(View("Warning"));
            }
            dbContext.Weddings.Remove(thisWedding);
            dbContext.SaveChanges();
            return(Redirect("/dashboard"));
        }
Exemple #12
0
        public IActionResult ShowEditWedding(int weddingId)
        {
            int     currentUser = Loginuser.GetUserID(HttpContext);
            Wedding thisWedding = dbContext.Weddings.FirstOrDefault(wed => wed.WeddingId == weddingId);

            if (thisWedding.UserId != currentUser)
            {
                ViewBag.message = "You can not edit this Wedding!!";
                return(View("Warning"));
            }
            else
            {
                NewWedding newWedding = new NewWedding(thisWedding);
                return(View(newWedding));
            }
        }
        public IActionResult NewMessage(Wall wall)
        {
            int UserId = Loginuser.GetUserID(HttpContext);

            if (UserId == 0)
            {
                ViewBag.message = " Need Register or login first!";
                return(View("Warning"));
            }
            Message message = new Message();

            message.UserId         = wall.UserId;
            message.MessageContent = wall.NewMessage;
            dbContext.Messages.Add(message);
            dbContext.SaveChanges();
            return(Redirect("/Dashboard"));
        }
Exemple #14
0
        public IActionResult RSVP(int weddingId, int userId)
        {
            int currentUser = Loginuser.GetUserID(HttpContext);

            if (userId != currentUser)
            {
                ViewBag.message = "Can not  RSVP for other user!";
                return(View("Warning"));
            }
            Attendence newAtten = new Attendence();

            newAtten.UserId    = userId;
            newAtten.WeedingId = weddingId;
            dbContext.Attendences.Add(newAtten);
            dbContext.SaveChanges();

            return(Redirect("/dashboard"));
        }
Exemple #15
0
        public IActionResult UnRSVP(int weddingId, int userId)
        {
            int currentUser = Loginuser.GetUserID(HttpContext);

            if (userId != currentUser)
            {
                ViewBag.message = "Can not  Un-RSVP for other user!";
                return(View("Warning"));
            }
            Attendence delAtten = dbContext.Attendences
                                  .Where(att => ((att.WeedingId == weddingId) && (att.UserId == userId)))
                                  .FirstOrDefault();

            dbContext.Attendences.Remove(delAtten);
            dbContext.SaveChanges();

            return(Redirect("/dashboard"));
        }
        public IActionResult NewComment(Wall wall)
        {
            int UserId = Loginuser.GetUserID(HttpContext);

            if (UserId == 0)
            {
                ViewBag.message = " Need Register or login first!";
                return(View("Warning"));
            }
            Comment comment = new Comment();

            comment.UserId         = wall.UserId;
            comment.MessageId      = wall.MessageId;
            comment.CommentContent = wall.NewComment;
            dbContext.Comments.Add(comment);
            dbContext.SaveChanges();
            return(Redirect("/Dashboard"));
        }
        public IActionResult OprateAccount(UserAccount newUserAcount)
        {
            int  logedUserID          = Loginuser.GetUserID(HttpContext);
            User UserwithTransactions = dbContext.Users
                                        .Include(user => user.Transactions)
                                        .FirstOrDefault(user => user.UserId == logedUserID);
            decimal currentBalane = dbContext.Users
                                    .Include(user => user.Transactions)
                                    .FirstOrDefault(user => user.UserId == logedUserID)
                                    .Transactions.Sum(trans => trans.Amount);
            UserAccount thisUserAcount = new UserAccount();

            thisUserAcount.ShowUser     = UserwithTransactions;
            thisUserAcount.ShownBalance = currentBalane.ToString("C2");

            if (!ModelState.IsValid)
            {
                return(View("UserAccount", thisUserAcount));
            }
            else
            {
                if (newUserAcount.Amount == 0)
                {
                    ModelState.AddModelError("Amount", "Can not deposit/withdaw $0");
                    return(View("UserAccount", thisUserAcount));
                }
                else if ((0 - newUserAcount.Amount) > currentBalane)
                {
                    ModelState.AddModelError("Amount", "Can not withdaw more then your balance!");
                    return(View("UserAccount", thisUserAcount));
                }
                else
                {
                    Transaction newTrans = new Transaction();
                    newTrans.UserId = logedUserID;
                    newTrans.Amount = newUserAcount.Amount;
                    dbContext.Transactions.Add(newTrans);
                    dbContext.SaveChanges();
                    return(Redirect("/accout/" + logedUserID));
                }
            }
        }
Exemple #18
0
        public IActionResult DeleteActivity(int activityId)
        {
            int UserId = Loginuser.GetUserID(HttpContext);

            if (UserId == 0)
            {
                ViewBag.message = " Session time out. Need Register or login first!";
                return(View("Warning"));
            }
            Activity thisAct = dbContext.Activitys.FirstOrDefault(act => act.ActivityId == activityId);

            if (thisAct.UserId != UserId)
            {
                ViewBag.message = "Can not delete a weeding  that not created by yourself!";
                return(View("Warning"));
            }
            dbContext.Activitys.Remove(thisAct);
            dbContext.SaveChanges();
            return(Redirect("/dashboard"));
        }
Exemple #19
0
        public IActionResult UnRSVP(int activityId, int userId)
        {
            int UserId = Loginuser.GetUserID(HttpContext);

            if (UserId == 0)
            {
                ViewBag.message = " Session time out. Need Register or login first!";
                return(View("Warning"));
            }
            if (userId != UserId)
            {
                ViewBag.message = "Can not  Un-RSVP for other user!";
                return(View("Warning"));
            }
            Attandence delAtten = dbContext.Attandences
                                  .Where(att => ((att.ActivityId == activityId) && (att.UserId == userId)))
                                  .FirstOrDefault();

            dbContext.Attandences.Remove(delAtten);
            dbContext.SaveChanges();

            return(Redirect("/dashboard"));
        }
Exemple #20
0
        public IActionResult RSVP(int activityId, int userId)
        {
            int UserId = Loginuser.GetUserID(HttpContext);

            if (UserId == 0)
            {
                ViewBag.message = " Session time out. Need Register or login first!";
                return(View("Warning"));
            }
            if (userId != UserId)
            {
                ViewBag.message = "Can not  Join for other user!";
                return(View("Warning"));
            }
            Activity        thisAct   = dbContext.Activitys.FirstOrDefault(act => act.ActivityId == activityId);
            List <Activity> joinedAct = dbContext.Activitys
                                        .Include(act => act.Attandences)
                                        .Where(act => act.Attandences.Any(user => user.UserId == userId))
                                        .ToList();

            foreach (Activity activity in joinedAct)
            {
                // if (DateTime.Compare(startTime, now) < 0)
                if ((DateTime.Compare(thisAct.StartTime, activity.EndTime) <= 0) && (DateTime.Compare(thisAct.StartTime, activity.StartTime) < 0))
                {
                    ViewBag.message = "Time conflict!";
                    return(View("Warning"));
                }
                if ((DateTime.Compare(thisAct.EndTime, activity.EndTime) <= 0) && (DateTime.Compare(thisAct.StartTime, activity.StartTime) >= 0))
                {
                    ViewBag.message = "Time conflict!";
                    return(View("Warning"));
                }

                // if ((DateTime.Compare(thisAct.StartTime, activity.EndTime) < 0) && (DateTime.Compare(thisAct.StartTime, activity.StartTime) > 0))
                // {
                //     ViewBag.message = "Time conflict!";
                //     return View("Warning");
                // }
                // if ((DateTime.Compare(thisAct.StartTime, activity.EndTime) < 0) && (DateTime.Compare(thisAct.StartTime, activity.StartTime) > 0))
                // {
                //     ViewBag.message = "Time conflict!";
                //     return View("Warning");
                // }


                // Console.WriteLine("activity end", activity.EndTime.ToString());
                // Console.WriteLine("this star", thisAct.StartTime.ToString());
                // Console.WriteLine("(DateTime.Compare(thisAct.StartTime,activity.EndTime)<0)",(DateTime.Compare(thisAct.StartTime, activity.EndTime) < 0).ToString());
            }


            Attandence newAtten = new Attandence();

            newAtten.UserId     = userId;
            newAtten.ActivityId = activityId;
            dbContext.Attandences.Add(newAtten);
            dbContext.SaveChanges();

            return(Redirect("/dashboard"));
        }