Пример #1
0
        public ActionResult AddStylist(int specialtyId, int stylistId)
        {
            StylistSpecialty newPair = new StylistSpecialty(stylistId, specialtyId);

            newPair.Save();
            return(RedirectToAction("Detail", new { id = specialtyId }));
        }
        public ActionResult Edit(Specialty specialty, List <int> StylistIds)
        {
            db.Entry(specialty).State = EntityState.Modified;
            var specialtyMatchesInJoinTable = db.StylistsSpecialties.Where(entry => entry.SpecialtyId == specialty.SpecialtyId).ToList();

            foreach (var stylist in specialtyMatchesInJoinTable)
            {
                int stylistId = stylist.StylistId;
                var joinEntry = db.StylistsSpecialties
                                .Where(entry => entry.StylistId == stylistId)
                                .Where(entry => entry.SpecialtyId == specialty.SpecialtyId);
                foreach (var entry in joinEntry)
                {
                    db.StylistsSpecialties.Remove(entry);
                }
            }
            foreach (var id in StylistIds)
            {
                Stylist          stylist             = db.Stylists.FirstOrDefault(_ => _.StylistId == id);
                StylistSpecialty newStylistSpecialty = new StylistSpecialty(stylist.StylistId, specialty.SpecialtyId);
                db.StylistsSpecialties.Add(newStylistSpecialty);
            }
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #3
0
        public void Equals_ReturnsTrueIfIdAndNameAreTheSame_StylistSpecialty()
        {
            // Arrange, Act
            StylistSpecialty firstStylistSpecialty  = new StylistSpecialty(1, 1, 1);
            StylistSpecialty secondStylistSpecialty = new StylistSpecialty(1, 1, 1);

            // Assert
            Assert.AreEqual(firstStylistSpecialty, secondStylistSpecialty);
        }
Пример #4
0
 public ActionResult Create(Stylist stylist, List <int> SpecialtyIds)
 {
     db.Stylists.Add(stylist);
     foreach (int specialtyId in SpecialtyIds)
     {
         StylistSpecialty newStylistSpecialty = new StylistSpecialty(specialtyId, stylist.StylistId);
         db.StylistSpecialties.Add(newStylistSpecialty);
     }
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
        public ActionResult Delete(int id)
        {
            Specialty        specialty = db.Specialties.FirstOrDefault(item => item.SpecialtyId == id);
            StylistSpecialty joinEntry = db.StylistsSpecialties.FirstOrDefault(entry => entry.SpecialtyId == id);

            db.Specialties.Remove(specialty);
            if (joinEntry != null)
            {
                db.StylistsSpecialties.Remove(joinEntry);
            }
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #6
0
        public void SaveAndGetAll_SavesToDatabaseAndReturnAll_StylistSpecialty()
        {
            //Arrange
            StylistSpecialty testStylistSpecialty = new StylistSpecialty(1, 1);

            //Act
            testStylistSpecialty.Save();
            List <StylistSpecialty> result   = StylistSpecialty.GetAll();
            List <StylistSpecialty> testList = new List <StylistSpecialty> {
                testStylistSpecialty
            };

            //Assert
            CollectionAssert.AreEqual(testList, result);
        }
Пример #7
0
        public void Save_AssignsIdToObject_Id()
        {
            //Arrange
            StylistSpecialty testStylistSpecialty = new StylistSpecialty(1, 1);

            //Act
            testStylistSpecialty.Save();
            StylistSpecialty savedStylistSpecialty = StylistSpecialty.GetAll()[0];

            int result = savedStylistSpecialty.GetId();
            int testId = testStylistSpecialty.GetId();

            //Assert
            Assert.AreEqual(testId, result);
        }
Пример #8
0
        public ActionResult Edit(Stylist stylist, List <int> SpecialtyIds, List <int> ClientIds)
        {
            db.Entry(stylist).State = EntityState.Modified;
            var stylistMatchesInJoinTable = db.StylistSpecialties.Where(entry => entry.StylistId == stylist.StylistId).ToList();

            foreach (var specialty in stylistMatchesInJoinTable)
            {
                int specialtyId = specialty.SpecialtyId;
                var joinEntry   = db.StylistSpecialties
                                  .Where(entry => entry.SpecialtyId == specialtyId)
                                  .Where(entry => entry.StylistId == stylist.StylistId);
                foreach (var entry in joinEntry)
                {
                    db.StylistSpecialties.Remove(entry);
                }
            }

            foreach (var id in SpecialtyIds)
            {
                Specialty        specialty           = db.Specialties.FirstOrDefault(otherEntry => otherEntry.SpecialtyId == id);
                StylistSpecialty newStylistSpecialty = new StylistSpecialty(specialty.SpecialtyId, stylist.StylistId);
                db.StylistSpecialties.Add(newStylistSpecialty);
            }

            var stylistMatchesClients = db.StylistClients.Where(entry => entry.StylistId == stylist.StylistId).ToList();

            foreach (var client in stylistMatchesClients)
            {
                int clientId  = client.ClientId;
                var joinEntry = db.StylistClients
                                .Where(entry => entry.ClientId == clientId)
                                .Where(entry => entry.StylistId == stylist.StylistId);
                foreach (var entry in joinEntry)
                {
                    db.StylistClients.Remove(entry);
                }
            }

            foreach (var id in ClientIds)
            {
                Client        client           = db.Clients.FirstOrDefault(newEntry => newEntry.ClientId == id);
                StylistClient newStylistClient = new StylistClient(client.ClientId, stylist.StylistId);
                db.StylistClients.Add(newStylistClient);
            }

            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #9
0
        public void GetTest_ReturnDataField()
        {
            // Arrange
            int id          = 1;
            int stylistId   = 1;
            int specialtyId = 1;
            StylistSpecialty testStylistSpecialty = new StylistSpecialty(stylistId, specialtyId, id);

            // Act
            int resultId          = testStylistSpecialty.GetId();
            int resultStylistId   = testStylistSpecialty.GetStylistId();
            int resultSpecialtyId = testStylistSpecialty.GetSpecialtyId();

            // Assert
            Assert.AreEqual(id, resultId);
            Assert.AreEqual(stylistId, resultStylistId);
            Assert.AreEqual(specialtyId, resultSpecialtyId);
        }
Пример #10
0
        public void RemoveSpecialty_DeleteStylistFromStylist_SpecialtyTable_Stylist()
        {
            // Arrange
            Stylist testStylist = new Stylist("testName", 1);

            testStylist.Save();
            Specialty testSpecialty = new Specialty("testSpecialty");

            testSpecialty.Save();
            StylistSpecialty testStylistSpecialty = new StylistSpecialty(testStylist.GetId(), testSpecialty.GetId());

            testStylistSpecialty.Save();

            // Act
            testStylist.RemoveSpecialty(testSpecialty.GetId());

            // Assert
            Assert.AreEqual(0, testSpecialty.GetStylists().Count);
        }
Пример #11
0
        public void Delete_DeleteStylistFromDatabaseAndStylist_SpecialtyTable_Stylist()
        {
            // Arrange
            Stylist testStylist = new Stylist("testName", 1);

            testStylist.Save();
            Specialty testSpecialty = new Specialty("testSpecialty");

            testSpecialty.Save();
            StylistSpecialty testStylistSpecialty = new StylistSpecialty(testStylist.GetId(), testSpecialty.GetId());

            testStylistSpecialty.Save();

            // Act
            testStylist.Delete();

            // Assert
            Assert.AreEqual(0, Stylist.Find(testStylist.GetId()).GetId());
            Assert.AreEqual(0, testSpecialty.GetStylists().Count);
        }
Пример #12
0
        public void GetStylists_RetrievesAllStylistsWithSpecialtyId_StylistList()
        {
            // Arrange
            Specialty testSpecialty = new Specialty("testSpecialty");

            testSpecialty.Save();
            Stylist testStylist = new Stylist("testStylist");

            testStylist.Save();
            StylistSpecialty testStylistSpecialty = new StylistSpecialty(testStylist.GetId(), testSpecialty.GetId());

            testStylistSpecialty.Save();
            List <Stylist> testStylists = new List <Stylist> {
                testStylist
            };

            // Act
            List <Stylist> resultStylists = testSpecialty.GetStylists();

            // Assert
            CollectionAssert.AreEqual(testStylists, resultStylists);
        }
Пример #13
0
        public void GetSpecialties_RetrievesAllSpecialtiesWithStylistId_SpecialtyList()
        {
            // Arrange
            Stylist testStylist = new Stylist("testStylist");

            testStylist.Save();
            Specialty testSpecialty = new Specialty("testSpecialty");

            testSpecialty.Save();
            StylistSpecialty testStylistSpecialty = new StylistSpecialty(testStylist.GetId(), testSpecialty.GetId());

            testStylistSpecialty.Save();
            List <Specialty> testSpecialties = new List <Specialty> {
                testSpecialty
            };

            // Act
            List <Specialty> resultSpecialties = testStylist.GetSpecialties();

            // Assert
            CollectionAssert.AreEqual(testSpecialties, resultSpecialties);
        }
Пример #14
0
 public void Dispose()
 {
     StylistSpecialty.DeleteAll();
 }