Ejemplo n.º 1
0
        public ActionResult FriendsToGroup(GroupViewModel model)
        {
            List <Group> group = new List <Group>();

            group = db.Groups.ToList();
            List <Customer> AllCustomers       = new List <Customer>();
            List <Customer> CustomersInGroup   = new List <Customer>();
            List <int>      CustomerIdsInGroup = new List <int>();

            AllCustomers = db.Customers.ToList();
            List <Customer_Group> CustomerGroup = new List <Customer_Group>();

            CustomerGroup = db.Customer_Group.ToList();
            Customer_Group newCustomerGroup = new Customer_Group();

            model.currentGroup = group[group.Count - 1].GroupId;

            newCustomerGroup.GroupId    = model.currentGroup;
            newCustomerGroup.CustomerId = Int32.Parse(model.RequestedCustomerId);

            model.CustomersInGroup = CustomersInGroup;
            db.Customer_Group.Add(newCustomerGroup);

            db.SaveChanges();
            return(RedirectToAction("FriendsToGroup", "Groups"));
        }
Ejemplo n.º 2
0
        public ActionResult CreateGroup([Bind(Include = "Date,Time,GroupId,GroupName")] GroupViewModel model)
        {
            Group  group  = new Group();
            string userId = User.Identity.GetUserId();

            group.Date      = model.Date;
            group.Time      = model.Time;
            group.GroupName = model.GroupName;
            db.Groups.Add(group);
            db.SaveChanges();
            List <Group> groups = db.Groups.ToList();

            model.currentGroup = groups[groups.Count - 1].GroupId;
            Customer_Group customerGroup = new Customer_Group();

            customerGroup.GroupId = model.currentGroup;
            List <Customer> AllCustomers   = db.Customers.ToList();
            var             loggedInUserId = User.Identity.GetUserId();

            customerGroup.CustomerId = (from x in AllCustomers where x.UserId == loggedInUserId select x.CustomerId).FirstOrDefault();
            db.Customer_Group.Add(customerGroup);
            db.SaveChanges();
            return(RedirectToAction("FriendsToGroup", "Groups"));
        }