Esempio n. 1
0
        public override void Visit(StructDcel n)
        {
            SymReferencing sym = n.structType as SymReferencing;

            Code = Code.Remove(Code.Length - $"struct {sym.id} = ".Length);
            n.structType.accept(this);
            emit(" ");
            n.structId.accept(this);
            emit("{");
            if (n.declarings.Count > 0)
            {
                AST first = n.declarings[0];
                foreach (AST ast in n.declarings)
                {
                    if (first != ast)
                    {
                        emit(", ");
                    }
                    Assigning assigning = ast as Assigning;
                    assigning.child.accept(this);
                    //Code = Code.Remove(Code.Length - 2);
                }
            }
            emit("}");
        }
Esempio n. 2
0
        public async Task Assign(Assigning assigning)
        {
            context.Assignings.Add(assigning);
            var book = context.Books.Find(assigning.BookId);

            book.IsAvailable = false;

            await context.SaveChangesAsync();
        }
Esempio n. 3
0
        public async Task Unassign(Assigning assigning)
        {
            var book = context.Books.Find(assigning.BookId);

            book.IsAvailable = true;

            context.Entry(assigning).State = EntityState.Deleted;

            await context.SaveChangesAsync();
        }
Esempio n. 4
0
 public static void ShowFormPhanCong()
 {
     if (m_Assigning == null || m_Assigning.IsDisposed)
     {
         m_Assigning           = new Assigning();
         m_Assigning.MdiParent = MainForm.ActiveForm;
         m_Assigning.Show();
     }
     else
     {
         m_Assigning.Activate();
     }
 }
Esempio n. 5
0
 public override void Visit(Assigning n)
 {
     /*if (n.id is SymReferencing) {
      *  SymReferencing sym = n.id as SymReferencing;
      *  emit($"{sym.id} ");
      * } else if (n.id is DotReferencing) {
      *  n.id.accept(this);
      * } else emit($"{n.id} = ");*/
     n.id.accept(this);
     if (!(n.child is StructDef))
     {
         emit($" = ");
     }
     n.child.accept(this);
     emit(";\n");
 }
        // after submintig the assainging form this function change the user field,
        //creating ner record of assinging and chacnge the apartment capacity.
        public async Task <IActionResult> ChangeA(Assigning assigning)
        {
            string Aut = HttpContext.Session.GetString("Aut");

            if (!Aut.Equals("2"))
            {
                return(RedirectToAction("NotAut", "Home"));
            }
            var user = await _context.Users.SingleOrDefaultAsync(u => u.StundetId == assigning.StundetId.Value);

            var apartment = await _context.Apartments.SingleOrDefaultAsync(a => a.ApartmentNum == assigning.ApartmentNum.Value);

            if (ModelState.IsValid)
            {
                _context.Add(assigning);
                user.ApartmentNum = assigning.ApartmentNum.Value;
                if (assigning.Room == 0)
                {
                    user.Room = RoomNum.OneA;
                }
                else if (assigning.Room == 1)
                {
                    user.Room = RoomNum.TwoA;
                }
                else if (assigning.Room == 2)
                {
                    user.Room = RoomNum.ThreeA;
                }
                else
                {
                    user.Room = RoomNum.FourA;
                }
                _context.Update(user);
                apartment.capacity = apartment.capacity - 1;
                _context.Update(apartment);
                await _context.SaveChangesAsync();
            }


            return(RedirectToAction("NotAssigning", "Apartments"));
        }
Esempio n. 7
0
        public override void Visit(Assigning n)
        {
            SymReferencing current = n.id as SymReferencing;

            if (currentStructType != "")
            {
                if (StructDic[currentStructType].Exists(x => x.Item1 == current.id))
                {
                    Tuple <string, int> tuple = StructDic[currentStructType].Find(x => x.Item1 == current.id);
                    StructDic[currentStructType].Remove(tuple);
                    StructDic[currentStructType].Add(new Tuple <string, int>(tuple.Item1, 1));
                }
                else
                {
                    error($"{n.id} doesn't exist in {currentStructType}");
                }
            }
            else if (n.id is DotReferencing)
            {
                DotReferencing dot   = n.id as DotReferencing;
                SymReferencing dotid = dot.dotId as SymReferencing;
                SymReferencing id    = dot.id as SymReferencing;
                if (StructDic[id.id].Exists(x => x.Item1 == dotid.id))
                {
                    Tuple <string, int> tuple = StructDic[id.id].Find(x => x.Item1 == dotid.id);
                    StructDic[id.id].Remove(tuple);
                    StructDic[id.id].Add(new Tuple <string, int>(tuple.Item1, 1));
                }
                else
                {
                    error($"{dotid.id} doesn't exist in {id.id}");
                }
            }
            else if (!(n.id is ListReferencing))
            {
                InitiationTable[GetKey(current.id)] = 1;
            }
            n.child.accept(this);
        }
Esempio n. 8
0
 public override void Visit(Assigning n)
 {
     if (n.id is SymReferencing)
     {
         SymReferencing sym = n.id as SymReferencing;
         emit($"{sym.id} ");
     }
     else if (n.id is DotReferencing)
     {
         n.id.accept(this);
     }
     else
     {
         emit($"{n.id} ");
     }
     if (!(n.child is StructDef || n.child is StructDcel))
     {
         emit("= ");
     }
     n.child.accept(this);
     emit(";\n");
 }
Esempio n. 9
0
        public override void Visit(Assigning n)
        {
            n.child.accept(this);
            int            m       = -99;
            SymReferencing current = n.id as SymReferencing;

            if (currentStructType != "")
            {
                if (StructDic[currentStructType].Exists(x => x.Item1 == current.id))
                {
                    m = StructDic[currentStructType].Find(x => x.Item1 == current.id).Item2;
                }
                else
                {
                    Error($"{n.id} doesn't exist in {currentStructType}");
                }
            }
            else if (n.id is DotReferencing || n.id is ListReferencing)
            {
                n.id.accept(this);
                m = n.id.type;
            }
            else
            {
                m = AST.SymbolTable[GetKeyVal(current.id)];
            }
            int t = Generalize(n.child.type, m);

            n.child = Convert(n.child, m);
            n.type  = t;
            if (n.child is StructDcel)
            {
                StructDcel     assStructDcel = n.child as StructDcel;
                SymReferencing strucid       = assStructDcel.structId as SymReferencing;
                SymReferencing structype     = assStructDcel.structType as SymReferencing;
                StructDic.Add(strucid.id, StructDic[structype.id]);
            }
        }
Esempio n. 10
0
        public void DotReferencingUnitTest()
        {
            try {
                AST.SymbolTable = new Dictionary <Tuple <string, string>, int>();
                Dictionary <string, List <Tuple <string, int> > > structDic =
                    new Dictionary <string, List <Tuple <string, int> > >()
                {
                    { "led", new List <Tuple <string, int> >()
                      {
                          new Tuple <string, int>("pinPower", AST.INTTYPE),
                          new Tuple <string, int>("Power", AST.VOID)
                      } }
                };
                InitiationChecker initiationChecker = new InitiationChecker(structDic);

                var assign = new Assigning(new DotReferencing(new SymReferencing("led"), new SymReferencing("pinPower")), new IntConst("50"));
                assign.accept(initiationChecker);
                DotReferencing dotReferencing = new DotReferencing(new SymReferencing("led"), new SymReferencing("pinPower"));
                dotReferencing.accept(initiationChecker);

                Dictionary <Tuple <string, string>, int>          actualSym      = initiationChecker.getInitiationTable;
                Dictionary <string, List <Tuple <string, int> > > actualStruct   = initiationChecker.getStructDic;
                Dictionary <Tuple <string, string>, int>          expectedSym    = new Dictionary <Tuple <string, string>, int>();
                Dictionary <string, List <Tuple <string, int> > > expectedStruct =
                    new Dictionary <string, List <Tuple <string, int> > >()
                {
                    { "led", new List <Tuple <string, int> >()
                      {
                          new Tuple <string, int>("Power", 0),
                          new Tuple <string, int>("pinPower", 1)
                      } }
                };
                Assert.IsTrue(ObjectCompare(actualSym, expectedSym) && ObjectCompare(actualStruct, expectedStruct), "DotReferencing faild");
            } finally {
                AST.SymbolTable.Clear();
            }
        }
Esempio n. 11
0
 public override void Visit(Decl n)
 {
     if (n.assigning != null && !(n.declaring is VoidDcl))
     {
         n.declaring.accept(this);
         if (n.declaring is ListDcl)
         {
             emit(" = ");
             Assigning assigning = n.assigning as Assigning;
             assigning.child.accept(this);
             emit(";\n");
         }
         else
         {
             Code = Code.Remove((Code.Length - n.declaring.id.Length) - 1);
             n.assigning.accept(this);
         }
     }
     else if (!(n.declaring is VoidDcl))
     {
         n.declaring.accept(this);
         emit(";\n");
     }
 }
Esempio n. 12
0
 public override void Visit(Assigning n)
 {
     n.child.accept(this);
 }
Esempio n. 13
0
        public void AssigningUnitTest()
        {
            try {
                Assigning   assigning   = new Assigning(new SymReferencing("a"), new IntConst("4"));
                TypeChecker typeChecker = new TypeChecker();
                AST.SymbolTable =
                    new Dictionary <Tuple <string, string>, int>()
                {
                    { new Tuple <string, string>("1", "a"), AST.INTTYPE },
                    { new Tuple <string, string>("1", "text"), AST.STRING },
                    { new Tuple <string, string>("1", "testList"), 664 },
                    { new Tuple <string, string>("1", "pin"), AST.STRUCT },
                    { new Tuple <string, string>("11", "pinPower"), AST.INTTYPE },
                    { new Tuple <string, string>("111", "value"), AST.INTTYPE }
                };
                assigning.accept(typeChecker);

                int actual   = assigning.type;
                int expected = AST.INTTYPE;
                Assert.IsTrue(actual == expected, "Simple assign faild");

                assigning = new Assigning(new SymReferencing("testList"), new ListConst(new List <AST>()
                {
                    new ListConst(new List <AST>()
                    {
                        new SymReferencing("text")
                    }), new ListConst(new List <AST>()
                    {
                        new StringConst("\"list\"")
                    }), new ListConst(new List <AST>()
                    {
                        new StringConst("\"thing\"")
                    })
                }));
                assigning.accept(typeChecker);

                actual   = assigning.type;
                expected = 664;
                Assert.IsTrue(actual == expected, "List assign faild");

                var structDef = new StructDef(new List <AST>()
                {
                    new IntDcl("pinPower"), new FuncDecl(new VoidDcl("Power"), new List <SymDeclaring>()
                    {
                        new IntDcl("value")
                    }, new List <AST>()
                    {
                        new Assigning(new SymReferencing("pinPower"), new SymReferencing("value"))
                    }, null)
                });
                structDef.structType = new SymReferencing("pin");
                assigning            = new Assigning(new SymReferencing("pin"), structDef);
                assigning.accept(typeChecker);

                actual   = assigning.type;
                expected = AST.STRUCT;
                Assert.IsTrue(actual == expected, "StructDef assign faild");
            } finally {
                AST.SymbolTable.Clear();
            }
        }
Esempio n. 14
0
        public void AssigningUnitTest()
        {
            try {
                AST.SymbolTable =
                    new Dictionary <Tuple <string, string>, int>()
                {
                    { new Tuple <string, string>("1", "text"), AST.STRING },
                    { new Tuple <string, string>("1", "testList"), 664 },
                    { new Tuple <string, string>("1", "pin"), AST.STRUCT },
                    { new Tuple <string, string>("11", "pinPower"), AST.INTTYPE },
                    { new Tuple <string, string>("111", "value"), AST.INTTYPE }
                };
                Dictionary <string, List <Tuple <string, int> > > structDic =
                    new Dictionary <string, List <Tuple <string, int> > >()
                {
                    { "pin", new List <Tuple <string, int> >()
                      {
                          new Tuple <string, int>("pinPower", AST.INTTYPE),
                          new Tuple <string, int>("Power", AST.VOID)
                      } },
                    { "led", new List <Tuple <string, int> >()
                      {
                          new Tuple <string, int>("pinPower", AST.INTTYPE),
                          new Tuple <string, int>("Power", AST.VOID)
                      } }
                };
                InitiationChecker initiationChecker = new InitiationChecker(structDic);

                Assigning assigning = new Assigning(new SymReferencing("text"), new StringConst("4"));
                assigning.accept(initiationChecker);

                Dictionary <Tuple <string, string>, int>          actualSym    = initiationChecker.getInitiationTable;
                Dictionary <string, List <Tuple <string, int> > > actualStruct = initiationChecker.getStructDic;
                Dictionary <Tuple <string, string>, int>          expectedSym  =
                    new Dictionary <Tuple <string, string>, int>()
                {
                    { new Tuple <string, string>("1", "text"), 1 },
                    { new Tuple <string, string>("1", "testList"), 0 },
                    { new Tuple <string, string>("1", "pin"), 0 },
                    { new Tuple <string, string>("11", "pinPower"), 0 },
                    { new Tuple <string, string>("111", "value"), 0 }
                };
                Dictionary <string, List <Tuple <string, int> > > expectedStruct =
                    new Dictionary <string, List <Tuple <string, int> > >()
                {
                    { "pin", new List <Tuple <string, int> >()
                      {
                          new Tuple <string, int>("pinPower", 0),
                          new Tuple <string, int>("Power", 0)
                      } },
                    { "led", new List <Tuple <string, int> >()
                      {
                          new Tuple <string, int>("pinPower", 0),
                          new Tuple <string, int>("Power", 0)
                      } }
                };
                Assert.IsTrue(ObjectCompare(actualSym, expectedSym) && ObjectCompare(actualStruct, expectedStruct), "Simple InitiationCheck faild");

                assigning = new Assigning(new SymReferencing("testList"), new ListConst(new List <AST>()
                {
                    new ListConst(new List <AST>()
                    {
                        new SymReferencing("text")
                    }), new ListConst(new List <AST>()
                    {
                        new StringConst("\"list\"")
                    }), new ListConst(new List <AST>()
                    {
                        new StringConst("\"thing\"")
                    })
                }));
                assigning.accept(initiationChecker);

                actualSym    = initiationChecker.getInitiationTable;
                actualStruct = initiationChecker.getStructDic;
                expectedSym  =
                    new Dictionary <Tuple <string, string>, int>()
                {
                    { new Tuple <string, string>("1", "text"), 1 },
                    { new Tuple <string, string>("1", "testList"), 1 },
                    { new Tuple <string, string>("1", "pin"), 0 },
                    { new Tuple <string, string>("11", "pinPower"), 0 },
                    { new Tuple <string, string>("111", "value"), 0 }
                };
                expectedStruct =
                    new Dictionary <string, List <Tuple <string, int> > >()
                {
                    { "pin", new List <Tuple <string, int> >()
                      {
                          new Tuple <string, int>("pinPower", 0),
                          new Tuple <string, int>("Power", 0)
                      } },
                    { "led", new List <Tuple <string, int> >()
                      {
                          new Tuple <string, int>("pinPower", 0),
                          new Tuple <string, int>("Power", 0)
                      } }
                };
                Assert.IsTrue(ObjectCompare(actualSym, expectedSym) && ObjectCompare(actualStruct, expectedStruct), "List InitiationCheck faild");

                var structDef = new StructDef(new List <AST>()
                {
                    new IntDcl("pinPower"), new FuncDecl(new VoidDcl("Power"), new List <SymDeclaring>()
                    {
                        new IntDcl("value")
                    }, new List <AST>()
                    {
                        new Assigning(new SymReferencing("pinPower"), new SymReferencing("value"))
                    }, null)
                });
                structDef.structType = new SymReferencing("pin");
                assigning            = new Assigning(new SymReferencing("pin"), structDef);
                assigning.accept(initiationChecker);

                actualSym    = initiationChecker.getInitiationTable;
                actualStruct = initiationChecker.getStructDic;
                expectedSym  =
                    new Dictionary <Tuple <string, string>, int>()
                {
                    { new Tuple <string, string>("1", "text"), 1 },
                    { new Tuple <string, string>("1", "testList"), 1 },
                    { new Tuple <string, string>("1", "pin"), 1 },
                    { new Tuple <string, string>("11", "pinPower"), 1 },
                    { new Tuple <string, string>("111", "value"), 1 },
                    { new Tuple <string, string>("11", "Power"), 1 },
                    { new Tuple <string, string>("111", "pinPower"), 1 }
                };
                expectedStruct =
                    new Dictionary <string, List <Tuple <string, int> > >()
                {
                    { "led", new List <Tuple <string, int> >()
                      {
                          new Tuple <string, int>("pinPower", 0),
                          new Tuple <string, int>("Power", 0)
                      } }
                };
                Assert.IsTrue(ObjectCompare(actualSym, expectedSym) && ObjectCompare(actualStruct, expectedStruct), "StructDef InitiationCheck faild");

                var structDcel = new StructDcel(new SymReferencing("pin"), new List <AST>()
                {
                    new Assigning(new SymReferencing("pinPower"), new IntConst("50"))
                });
                structDcel.structId = new SymReferencing("led");
                assigning           = new Assigning(new SymReferencing("led"), structDcel);
                assigning.accept(initiationChecker);

                actualSym    = initiationChecker.getInitiationTable;
                actualStruct = initiationChecker.getStructDic;
                expectedSym  =
                    new Dictionary <Tuple <string, string>, int>()
                {
                    { new Tuple <string, string>("1", "text"), 1 },
                    { new Tuple <string, string>("1", "testList"), 1 },
                    { new Tuple <string, string>("1", "pin"), 1 },
                    { new Tuple <string, string>("11", "pinPower"), 1 },
                    { new Tuple <string, string>("111", "value"), 1 },
                    { new Tuple <string, string>("11", "Power"), 1 },
                    { new Tuple <string, string>("111", "pinPower"), 1 },
                    { new Tuple <string, string>("1", "led"), 1 }
                };
                expectedStruct =
                    new Dictionary <string, List <Tuple <string, int> > >()
                {
                    { "led", new List <Tuple <string, int> >()
                      {
                          new Tuple <string, int>("Power", 0),
                          new Tuple <string, int>("pinPower", 1)
                      } }
                };
                Assert.IsTrue(ObjectCompare(actualSym, expectedSym) && ObjectCompare(actualStruct, expectedStruct), "StructDcel InitiationCheck faild");
            } finally {
                AST.SymbolTable.Clear();
            }
        }
Esempio n. 15
0
        //capacity כמה מקום פנוי יש
        //The function goes through all the Approval kits and assigning the students to the apartments
        public async Task <IActionResult> Assigning()
        {
            //Couples ApprovalKit

            List <ApprovalKit> Couples = _context.ApprovalKits.Where(
                a =>
                a.RoomType == RoomType.דירה_זוגית).ToList();

            //Single ApprovalKit
            List <ApprovalKit> Single = _context.ApprovalKits.Where(
                r =>
                r.RoomType == RoomType.חדר_ליחיד &&
                r.HealthCondition == HealthCondition.ללא_מגבלה
                ).ToList();


            //Accessible ApprovalKit
            List <ApprovalKit> Accessible = _context.ApprovalKits.Where(
                r =>
                r.RoomType == RoomType.חדר_ליחיד && (
                    r.HealthCondition == HealthCondition.מגבלה_פיזית_אחרת ||
                    r.HealthCondition == HealthCondition.נכה_צהל ||
                    r.HealthCondition == HealthCondition.נכות)
                ).ToList();


            //Couples

            foreach (ApprovalKit a in Couples)
            {
                var asaing = await _context.Assigning.SingleOrDefaultAsync(u => u.StundetId.Value == a.StundetId.Value);

                if (asaing == null)
                {
                    //a main student || c main student parnter
                    if (a.PartnerId1 != null)
                    {
                        var c = await _context.ApprovalKits.SingleOrDefaultAsync(m => m.StundetId.Value == a.PartnerId1.Value); //find the partner of the main student

                        if (c != null)
                        {
                            if (c.PartnerId1.Value == a.StundetId.Value)
                            {
                                //get empty apartment
                                var apartment = await _context.Apartments.FirstOrDefaultAsync(m => m.Type.Equals("Couples") && m.capacity == 2);

                                if (apartment != null)
                                {
                                    apartment.capacity = 0;
                                    _context.Update(apartment);
                                    // the user obj of a
                                    var u1 = await _context.Users.SingleOrDefaultAsync(m => m.StundetId == a.StundetId);

                                    //the user obj of c
                                    var u2 = await _context.Users.SingleOrDefaultAsync(m => m.StundetId == c.StundetId);

                                    Assigning p1 = new Assigning
                                    {
                                        StundetId    = a.StundetId.Value,
                                        ApartmentNum = apartment.ApartmentNum,
                                        Room         = 1
                                    };
                                    u1.ApartmentNum = apartment.ApartmentNum;
                                    u1.Room         = RoomNum.OneA;

                                    _context.Update(u1);
                                    Assigning p2 = new Assigning
                                    {
                                        StundetId    = c.StundetId.Value,
                                        ApartmentNum = apartment.ApartmentNum,
                                        Room         = 2
                                    };
                                    u2.ApartmentNum = apartment.ApartmentNum;
                                    u2.Room         = RoomNum.TwoA;
                                    _context.Update(u2);

                                    _context.Add(p1);
                                    _context.Add(p2);
                                    await _context.SaveChangesAsync();
                                }
                            }
                            ;
                        }
                        ;
                        //if there is no partner
                    }
                }
                ;
            }
            ;
            //Accessible
            foreach (ApprovalKit a in Accessible)
            {
                var asaing = await _context.Assigning.SingleOrDefaultAsync(u => u.StundetId.Value == a.StundetId.Value);

                if (asaing == null)
                {
                    ApprovalKit[] roomies = new ApprovalKit[3];
                    roomies[0] = a;
                    int size = 1;
                    if (a.PartnerId1 != null)
                    {
                        var c = await _context.ApprovalKits.SingleOrDefaultAsync(m => m.StundetId.Value == a.PartnerId1.Value && m.Gender == a.Gender);

                        if (c != null)
                        {
                            if (c.PartnerId1.Value == a.StundetId.Value || c.PartnerId2.Value == a.StundetId.Value)
                            {
                                roomies[1] = c;
                                size++;
                            }
                            ;
                        }
                        ;
                    }
                    ;
                    if (a.PartnerId2 != null)
                    {
                        var c = await _context.ApprovalKits.SingleOrDefaultAsync(m => m.StundetId == a.PartnerId2.Value && m.Gender == a.Gender);

                        if (c != null)
                        {
                            if (c.PartnerId1.Value == a.StundetId.Value || c.PartnerId2.Value == a.StundetId.Value)
                            {
                                roomies[2] = c;
                                size++;
                            }
                            ;
                        }
                        ;
                    }
                    ;
                    //change proprties of apartment
                    var apartment = await _context.Apartments.FirstOrDefaultAsync(m => m.Type.Equals("Accessible") && m.capacity == 3);

                    if (apartment != null)
                    {
                        int c = apartment.capacity.Value;
                        apartment.LivingWithReligious = a.LivingWithReligious;
                        apartment.LivingWithSmoker    = a.LivingWithSmoker;
                        apartment.Gender   = a.Gender;
                        apartment.capacity = apartment.capacity - size;
                        _context.Update(apartment);
                        await _context.SaveChangesAsync();


                        // save proprties of roomeis
                        foreach (ApprovalKit u in roomies)
                        {
                            if (u != null)
                            {
                                var user = await _context.Users.SingleOrDefaultAsync(m => m.StundetId == u.StundetId.Value);

                                Assigning r = new Assigning
                                {
                                    StundetId    = u.StundetId.Value,
                                    ApartmentNum = apartment.ApartmentNum,
                                    Room         = c,
                                };
                                user.ApartmentNum = apartment.ApartmentNum;
                                if (r.Room == 1)
                                {
                                    user.Room = RoomNum.OneA;
                                }
                                else if (r.Room == 2)
                                {
                                    user.Room = RoomNum.TwoA;
                                }
                                else if (r.Room == 3)
                                {
                                    user.Room = RoomNum.ThreeA;
                                }
                                else
                                {
                                    user.Room = RoomNum.FourA;
                                }
                                _context.Update(user);

                                _context.Add(r);
                                await _context.SaveChangesAsync();

                                c--;
                            }
                            ;
                        }
                        ;
                    }
                }
                ;
            }
            ;
            //Single
            foreach (ApprovalKit a in Single)
            {
                var asaing = await _context.Assigning.FirstOrDefaultAsync(x => x.StundetId.Value == a.StundetId.Value);

                if (asaing == null)
                {
                    ApprovalKit[] roomies = new ApprovalKit[4];
                    roomies[0] = a;
                    int size = 1;
                    if (a.PartnerId1 != null)
                    {
                        var c = await _context.ApprovalKits.SingleOrDefaultAsync(m => m.StundetId.Value == a.PartnerId1.Value && m.Gender == a.Gender);

                        if (c != null)
                        {
                            if (c.PartnerId1.Value == a.StundetId.Value || c.PartnerId2.Value == a.StundetId.Value || c.PartnerId3.Value == a.StundetId.Value)
                            {
                                roomies[1] = c;
                                size++;
                            }
                            ;
                        }
                        ;
                    }
                    ;
                    if (a.PartnerId2 != null)
                    {
                        var c = await _context.ApprovalKits.SingleOrDefaultAsync(m => m.StundetId.Value == a.PartnerId2.Value && m.Gender == a.Gender);

                        if (c != null)
                        {
                            if (c.PartnerId1.Value == a.StundetId.Value || c.PartnerId2.Value == a.StundetId.Value || c.PartnerId3.Value == a.StundetId.Value)
                            {
                                roomies[2] = c;
                                size++;
                            }
                        }
                        ;
                    }
                    ;
                    if (a.PartnerId3 != null)
                    {
                        var c = await _context.ApprovalKits.SingleOrDefaultAsync(m => m.StundetId == a.PartnerId3.Value && m.Gender == a.Gender);

                        if (c != null)
                        {
                            if (c.PartnerId1.Value == a.StundetId.Value || c.PartnerId2.Value == a.StundetId.Value || c.PartnerId3.Value == a.StundetId.Value)
                            {
                                roomies[3] = c;
                                size++;
                            }
                        }
                    }
                    ;

                    Apartments apartment = await _context.Apartments.FirstOrDefaultAsync(m => m.capacity >= size &&
                                                                                         m.Type.Equals("Single") &&
                                                                                         m.LivingWithReligious == a.LivingWithReligious &&
                                                                                         m.LivingWithSmoker == a.LivingWithSmoker &&
                                                                                         m.ReligiousType == a.ReligiousType &&
                                                                                         m.Gender == a.Gender);

                    if (apartment == null)
                    {
                        apartment = _context.Apartments.FirstOrDefault(m => m.capacity >= size && m.Type.Equals("Single"));
                    }
                    ;

                    if (apartment != null)
                    {
                        int c = apartment.capacity.Value;
                        apartment.LivingWithReligious = a.LivingWithReligious;
                        apartment.LivingWithSmoker    = a.LivingWithSmoker;
                        apartment.Gender        = a.Gender;
                        apartment.capacity      = apartment.capacity - size;
                        apartment.ReligiousType = a.ReligiousType;
                        _context.Update(apartment);
                        await _context.SaveChangesAsync();

                        foreach (ApprovalKit u in roomies)
                        {
                            if (u != null)
                            {
                                var user = await _context.Users.SingleOrDefaultAsync(m => m.StundetId == u.StundetId);

                                Assigning r = new Assigning
                                {
                                    StundetId    = u.StundetId.Value,
                                    ApartmentNum = apartment.ApartmentNum,
                                    Room         = c,
                                };
                                user.ApartmentNum = apartment.ApartmentNum;
                                if (r.Room == 1)
                                {
                                    user.Room = RoomNum.OneA;
                                }
                                else if (r.Room == 2)
                                {
                                    user.Room = RoomNum.TwoA;
                                }
                                else if (r.Room == 3)
                                {
                                    user.Room = RoomNum.ThreeA;
                                }
                                else
                                {
                                    user.Room = RoomNum.FourA;
                                }
                                _context.Update(user);
                                _context.Add(r);

                                await _context.SaveChangesAsync();

                                c--;
                            }
                            ; //end if u!=null
                        }
                        ;     //end foreach roomies
                    }// apartment!=null
                }
                ; //assing==null
            }
            ;     //foreach approval kit

            //await _context.SaveChangesAsync();
            //ViewBag.NotAssigning = Globals.NotAssigning;

            return(RedirectToAction("NotAssigning", "Apartments"));
        }