Exemple #1
0
        public ActionResult Delete(int id)
        {
            PartifyDbContext context = new PartifyDbContext();
            Party            item    = context.Parties
                                       .Where(i => i.Id == id)
                                       .FirstOrDefault();

            context.Parties.Remove(item);
            context.SaveChanges();

            return(RedirectToAction("Index", "Parties"));
        }
        public ActionResult Delete(int partyId)
        {
            PartifyDbContext context = new PartifyDbContext();

            User u = (User)Session["loggedUser"];

            Invite inv = context.Invites
                         .Where(i => (i.Party.Id == partyId) && (i.Receiver.Id == u.Id))
                         .FirstOrDefault();

            context.Invites.Remove(inv);
            context.SaveChanges();

            return(RedirectToAction("Index", "Invites"));
        }
Exemple #3
0
        public ActionResult Create(CreateVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            User item = new User();

            item.Username  = model.Username;
            item.Password  = model.Password;
            item.FirstName = model.FirstName;
            item.LastName  = model.LastName;

            PartifyDbContext context = new PartifyDbContext();

            context.Users.Add(item);
            context.SaveChanges();

            return(RedirectToAction("Login", "Home"));
        }
Exemple #4
0
        public ActionResult Edit(EditVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            User item = new User();

            item.Id        = model.Id;
            item.Username  = model.Username;
            item.Password  = model.Password;
            item.FirstName = model.FirstName;
            item.LastName  = model.LastName;

            PartifyDbContext context = new PartifyDbContext();
            DbEntityEntry    entry   = context.Entry(item);

            entry.State = EntityState.Modified;
            context.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
Exemple #5
0
        public ActionResult Edit(EditVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            User loggedUser = (User)Session["loggedUser"];

            Party item = new Party();

            item.Id          = model.Id;
            item.Title       = model.Title;
            item.Description = model.Description;
            item.OwnerId     = loggedUser.Id;

            PartifyDbContext context = new PartifyDbContext();
            DbEntityEntry    entry   = context.Entry(item);

            entry.State = EntityState.Modified;
            context.SaveChanges();

            return(RedirectToAction("Index", "Parties"));
        }
        public ActionResult Create(CreateVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            PartifyDbContext context = new PartifyDbContext();
            Party            P       = context.Parties // get the party object from db
                                       .Where(p => p.Id == model.PartyId)
                                       .FirstOrDefault();
            User Sender   = (User)Session["loggedUser"]; // get the sender obj from session
            User Receiver = context.Users                // get the receiver object from db
                            .Where(u => u.Username == model.ReceiverUsername)
                            .FirstOrDefault();

            if (Receiver == null || P == null) // if receiver username or party id wrong/invalid
            {
                ModelState.AddModelError(string.Empty, "Wrong username or party");
                return(View(model));
            }

            if (Receiver.Id == Sender.Id) // if user tries to invite themselves
            {
                ModelState.AddModelError(string.Empty, "You cannot invite yourself");
                return(View(model));
            }

            if (P.OwnerId == Receiver.Id) // hosts cannot be invited to their parties
            {
                ModelState.AddModelError(string.Empty, "You cannot invite the host");
                return(View(model));
            }

            bool IsThisTheOwner = false;

            if (P.OwnerId == Sender.Id)
            {
                IsThisTheOwner = true;
            }
            else // if the sender of the invite is not the party owner
            {
                object isSenderInvited = context.Invites // check db if the sender is at least invited
                                         .Where(i => (i.Sender.Id == P.OwnerId) &&
                                                (i.Receiver.Id == Sender.Id))
                                         .FirstOrDefault();
                if (isSenderInvited == null) // if not
                {
                    ModelState.AddModelError(string.Empty, "You are unauthorised to invite people to this party");
                    return(View(model)); // return
                }
            }

            Invite inv = new Invite();

            inv.Sender = context.Users
                         .Where(u => u.Id == Sender.Id)
                         .FirstOrDefault();
            inv.Receiver = Receiver;
            inv.Party    = P;

            Invite check = context.Invites.SingleOrDefault(dbInvite => (dbInvite.Party.Id == inv.Party.Id) &&
                                                           (dbInvite.Receiver.Id == inv.Receiver.Id) &&
                                                           (dbInvite.Sender.Id == inv.Sender.Id)
                                                           );

            if (check == null)
            {
                context.Invites.Add(inv);
                context.SaveChanges();
            }

            if (IsThisTheOwner)
            {
                return(RedirectToAction("Index", "Parties"));
            }

            return(RedirectToAction("Index", "Invites"));
        }