示例#1
0
        private static SCOUserTeamAssignment [] InitializeSCOUserTeamAssignments(FlatmateContext context, UserTeam [] userTeams, SingleComplexOrder [] SCOs)
        {
            var SCOUTAs = new SCOUserTeamAssignment[]
            {
                new SCOUserTeamAssignment
                {
                    TeamId = userTeams.First(ut => ut.Team.Name == "Misie Pysie").TeamId,
                    UserId = userTeams.First(ut => ut.User.FirstName == "Adam").UserId,
                    SCOId  = SCOs.First(sco => sco.Subject == "Zakupy - spożywczak").Id
                },
                new SCOUserTeamAssignment
                {
                    TeamId = userTeams.First(ut => ut.Team.Name == "Misie Pysie").TeamId,
                    UserId = userTeams.First(ut => ut.User.FirstName == "Max").UserId,
                    SCOId  = SCOs.First(sco => sco.Subject == "Zakupy - spożywczak").Id
                },
                new SCOUserTeamAssignment
                {
                    TeamId = userTeams.First(ut => ut.Team.Name == "Misie Pysie").TeamId,
                    UserId = userTeams.First(ut => ut.User.FirstName == "Tom").UserId,
                    SCOId  = SCOs.First(sco => sco.Subject == "Zakupy - spożywczak").Id
                },
                new SCOUserTeamAssignment
                {
                    TeamId = userTeams.First(ut => ut.Team.Name == "Grzybowska 96").TeamId,
                    UserId = userTeams.First(ut => ut.User.FirstName == "Tom").UserId,
                    SCOId  = SCOs.First(sco => sco.Subject == "Opłata za prąd").Id
                },
                new SCOUserTeamAssignment
                {
                    TeamId = userTeams.First(ut => ut.Team.Name == "Grzybowska 96").TeamId,
                    UserId = userTeams.First(ut => ut.User.FirstName == "Alice").UserId,
                    SCOId  = SCOs.First(sco => sco.Subject == "Opłata za prąd").Id
                },
                new SCOUserTeamAssignment
                {
                    TeamId = userTeams.First(ut => ut.Team.Name == "Grzybowska 96").TeamId,
                    UserId = userTeams.First(ut => ut.User.FirstName == "Robert").UserId,
                    SCOId  = SCOs.First(sco => sco.Subject == "Opłata za prąd").Id
                },
                new SCOUserTeamAssignment
                {
                    TeamId = userTeams.First(ut => ut.Team.Name == "Atomówki").TeamId,
                    UserId = userTeams.First(ut => ut.User.FirstName == "Adam").UserId,
                    SCOId  = SCOs.First(sco => sco.Subject == "Wyrównanie rachunku").Id
                },
                new SCOUserTeamAssignment
                {
                    TeamId = userTeams.First(ut => ut.Team.Name == "Atomówki").TeamId,
                    UserId = userTeams.First(ut => ut.User.FirstName == "Robert").UserId,
                    SCOId  = SCOs.First(sco => sco.Subject == "Wyrównanie rachunku").Id
                },
                new SCOUserTeamAssignment
                {
                    TeamId = userTeams.First(ut => ut.Team.Name == "Atomówki").TeamId,
                    UserId = userTeams.First(ut => ut.User.FirstName == "Tom").UserId,
                    SCOId  = SCOs.First(sco => sco.Subject == "Wyrównanie rachunku").Id
                }
            };

            foreach (SCOUserTeamAssignment scouta in SCOUTAs)
            {
                context.OrdersAssignments.Add(scouta);
            }
            context.SaveChanges();

            return(SCOUTAs);
        }
示例#2
0
        public IActionResult NewShoppingList([Bind("Subject, ExpenseCategory, GroupId, SingleElementTitles, SingleElementAmounts, SingleElementUnits, ParticipantIds")] ShoppingCreateViewModel scvm)
        {
            //TODO: change to current user Id
            int currentUserId = 1;

            if (ModelState.IsValid)
            {
                //Dividing data between new event and user assignments.
                var sco = new SingleComplexOrder
                {
                    Subject         = scvm.Subject,
                    ExpenseCategory = scvm.ExpenseCategory,
                    CreationDate    = DateTime.Now
                };

                _context.ComplexOrders.Add(sco);
                _context.SaveChanges();

                var soeToAppend = new List <SingleOrderElement>();

                //Creating per user invitations
                for (int i = 0; i < scvm.SingleElementTitles.Length; i++)
                {
                    soeToAppend.Add(new SingleOrderElement
                    {
                        Title  = scvm.SingleElementTitles[i],
                        Amount = scvm.SingleElementAmounts[i],
                        Unit   = scvm.SingleElementUnits[i],
                        SCOId  = sco.Id
                    });
                }

                _context.OrderElements.AddRange(soeToAppend);
                _context.SaveChanges();

                var scoutas = new List <SCOUserTeamAssignment>
                {
                    new SCOUserTeamAssignment
                    {
                        SCOId  = sco.Id,
                        UserId = currentUserId,
                        TeamId = scvm.GroupId
                    }
                };

                for (int i = 0; i < scvm.ParticipantIds.Length; i++)
                {
                    var scouta = new SCOUserTeamAssignment
                    {
                        SCOId  = sco.Id,
                        UserId = scvm.ParticipantIds[i],
                        TeamId = scvm.GroupId
                    };
                    scoutas.Add(scouta);
                }

                _context.OrdersAssignments.AddRange(scoutas);
                _context.SaveChanges();

                //TODO: change for the currentUserId
                return(RedirectToAction("Index", "BudgetManager", null));
            }
            return(PartialView("_createNewShoppingListPartial", scvm));
        }