public async Task ShouldAddTeacherContactAsync()
        {
            // given
            TeacherContact randomTeacherContact   = CreateRandomTeacherContact();
            TeacherContact inputTeacherContact    = randomTeacherContact;
            TeacherContact storageTeacherContact  = randomTeacherContact;
            TeacherContact expectedTeacherContact = storageTeacherContact;

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertTeacherContactAsync(inputTeacherContact))
            .ReturnsAsync(storageTeacherContact);

            // when
            TeacherContact actualTeacherContact =
                await this.teacherContactService.AddTeacherContactAsync(inputTeacherContact);

            // then
            actualTeacherContact.Should().BeEquivalentTo(expectedTeacherContact);

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertTeacherContactAsync(inputTeacherContact),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
        public async Task <IActionResult> DeletePost(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Teacher teacher = await _db.Teachers.FindAsync(id);

            TeacherContact teacherContact = await _db.TeacherContacts.FirstOrDefaultAsync(c => c.Id == teacher.TeacherContactId);

            SkillsTeacher skillsTeacher = await _db.SkillsTeachers.FirstOrDefaultAsync(c => c.Id == teacher.SkillsTeacherId);

            TeacherVM teacherVM = new TeacherVM()
            {
                Teacher        = teacher,
                TeacherContact = teacherContact,
                SkillsTeacher  = skillsTeacher
            };

            if (teacherVM == null)
            {
                return(NotFound());
            }
            PhotoFileDelete.IsDeletePhoto(_env.WebRootPath, "img/teacher", teacherVM.Teacher.Image);
            _db.TeacherContacts.Remove(teacherVM.TeacherContact);
            _db.SkillsTeachers.Remove(teacherVM.SkillsTeacher);
            _db.Teachers.Remove(teacherVM.Teacher);
            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Пример #3
0
        public ValueTask <TeacherContact> AddTeacherContactAsync(TeacherContact teacherContact) =>
        TryCatch(() =>
        {
            ValidateTeacherContactOnAdd(teacherContact);

            return(this.storageBroker.InsertTeacherContactAsync(teacherContact));
        });
        public async void ShouldThrowValidationExceptionOnAddWhenTeacherContactIsNullAndLogItAsync()
        {
            // given
            TeacherContact invalidTeacherContact = null;

            var nullTeacherContactException = new NullTeacherContactException();

            var expectedTeacherContactValidationException =
                new TeacherContactValidationException(nullTeacherContactException);

            // when
            ValueTask <TeacherContact> addTeacherContactTask =
                this.teacherContactService.AddTeacherContactAsync(invalidTeacherContact);

            // then
            await Assert.ThrowsAsync <TeacherContactValidationException>(() =>
                                                                         addTeacherContactTask.AsTask());

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(
                                                                    expectedTeacherContactValidationException))),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertTeacherContactAsync(It.IsAny <TeacherContact>()),
                                          Times.Never);

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnAddWhenContactIdIsInvalidAndLogItAsync()
        {
            // given
            TeacherContact randomTeacherContact = CreateRandomTeacherContact();
            TeacherContact inputTeacherContact  = randomTeacherContact;

            inputTeacherContact.ContactId = default;

            var invalidTeacherContactException = new InvalidTeacherContactException(
                parameterName: nameof(TeacherContact.ContactId),
                parameterValue: inputTeacherContact.ContactId);

            var expectedTeacherContactValidationException =
                new TeacherContactValidationException(invalidTeacherContactException);

            // when
            ValueTask <TeacherContact> addTeacherContactTask =
                this.teacherContactService.AddTeacherContactAsync(inputTeacherContact);

            // then
            await Assert.ThrowsAsync <TeacherContactValidationException>(() =>
                                                                         addTeacherContactTask.AsTask());

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(
                                                                    expectedTeacherContactValidationException))),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertTeacherContactAsync(It.IsAny <TeacherContact>()),
                                          Times.Never);

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
 private static void ValidateTeacherContactIsNull(TeacherContact teacherContact)
 {
     if (teacherContact is null)
     {
         throw new NullTeacherContactException();
     }
 }
        public async Task ShouldThrowDependencyExceptionOnAddWhenDbExceptionOccursAndLogItAsync()
        {
            // given
            TeacherContact randomTeacherContact    = CreateRandomTeacherContact();
            TeacherContact inputTeacherContact     = randomTeacherContact;
            var            databaseUpdateException = new DbUpdateException();

            var expectedTeacherContactDependencyException =
                new TeacherContactDependencyException(databaseUpdateException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertTeacherContactAsync(It.IsAny <TeacherContact>()))
            .ThrowsAsync(databaseUpdateException);

            // when
            ValueTask <TeacherContact> addTeacherContactTask =
                this.teacherContactService.AddTeacherContactAsync(inputTeacherContact);

            // then
            await Assert.ThrowsAsync <TeacherContactDependencyException>(() =>
                                                                         addTeacherContactTask.AsTask());

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(
                                                                    expectedTeacherContactDependencyException))),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertTeacherContactAsync(It.IsAny <TeacherContact>()),
                                          Times.Once);

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
        public async Task <IActionResult> Detail(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            Teacher teacher = await _db.Teachers.FindAsync(id);

            TeacherContact teacherContact = await _db.TeacherContacts.FirstOrDefaultAsync(c => c.Id == teacher.TeacherContactId);

            SkillsTeacher skillsTeacher = await _db.SkillsTeachers.FirstOrDefaultAsync(c => c.Id == teacher.SkillsTeacherId);

            TeacherVM teacherVM = new TeacherVM()
            {
                Teacher        = teacher,
                TeacherContact = teacherContact,
                SkillsTeacher  = skillsTeacher
            };

            if (teacherVM == null)
            {
                return(NotFound());
            }
            return(View(teacherVM));
        }
        public async Task ShouldRetrieveTeacherContactById()
        {
            // given
            DateTimeOffset inputDateTime          = GetRandomDateTime();
            TeacherContact randomTeacherContact   = CreateRandomTeacherContact(inputDateTime);
            TeacherContact storageTeacherContact  = randomTeacherContact;
            TeacherContact expectedTeacherContact = storageTeacherContact;

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectTeacherContactByIdAsync(randomTeacherContact.TeacherId, randomTeacherContact.ContactId))
            .ReturnsAsync(randomTeacherContact);

            // when
            TeacherContact actualTeacherContact = await
                                                  this.teacherContactService.RetrieveTeacherContactByIdAsync(
                randomTeacherContact.TeacherId, randomTeacherContact.ContactId);

            // then
            actualTeacherContact.Should().BeEquivalentTo(expectedTeacherContact);

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectTeacherContactByIdAsync(randomTeacherContact.TeacherId, randomTeacherContact.ContactId),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
        public async Task ShouldGetAllTeachersAsync()
        {
            // given
            IEnumerable <TeacherContact> randomTeacherContacts   = CreateRandomTeacherContacts();
            List <TeacherContact>        inputTeacherContacts    = randomTeacherContacts.ToList();
            List <TeacherContact>        expectedTeacherContacts = inputTeacherContacts;

            foreach (TeacherContact inputTeacherContact in inputTeacherContacts)
            {
                await this.otripleSApiBroker.PostTeacherContactAsync(inputTeacherContact);
            }

            // when
            IEnumerable <TeacherContact> actualTeacherContacts =
                await this.otripleSApiBroker.GetAllTeacherContactsAsync();

            // then
            foreach (TeacherContact expectedTeacherContact in expectedTeacherContacts)
            {
                TeacherContact actualTeacherContact =
                    actualTeacherContacts.FirstOrDefault(teacherContact =>
                                                         teacherContact.TeacherId == expectedTeacherContact.TeacherId &&
                                                         teacherContact.ContactId == expectedTeacherContact.ContactId);

                actualTeacherContact.Should().BeEquivalentTo(expectedTeacherContact,
                                                             options => options
                                                             .Excluding(teacherContact => teacherContact.Teacher)
                                                             .Excluding(teacherContact => teacherContact.Contact));

                await this.otripleSApiBroker.DeleteTeacherContactByIdAsync(
                    actualTeacherContact.TeacherId,
                    actualTeacherContact.ContactId);
            }
        }
        public async Task ShouldPostTeacherContactAsync()
        {
            // given
            TeacherContact randomTeacherContact   = CreateRandomTeacherContact();
            TeacherContact inputTeacherContact    = randomTeacherContact;
            TeacherContact expectedTeacherContact = inputTeacherContact;

            // when
            await this.otripleSApiBroker.PostTeacherContactAsync(inputTeacherContact);

            TeacherContact actualTeacherContact =
                await this.otripleSApiBroker.GetTeacherContactByIdAsync(
                    inputTeacherContact.TeacherId,
                    inputTeacherContact.ContactId);

            // then
            actualTeacherContact.Should().BeEquivalentTo(expectedTeacherContact,
                                                         options => options
                                                         .Excluding(teacherContact => teacherContact.Teacher)
                                                         .Excluding(teacherContact => teacherContact.Contact));

            await this.otripleSApiBroker.DeleteTeacherContactByIdAsync(
                actualTeacherContact.TeacherId,
                actualTeacherContact.ContactId);
        }
 private static void ValidateStorageTeacherContact(
     TeacherContact storageTeacherContact,
     Guid teacherId, Guid contactId)
 {
     if (storageTeacherContact == null)
     {
         throw new NotFoundTeacherContactException(teacherId, contactId);
     }
 }
        public async ValueTask <TeacherContact> DeleteTeacherContactAsync(
            TeacherContact TeacherContact)
        {
            EntityEntry <TeacherContact> TeacherContactEntityEntry =
                this.TeacherContacts.Remove(TeacherContact);

            await this.SaveChangesAsync();

            return(TeacherContactEntityEntry.Entity);
        }
        public async ValueTask <TeacherContact> InsertTeacherContactAsync(
            TeacherContact TeacherContact)
        {
            EntityEntry <TeacherContact> TeacherContactEntityEntry =
                await this.TeacherContacts.AddAsync(TeacherContact);

            await this.SaveChangesAsync();

            return(TeacherContactEntityEntry.Entity);
        }
Пример #15
0
        public ValueTask <TeacherContact> RetrieveTeacherContactByIdAsync(Guid teacherId, Guid contactId) =>
        TryCatch(async() =>
        {
            ValidateTeacherContactIdIsNull(teacherId, contactId);

            TeacherContact storageTeacherContact =
                await this.storageBroker.SelectTeacherContactByIdAsync(teacherId, contactId);

            ValidateStorageTeacherContact(storageTeacherContact, teacherId, contactId);

            return(storageTeacherContact);
        });
        public async ValueTask <TeacherContact> DeleteTeacherContactAsync(
            TeacherContact teacherContact)
        {
            using var broker = new StorageBroker(this.configuration);

            EntityEntry <TeacherContact> teacherContactEntityEntry =
                broker.TeacherContacts.Remove(entity: teacherContact);

            await broker.SaveChangesAsync();

            return(teacherContactEntityEntry.Entity);
        }
        private static void ValidateTeacherContactRequiredFields(TeacherContact teacherContact)
        {
            switch (teacherContact)
            {
            case { } when IsInvalid(teacherContact.TeacherId):
                throw new InvalidTeacherContactInputException(
                          parameterName: nameof(TeacherContact.TeacherId),
                          parameterValue: teacherContact.TeacherId);

            case { } when IsInvalid(teacherContact.ContactId):
                throw new InvalidTeacherContactInputException(
                          parameterName: nameof(TeacherContact.ContactId),
                          parameterValue: teacherContact.ContactId);
            }
        }
        public async Task <IActionResult> Create(TeacherVM createTeacherVM)
        {
            Teacher teacher = await _db.Teachers.FirstOrDefaultAsync();

            SkillsTeacher skillsTeacher = await _db.SkillsTeachers.FirstOrDefaultAsync();

            TeacherContact teacherContact = await _db.TeacherContacts.FirstOrDefaultAsync();

            if (createTeacherVM.Teacher.PhotoTeacher == null)
            {
                ModelState.AddModelError("", "Zehmet olmasa şəkil seçin !");
                return(View());
            }
            if (!createTeacherVM.Teacher.PhotoTeacher.IsImage())
            {
                ModelState.AddModelError("Photo", "Zehmet olmasa şəkil formati seçin !");
                return(View());
            }
            if (createTeacherVM.Teacher.PhotoTeacher.MaxLenght(500))
            {
                ModelState.AddModelError("Photo", "Secilen şəkil olcusu maksimum 500kb olmalidi seçin !");
                return(View());
            }

            TeacherVM teacherVM = new TeacherVM()
            {
                Teacher        = teacher,
                SkillsTeacher  = skillsTeacher,
                TeacherContact = teacherContact
            };
            SkillsTeacher  skills_Teacher = createTeacherVM.SkillsTeacher;
            TeacherContact contact        = createTeacherVM.TeacherContact;

            teacher = createTeacherVM.Teacher;
            teacher.SkillsTeacher         = skills_Teacher;
            teacher.TeacherContact        = contact;
            createTeacherVM.Teacher.Image = await createTeacherVM.Teacher.PhotoTeacher.SaveImage(_env.WebRootPath, "img/teacher");

            _db.Teachers.Add(teacher);
            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Пример #19
0
        public async Task ShouldThrowValidationExceptionOnRemoveWhenStorageTeacherContactIsInvalidAndLogItAsync()
        {
            // given
            DateTimeOffset randomDateTime            = GetRandomDateTime();
            TeacherContact randomTeacherContact      = CreateRandomTeacherContact(randomDateTime);
            Guid           inputContactId            = randomTeacherContact.ContactId;
            Guid           inputTeacherId            = randomTeacherContact.TeacherId;
            TeacherContact nullStorageTeacherContact = null;

            var notFoundTeacherContactException =
                new NotFoundTeacherContactException(inputTeacherId, inputContactId);

            var expectedSemesterCourseValidationException =
                new TeacherContactValidationException(notFoundTeacherContactException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectTeacherContactByIdAsync(inputTeacherId, inputContactId))
            .ReturnsAsync(nullStorageTeacherContact);

            // when
            ValueTask <TeacherContact> removeTeacherContactTask =
                this.teacherContactService.RemoveTeacherContactByIdAsync(inputTeacherId, inputContactId);

            // then
            await Assert.ThrowsAsync <TeacherContactValidationException>(() =>
                                                                         removeTeacherContactTask.AsTask());

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(
                                                                    expectedSemesterCourseValidationException))),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectTeacherContactByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.DeleteTeacherContactAsync(It.IsAny <TeacherContact>()),
                                          Times.Never);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
        public async Task ShouldRemoveTeacherContactAsync()
        {
            // given
            var            randomTeacherId      = Guid.NewGuid();
            var            randomContactId      = Guid.NewGuid();
            Guid           inputTeacherId       = randomTeacherId;
            Guid           inputContactId       = randomContactId;
            DateTimeOffset inputDateTime        = GetRandomDateTime();
            TeacherContact randomTeacherContact = CreateRandomTeacherContact(inputDateTime);

            randomTeacherContact.TeacherId = inputTeacherId;
            randomTeacherContact.ContactId = inputContactId;
            TeacherContact storageTeacherContact  = randomTeacherContact;
            TeacherContact expectedTeacherContact = storageTeacherContact;

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectTeacherContactByIdAsync(inputTeacherId, inputContactId))
            .ReturnsAsync(storageTeacherContact);

            this.storageBrokerMock.Setup(broker =>
                                         broker.DeleteTeacherContactAsync(storageTeacherContact))
            .ReturnsAsync(expectedTeacherContact);

            // when
            TeacherContact actualTeacherContact =
                await this.teacherContactService.RemoveTeacherContactByIdAsync(inputTeacherId, inputContactId);

            // then
            actualTeacherContact.Should().BeEquivalentTo(expectedTeacherContact);

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectTeacherContactByIdAsync(inputTeacherId, inputContactId),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.DeleteTeacherContactAsync(storageTeacherContact),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnAddWhenReferneceExceptionAndLogItAsync()
        {
            // given
            TeacherContact randomTeacherContact  = CreateRandomTeacherContact();
            TeacherContact invalidTeacherContact = randomTeacherContact;
            string         randomMessage         = GetRandomMessage();
            string         exceptionMessage      = randomMessage;
            var            foreignKeyConstraintConflictException = new ForeignKeyConstraintConflictException(exceptionMessage);

            var invalidTeacherContactReferenceException =
                new InvalidTeacherContactReferenceException(foreignKeyConstraintConflictException);

            var expectedTeacherContactValidationException =
                new TeacherContactValidationException(invalidTeacherContactReferenceException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertTeacherContactAsync(invalidTeacherContact))
            .ThrowsAsync(foreignKeyConstraintConflictException);

            // when
            ValueTask <TeacherContact> addTeacherContactTask =
                this.teacherContactService.AddTeacherContactAsync(invalidTeacherContact);

            // then
            await Assert.ThrowsAsync <TeacherContactValidationException>(() =>
                                                                         addTeacherContactTask.AsTask());

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(
                                                                    expectedTeacherContactValidationException))),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertTeacherContactAsync(invalidTeacherContact),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnAddWhenTeacherContactAlreadyExistsAndLogItAsync()
        {
            // given
            TeacherContact randomTeacherContact        = CreateRandomTeacherContact();
            TeacherContact alreadyExistsTeacherContact = randomTeacherContact;
            string         randomMessage         = GetRandomMessage();
            string         exceptionMessage      = randomMessage;
            var            duplicateKeyException = new DuplicateKeyException(exceptionMessage);

            var alreadyExistsTeacherContactException =
                new AlreadyExistsTeacherContactException(duplicateKeyException);

            var expectedTeacherContactValidationException =
                new TeacherContactValidationException(alreadyExistsTeacherContactException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertTeacherContactAsync(alreadyExistsTeacherContact))
            .ThrowsAsync(duplicateKeyException);

            // when
            ValueTask <TeacherContact> addTeacherContactTask =
                this.teacherContactService.AddTeacherContactAsync(alreadyExistsTeacherContact);

            // then
            await Assert.ThrowsAsync <TeacherContactValidationException>(() =>
                                                                         addTeacherContactTask.AsTask());

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(
                                                                    expectedTeacherContactValidationException))),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertTeacherContactAsync(alreadyExistsTeacherContact),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
        public async Task ShouldDeleteTeacherContactAsync()
        {
            // given
            TeacherContact randomTeacherContact = await PostRandomTeacherContactAsync();

            TeacherContact inputTeacherContact    = randomTeacherContact;
            TeacherContact expectedTeacherContact = inputTeacherContact;

            // when
            TeacherContact deletedTeacherContact =
                await DeleteTeacherContactAsync(inputTeacherContact);

            ValueTask <TeacherContact> getTeacherContactByIdTask =
                this.otripleSApiBroker.GetTeacherContactByIdAsync(
                    inputTeacherContact.TeacherId, inputTeacherContact.ContactId);

            // then
            deletedTeacherContact.Should().BeEquivalentTo(expectedTeacherContact);

            await Assert.ThrowsAsync <HttpResponseNotFoundException>(() =>
                                                                     getTeacherContactByIdTask.AsTask());
        }
        public async Task ShouldGetAllTeacherContactsAsync()
        {
            // given
            Teacher randomTeacher = await PostRandomTeacherAsync();

            var randomTeacherContacts = new List <TeacherContact>();

            for (int i = 0; i < GetRandomNumber(); i++)
            {
                randomTeacherContacts.Add(await CreateRandomTeacherContactAsync(randomTeacher));
            }

            List <TeacherContact> inputTeacherContacts    = randomTeacherContacts.ToList();
            List <TeacherContact> expectedTeacherContacts = inputTeacherContacts;

            // when
            IEnumerable <TeacherContact> actualTeacherContacts =
                await this.otripleSApiBroker.GetAllTeacherContactsAsync();

            // then
            foreach (TeacherContact expectedTeacherContact in expectedTeacherContacts)
            {
                TeacherContact actualTeacherContact =
                    actualTeacherContacts.Single(teacherContact =>
                                                 teacherContact.TeacherId == expectedTeacherContact.TeacherId &&
                                                 teacherContact.ContactId == expectedTeacherContact.ContactId);

                actualTeacherContact.Should().BeEquivalentTo(expectedTeacherContact);

                await this.otripleSApiBroker.DeleteTeacherContactByIdAsync(
                    actualTeacherContact.TeacherId, actualTeacherContact.ContactId);

                await this.otripleSApiBroker.DeleteContactByIdAsync(actualTeacherContact.ContactId);
            }

            await this.otripleSApiBroker.DeleteTeacherByIdAsync(randomTeacher.Id);
        }
        public async Task <IActionResult> Edit(int?id, TeacherVM teacherEdit)
        {
            Teacher teacher = await _db.Teachers.FindAsync(id);

            TeacherContact teacherContact = await _db.TeacherContacts.FirstOrDefaultAsync(c => c.Id == teacher.TeacherContactId);

            SkillsTeacher skillsTeacher = await _db.SkillsTeachers.FirstOrDefaultAsync(c => c.Id == teacher.SkillsTeacherId);

            TeacherVM teacherVM = new TeacherVM()
            {
                Teacher        = teacher,
                TeacherContact = teacherContact,
                SkillsTeacher  = skillsTeacher
            };

            if (teacherEdit == null)
            {
                return(NotFound());
            }
            if (id == null)
            {
                return(NotFound());
            }

            if (teacherEdit.Teacher.PhotoTeacher != null)
            {
                if (!teacherEdit.Teacher.PhotoTeacher.IsImage())
                {
                    ModelState.AddModelError("Photo", "Zehmet olmasa şəkil formati seçin !");
                    return(View());
                }
                if (teacherEdit.Teacher.PhotoTeacher.MaxLenght(500))
                {
                    ModelState.AddModelError("Photo", "Secilen şəkil olcusu maksimum 500kb olmalidi seçin !");
                    return(View());
                }
                PhotoFileDelete.IsDeletePhoto(_env.WebRootPath, "img/teacher", teacherVM.Teacher.Image);
                teacherVM.Teacher.Image = await teacherEdit.Teacher.PhotoTeacher.SaveImage(_env.WebRootPath, "img/teacher");
            }
            teacherVM.Teacher.FullName          = teacherEdit.Teacher.FullName;
            teacherVM.Teacher.About             = teacherEdit.Teacher.About;
            teacherVM.Teacher.DEGREE            = teacherEdit.Teacher.DEGREE;
            teacherVM.Teacher.EXPERIENCE        = teacherEdit.Teacher.EXPERIENCE;
            teacherVM.Teacher.HOBBIES           = teacherEdit.Teacher.HOBBIES;
            teacherVM.Teacher.FACULTY           = teacherEdit.Teacher.FACULTY;
            teacherVM.Teacher.Position          = teacherEdit.Teacher.Position;
            teacher.TeacherContact.Email        = teacherEdit.TeacherContact.Email;
            teacher.TeacherContact.Phone        = teacherEdit.TeacherContact.Phone;
            teacher.TeacherContact.Facebook     = teacherEdit.TeacherContact.Facebook;
            teacher.TeacherContact.SKYPE        = teacherEdit.TeacherContact.SKYPE;
            teacher.TeacherContact.Linkedin     = teacherEdit.TeacherContact.Linkedin;
            teacher.TeacherContact.Twitter      = teacherEdit.TeacherContact.Twitter;
            teacher.SkillsTeacher.Language      = teacherEdit.SkillsTeacher.Language;
            teacher.SkillsTeacher.Team_Leader   = teacherEdit.SkillsTeacher.Team_Leader;
            teacher.SkillsTeacher.Development   = teacherEdit.SkillsTeacher.Development;
            teacher.SkillsTeacher.Design        = teacherEdit.SkillsTeacher.Design;
            teacher.SkillsTeacher.Innovation    = teacherEdit.SkillsTeacher.Innovation;
            teacher.SkillsTeacher.Communication = teacherEdit.SkillsTeacher.Communication;
            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
 private static void ValidateTeacherContactOnAdd(TeacherContact teacherContact)
 {
     ValidateTeacherContactIsNull(teacherContact);
     ValidateTeacherContactRequiredFields(teacherContact);
 }
Пример #27
0
 public async ValueTask <TeacherContact> PostTeacherContactAsync(TeacherContact teacher) =>
 await this.apiFactoryClient.PostContentAsync(TeacherContactsRelativeUrl, teacher);