Ejemplo n.º 1
0
        public void A_ChangedTitle_modifies_Existing_country_in_the_database()
        {
            var bootStrapper = new BootStrapper();
            bootStrapper.StartServices();
            var serviceEvents = bootStrapper.GetService<IServiceEvents>();
            //1.- Create message
            var aggr = GenerateRandomAggregate();

            //2.- Create the tuple in the database
            var repository = new TitleRepository(_configuration.TestServer);
            repository.Insert(aggr);

            //3.- Change the aggregate
            aggr.NameKeyId = StringExtension.RandomString(10);
            aggr.SapCode = StringExtension.RandomString(2);
            aggr.Deleted = new Random().Next();

            //4.- Emit message
            var message = GenerateMessage(aggr);
            message.MessageType = typeof(ChangedTitle).Name;
            serviceEvents.AddIncommingEvent(new IncommingEvent { @event = message });


            //5.- Load the saved country
            var title = repository.Get(aggr.Id);
            //6.- Check equality
            Assert.True(ObjectExtension.AreEqual(aggr, title));
        }
        public ActionResult PersonnelAdd()
        {
            TitleRepository title = new TitleRepository();

            ViewBag.TitleList = title.Listing();
            return(View());
        }
Ejemplo n.º 3
0
        public List <Title> List()
        {
            TitleRepository trepository  = new TitleRepository();
            List <Title>    listcategory = trepository.List();

            return(listcategory);
        }
Ejemplo n.º 4
0
        //// GET api/authors
        //public IEnumerable<Author> Get()
        //{
        //    var repo = new AuthorRepository();

        //    return repo.GetAuthors();
        //}

        // GET api/authors
        public Task <FullResponse> Get()
        {
            var authorRepo = new AuthorRepository();
            var titleRepo  = new TitleRepository();

            var tcs = new TaskCompletionSource <FullResponse>();

            var response = new FullResponse();

            int outstandingOperations = 2;

            Task.Factory.FromAsync(authorRepo.BeginGetAuthors(null, null), iar =>
            {
                response.Authors = authorRepo.EndGetAuthors(iar);
                int currentCount = Interlocked.Decrement(ref outstandingOperations);
                if (currentCount == 0)
                {
                    tcs.SetResult(response);
                }
            });

            Task.Factory.FromAsync(titleRepo.BeginGetTitles(null, null), iar =>
            {
                response.Titles  = titleRepo.EndGetTitles(iar);
                int currentCount = Interlocked.Decrement(ref outstandingOperations);
                if (currentCount == 0)
                {
                    tcs.SetResult(response);
                }
            });

            return(tcs.Task);
        }
Ejemplo n.º 5
0
 public ActionResult EditTitles(int id, AdminControllerTitleVM titleModel)
 {
     TryUpdateModel(titleModel);
     if (ModelState.IsValid)
     {
         Title           title           = null;
         TitleRepository titleRepository = new TitleRepository();
         if (id > 0)
         {
             title      = titleRepository.GetById(id);
             title.Name = titleModel.Title;
             titleRepository.Save(title);
             return(RedirectToAction("ManageTitles"));
         }
         else
         {
             title = titleRepository.GetAll(filter: t => t.Name == titleModel.Title).FirstOrDefault();
             if (title == null)
             {
                 title      = new Title();
                 title.Name = titleModel.Title;
                 titleRepository.Save(title);
                 return(RedirectToAction("ManageTitles"));
             }
             else
             {
                 throw new ArgumentException("Invalid Title");
             }
         }
     }
     return(View(titleModel));
 }
Ejemplo n.º 6
0
 public UnitOfWork(XdContext context)
 {
     _context            = context;
     AddressInformations = new AddressInformationRepository(_context);
     AppUsers            = new AppUserRepository(_context);
     AppUserRoles        = new AppUserRoleRepository(_context);
     Contacts            = new ContactRepository(_context);
     Credentials         = new CredentialsRepository(_context);
     DbTypes             = new DbTypeRepository(_context);
     Entities            = new EntityRepository(_context);
     EntityTypes         = new EntityTypeRepository(_context);
     Fields = new FieldRepository(_context);
     FieldRequirementLevels = new FieldRequirementLevelRepository(_context);
     FieldTypes             = new FieldTypeRepository(_context);
     Forms           = new FormRepository(_context);
     FormTypes       = new FormTypeRepository(_context);
     Genders         = new GenderRepository(_context);
     MaritalStatuses = new MaritalStatusRepository(_context);
     MenuItems       = new MenuItemRepository(_context);
     Roles           = new RoleRepository(_context);
     Tabs            = new TabRepository(_context);
     Titles          = new TitleRepository(_context);
     Views           = new ViewRepository(_context);
     ViewTypes       = new ViewTypeRepository(_context);
 }
Ejemplo n.º 7
0
        public ActionResult ManageTitles()
        {
            TitleRepository        titleRepository = new TitleRepository();
            AdminControllerTitleVM titleModel      = new AdminControllerTitleVM();

            titleModel.titleList = titleRepository.GetAll();
            return(View(titleModel));
        }
Ejemplo n.º 8
0
        public ActionResult EditTeachers(int id)
        {
            TeacherRepository        teacherRepository = new TeacherRepository();
            TitleRepository          titleRepository   = new TitleRepository();
            Teacher                  teacher           = new Teacher();
            AdminControllerTeacherVM teacherModel      = new AdminControllerTeacherVM();
            List <SelectListItem>    SelectListTitle   = new List <SelectListItem>();
            SelectListItem           select            = null;
            Title title = new Title();

            teacher.Title = title;

            if (id > 0)
            {
                teacher = teacherRepository.GetById(id);
                select  = new SelectListItem()
                {
                    Text = teacher.Title.Name, Value = teacher.Title.Id.ToString()
                };
                SelectListTitle.Add(select);
            }

            teacherModel.TitleList = titleRepository.GetAll();
            foreach (var item in teacherModel.TitleList)
            {
                if (item.Id != teacher.Title.Id)
                {
                    select = new SelectListItem()
                    {
                        Text = item.Name, Value = item.Id.ToString()
                    };
                    SelectListTitle.Add(select);
                }
            }

            if (id > 0)
            {
                teacher = teacherRepository.GetById(id);
                teacherModel.FirstName = teacher.FirstName;
                teacherModel.LastName  = teacher.LastName;
                teacherModel.UserName  = teacher.UserName;
                teacherModel.Password  = teacher.Password;
                teacherModel.isActive  = teacher.IsActive;
                teacherModel.Id        = id;
            }

            if (id == 0)
            {
                teacher.FirstName = teacherModel.FirstName;
                teacher.LastName  = teacherModel.LastName;
                teacher.UserName  = teacherModel.UserName;
                teacher.Password  = teacherModel.Password;
                teacher.IsActive  = teacherModel.isActive;
            }
            teacherModel.ListItems = SelectListTitle;
            return(View(teacherModel));
        }
Ejemplo n.º 9
0
        public JsonResult Title(int?draw, int?start, int?length, List <Dictionary <string, string> > order, List <Dictionary <string, string> > columns)
        {
            var search = Request["search[value]"];
            var dir    = order[0]["dir"].ToLower();
            var column = columns[int.Parse(order[0]["column"])]["data"];

            var dataTableData = new TitleRepository().GetPage(search, draw, start, length, dir, column);

            return(Json(dataTableData, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 10
0
        public ActionResult TitleDetail(int?id)
        {
            TitleViewModel model = new TitleViewModel();

            if (id.HasValue)
            {
                model = new TitleRepository().GetByID((int)id);
            }
            ViewBag.Sex = DropDownList.GetTitle(model.SexID, id, true);
            return(PartialView("_Title", model));
        }
Ejemplo n.º 11
0
        static private ControllerContainer controllerConfig()
        {
            var db = new DbConnection();
            var materialRepository     = new MaterialRepository(db);
            var materialLoanRepository = new MaterialLoanRepository(db);
            var titleRepository        = new TitleRepository(db);
            var memberRepository       = new MemberRepository(db);
            var loanRepository         = new LoanRepository(db);

            return(new ControllerContainer(materialRepository, materialLoanRepository, titleRepository, memberRepository, loanRepository));
        }
Ejemplo n.º 12
0
        public void GetAll_Test()
        {
            // Arrange
            TestKolgraphEntities context = new TestKolgraphEntities();
            var repository = new TitleRepository(context);

            // Act
            IEnumerable <title> result = repository.GetAll();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(context.title.Count(), result.Count());
        }
Ejemplo n.º 13
0
        public void GetById_Test()
        {
            // Arrange
            TestKolgraphEntities context = new TestKolgraphEntities();
            var repository = new TitleRepository(context);
            int id         = 1;

            // Act
            title result = repository.GetById(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(id, result.id);
        }
        async Task GetDataAsync()
        {
            var authorRepo = new AuthorRepository();
            var titleRepo  = new TitleRepository();

            Task <IEnumerable <Author> > authorsTask = authorRepo.GetAuthorsAsync();
            Task <IEnumerable <Title> >  titlesTask  = titleRepo.GetTitlesAsync();

            await Task.WhenAll(authorsTask, titlesTask);

            int authorCount = authorsTask.Result.Count();
            int titleCount  = titlesTask.Result.Count();

            output.Text = (authorCount + titleCount).ToString();
        }
Ejemplo n.º 15
0
        public void GetAllFilterByCurrent_Test()
        {
            // Arrange
            TestKolgraphEntities context = new TestKolgraphEntities();
            var repository = new TitleRepository(context);
            var service    = new TitleService(repository);

            // Act
            IEnumerable <TitleModel> result = service.GetAllFilterByCurrent();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(context.title.Where(x => x.isCurrent).Count(), result.Count());
            Assert.AreEqual(result.Where(x => x.IsCurrent).Count(), result.Count());
        }
Ejemplo n.º 16
0
        public void GetById_Test()
        {
            // Arrange
            TestKolgraphEntities context = new TestKolgraphEntities();
            var repository = new TitleRepository(context);
            var service    = new TitleService(repository);
            int id         = 1;

            // Act
            TitleModel result = service.GetById(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(id, result.Id);
        }
Ejemplo n.º 17
0
        public JsonResult SaveTitle(TitleViewModel model)
        {
            ResponseData result = new Models.ResponseData();

            if (model.TiID != 0)
            {
                result = new TitleRepository().UpdateByEntity(model);
            }
            else
            {
                result = new TitleRepository().AddByEntity(model);
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult AddTitle(UniversitySystem.ViewModel.Titles.AddTitle model)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }

            TitleRepository titleRepo = new TitleRepository();
            Title title = new Title();

            title.Name = model.TitlteName;

            titleRepo.Save(title);

            return RedirectToAction("ListTeachers", "Teacher");
        }
Ejemplo n.º 19
0
 public void A_RegisteredTitle_creates_a_new_currency_in_the_database()
 {
     var bootStrapper = new BootStrapper();
     bootStrapper.StartServices();
     var serviceEvents = bootStrapper.GetService<IServiceEvents>();
     //1.- Create message
     var aggr = GenerateRandomAggregate();
     var message = GenerateMessage(aggr);
     //2.- Emit message
     serviceEvents.AddIncommingEvent(new IncommingEvent { @event = message });
     //3.- Load the saved country
     var repository = new TitleRepository(_configuration.TestServer);
     var title = repository.Get(aggr.Id);
     //4.- Check equality
     Assert.True(ObjectExtension.AreEqual(aggr, title));
 }
        public async Task <ActionResult> Full()
        {
            var authorRepo = new AuthorRepository();
            var titleRepo  = new TitleRepository();

            var authorsTask = authorRepo.GetAuthorsAsync();
            var titlesTask  = titleRepo.GetTitlesAsync();

            await Task.WhenAll(authorsTask, titlesTask);

            IEnumerable <Author> authors = authorsTask.Result;
            IEnumerable <Title>  titles  = titlesTask.Result;

            return(View("Full", new FullViewModel {
                Authors = authors, Titles = titles
            }));
        }
Ejemplo n.º 21
0
        public void TitlesShouldBeSortedAlphaNumericWhenSearchNotSupplied(List <Title> mockTitles)
        {
            mockTitles.Add(new Title
            {
                TitleName         = "1",
                TitleNameSortable = "1"
            });
            var mockTitleSet = mockTitles.AsDbSetMock();

            var mockApplicationDbContextFixture = new Mock <IApplicationDbContext>();

            mockApplicationDbContextFixture.Setup(a => a.Title).Returns(mockTitleSet.Object);
            var sut    = new TitleRepository(mockApplicationDbContextFixture.Object);
            var titles = sut.GetTitlesBySearchText(string.Empty);

            Assert.True(titles.First().TitleName == "1");
        }
        // GET api/Full/

        public async Task <FullResponse> Get()
        {
            var authorRepo = new AuthorRepository();
            var titleRepo  = new TitleRepository();

            var authorTask = authorRepo.GetAuthorsAsync();
            var titleTask  = titleRepo.GetTitlesAsync();

            await Task.WhenAll(authorTask, titleTask);

            var response = new FullResponse
            {
                Authors = authorTask.Result,
                Titles  = titleTask.Result
            };

            return(response);
        }
Ejemplo n.º 23
0
        public ActionResult EditTitles(int id)
        {
            Title                  title           = new Title();
            TitleRepository        titleRepository = new TitleRepository();
            AdminControllerTitleVM titleModel      = new AdminControllerTitleVM();

            if (id > 0)
            {
                title              = titleRepository.GetById(id);
                titleModel.Title   = title.Name;
                titleModel.TitleID = id;
            }

            if (id == 0)
            {
                title.Name = titleModel.Title;
            }
            return(View(titleModel));
        }
Ejemplo n.º 24
0
        private bool disposedValue = false; // To detect redundant calls
        public UnitOfWork(IConfiguration configuration)
        {
            _redisHandler  = new RedisHandler();
            _configuration = configuration;
            //_redisHandler = new RedisHandler(_configuration);

            _connection = new SqlConnection(_configuration.GetSection("Appsettings:ConnectionString").Value);
            _connection.Open();
            _transaction = _connection.BeginTransaction();



            _genericRepository = new GenericRepository <T>(_transaction);
            _tokenHandler      = new JwtSecurityTokenHandler();
            _authRepository    = new AuthRepository(_transaction);
            _titleRepository   = new TitleRepository(_transaction);
            _entryRepository   = new EntryRepository(_transaction);
            _helperRepository  = new HelperRepository(_transaction);
        }
Ejemplo n.º 25
0
        public TitleDataService()
        {
            var context = new ImdbContext();

            _castInfo        = new CastInfoRepository(context);
            _titles          = new TitleRepository(context);
            _casts           = new CastsRepository(context);
            _genre           = new GenreRepository(context);
            _format          = new FormatRepository(context);
            _userRating      = new UserRatingRepository(context);
            _titleFormat     = new TitleFormatRepository(context);
            _titleGenre      = new TitleGenreRepository(context);
            _titleAlias      = new TitleAliasRepository(context);
            _titleInfo       = new TitleInfoRepository(context);
            _episodes        = new GenericRepository <Episodes>(context);
            _comments        = new CommentsRepository(context);
            _bookmarks       = new BookmarkRepository(context);
            _flaggedComments = new FlaggedCommentsRepository(context);
        }
Ejemplo n.º 26
0
        public void A_UnregisteredTitle_modifies_Existing_country_in_the_database()
        {
            var bootStrapper = new BootStrapper();
            bootStrapper.StartServices();
            var serviceEvents = bootStrapper.GetService<IServiceEvents>();
            //1.- Create message
            var aggr = GenerateRandomAggregate();

            //2.- Create the tuple in the database
            var repository = new TitleRepository(_configuration.TestServer);
            repository.Insert(aggr);

            //3.- Emit message
            var message = GenerateMessage(aggr);
            message.MessageType = typeof(UnregisteredTitle).Name;
            serviceEvents.AddIncommingEvent(new IncommingEvent { @event = message });

            var tax = repository.Get(aggr.Id);
            Assert.Null(tax);
        }
Ejemplo n.º 27
0
        public JsonResult DeleteTitle(int id)
        {
            bool              TitleInUse        = false;
            Title             title             = new Title();
            TitleRepository   titleRepository   = new TitleRepository();
            TeacherRepository teacherRepository = new TeacherRepository();

            title = titleRepository.GetById(id);
            Teacher teacher = teacherRepository.GetAll(filter: t => t.Title.Id == id).FirstOrDefault();

            if (teacher == null)
            {
                titleRepository.Delete(title);
            }
            else
            {
                TitleInUse = true;
            }

            //return RedirectToAction("ManageTitles");
            return(Json(TitleInUse, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 28
0
        public void FullAsync()
        {
            AsyncManager.OutstandingOperations.Increment(2);

            var authorRepo = new AuthorRepository();

            authorRepo.GetAuthorsCompleted += (s, e) =>
            {
                AsyncManager.Parameters["authors"] = e.Authors;
                AsyncManager.OutstandingOperations.Decrement();
            };
            authorRepo.GetAuthorsEAP();


            var titleRepo = new TitleRepository();

            titleRepo.GetTitlesCompleted += (s, e) =>
            {
                AsyncManager.Parameters["titles"] = e.Titles;
                AsyncManager.OutstandingOperations.Decrement();
            };
            titleRepo.GetTitlesEAP();
        }
Ejemplo n.º 29
0
        public ActionResult Home()
        {
            AdminControllerAdminVM model             = new AdminControllerAdminVM();
            StudentRepository      studentRepository = new StudentRepository();
            TeacherRepository      teacherRepository = new TeacherRepository();
            CourseRepository       courseRepository  = new CourseRepository();
            SubjectRepository      subjectRepository = new SubjectRepository();
            TitleRepository        titleRepository   = new TitleRepository();

            model.ActiveStudentCount   = studentRepository.GetAll(filter: s => s.IsActive == true).Count;
            model.InActiveStudentCount = studentRepository.GetAll(filter: s => s.IsActive == false).Count;
            model.ActiveTeacherCount   = teacherRepository.GetAll(filter: t => t.IsActive == true).Count;
            model.InActiveTeacherCount = teacherRepository.GetAll(filter: t => t.IsActive == false).Count;
            model.CourseCount          = courseRepository.GetAll().Count;
            model.SubjectCount         = subjectRepository.GetAll().Count;
            model.TitleCount           = titleRepository.GetAll().Count();
            Administrator           admin           = new Administrator();
            AdministratorRepository adminRepository = new AdministratorRepository();

            admin           = adminRepository.GetById(AuthenticationManager.LoggedUser.Id);
            model.FirstName = admin.FirstName;
            model.LastName  = admin.LastName;
            return(View(model));
        }
 public ActionResult Home()
 {
     AdminControllerAdminVM model = new AdminControllerAdminVM();
     StudentRepository studentRepository = new StudentRepository();
     TeacherRepository teacherRepository = new TeacherRepository();
     CourseRepository courseRepository = new CourseRepository();
     SubjectRepository subjectRepository = new SubjectRepository();
     TitleRepository titleRepository = new TitleRepository();
     model.ActiveStudentCount = studentRepository.GetAll(filter: s => s.IsActive == true).Count;
     model.InActiveStudentCount = studentRepository.GetAll(filter: s => s.IsActive == false).Count;
     model.ActiveTeacherCount = teacherRepository.GetAll(filter: t => t.IsActive == true).Count;
     model.InActiveTeacherCount = teacherRepository.GetAll(filter: t => t.IsActive == false).Count;
     model.CourseCount = courseRepository.GetAll().Count;
     model.SubjectCount = subjectRepository.GetAll().Count;
     model.TitleCount = titleRepository.GetAll().Count();
     Administrator admin = new Administrator();
     AdministratorRepository adminRepository = new AdministratorRepository();
     admin = adminRepository.GetById(AuthenticationManager.LoggedUser.Id);
     model.FirstName = admin.FirstName;
     model.LastName = admin.LastName;
     return View(model);
 }
        public JsonResult CheckForExistingName(string name, string type, int id)
        {
            bool exist = false;
            switch (type)
            {
                case "Admin":
                    Administrator admin = new Administrator();
                    AdministratorRepository adminRepository = new AdministratorRepository();
                    admin = adminRepository.GetAll(filter: a => a.UserName == name && a.Id != id).FirstOrDefault();
                    if (admin != null)
                    {
                        exist = true;
                    };
                    break;
                case "Student":
                    Student student = new Student();
                    StudentRepository studentRepository = new StudentRepository();
                    student = studentRepository.GetAll(filter: s => s.UserName == name && s.Id != id).FirstOrDefault();
                    if (student != null)
                    {
                        exist = true;
                    };
                    break;
                case "Teacher":
                    Teacher teacher = new Teacher();
                    TeacherRepository teacherRepository = new TeacherRepository();
                    teacher = teacherRepository.GetAll(filter: t => t.UserName == name && t.Id != id).FirstOrDefault();
                    if (teacher != null)
                    {
                        exist = true;
                    };
                    break;
                case "Course":
                    Course course = new Course();
                    CourseRepository courseRepository = new CourseRepository();
                    course = courseRepository.GetAll(filter: c => c.Name == name).FirstOrDefault();
                    if (course != null)
                    {
                        exist = true;
                    };
                    break;
                case "Title":
                    Title title = new Title();
                    TitleRepository titleRepository = new TitleRepository();
                    title = titleRepository.GetAll(filter: t => t.Name == name).FirstOrDefault();
                    if (title != null)
                    {
                        exist = true;
                    };
                    break;
                case "Subject":
                    Subject subject = new Subject();
                    SubjectRepository subjectRepository = new SubjectRepository();
                    subject = subjectRepository.GetAll(filter: s => s.Name == name).FirstOrDefault();
                    if (subject != null)
                    {
                        exist = true;
                    };
                    break;
            }

            return Json(exist, JsonRequestBehavior.AllowGet);
        }
        public ActionResult EditTeacher(int id)
        {
            TeacherEditTeacherVM model = new TeacherEditTeacherVM();
            TitleRepository titleRepo = new TitleRepository();
            List<SelectListItem> list = new List<SelectListItem>();
            UserRepository<Teacher> teacherRepo = new UserRepository<Teacher>();

            Teacher teacher = teacherRepo.GetByID(id);

            var teacherTitle = titleRepo.GetByID(teacher.Title.ID);

            list.Add(new SelectListItem() { Text = teacherTitle.Name, Value = teacherTitle.ID.ToString() });
            var title = titleRepo.GetAll();

            foreach (var item in title)
            {
                if (item.ID != teacher.Title.ID)
                {
                    list.Add(new SelectListItem() { Text = item.Name, Value = item.ID.ToString() });
                }

            }
            model.FirstName = teacher.FirstName;
            model.LastName = teacher.LastName;
            model.Active = teacher.Active;
            model.TeacherID = teacher.ID;
            model.TitleList = list;

            return View(model);
        }
 public ActionResult EditTitles(int id, AdminControllerTitleVM titleModel)
 {
     TryUpdateModel(titleModel);
     if (ModelState.IsValid)
     {
         Title title = null;
         TitleRepository titleRepository = new TitleRepository();
         if (id > 0)
         {
             title = titleRepository.GetById(id);
             title.Name = titleModel.Title;
             titleRepository.Save(title);
             return RedirectToAction("ManageTitles");
         }
         else
         {
             title = titleRepository.GetAll(filter: t => t.Name == titleModel.Title).FirstOrDefault();
             if (title == null)
             {
                 title = new Title();
                 title.Name = titleModel.Title;
                 titleRepository.Save(title);
                 return RedirectToAction("ManageTitles");
             }
             else
             {
                 throw new ArgumentException("Invalid Title");
             }
         }
     }
     return View(titleModel);
 }
Ejemplo n.º 34
0
        public JsonResult SexByTitle(int titleid)
        {
            var result = new TitleRepository().GetSexByTitle(titleid);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 35
0
 public TitleBusiness()
 {
     TR = new TitleRepository();
 }
        public ActionResult EditTeacher(TeacherEditTeacherVM model)
        {
            if (!ModelState.IsValid)
            {
                model.TitleList = TeacherTitle();
                return View(model);
            }
            UnitOfWork unitOfWork = new UnitOfWork();
            UserRepository<Teacher> teacherRepo = new UserRepository<Teacher>(unitOfWork);
            TitleRepository tiRepo = new TitleRepository(unitOfWork);

            Teacher teacher = teacherRepo.GetByID(model.TeacherID);

            try
            {
                int TitleId = Convert.ToInt32(model.selectedValueID);
                Title title = tiRepo.GetByID(TitleId);

                if (model.FirstName != teacher.FirstName || model.LastName != teacher.LastName || model.Active != teacher.Active || TitleId != teacher.Title.ID)
                {
                    teacher.FirstName = model.FirstName;
                    teacher.LastName = model.LastName;
                    teacher.Username = model.FirstName;
                    teacher.Active = model.Active;
                    teacher.Title = title;

                    teacherRepo.Save(teacher);
                    unitOfWork.Commit();
                }
            }
            catch (Exception)
            {
                unitOfWork.RollBack();
            }
            return RedirectToAction("ListTeachers", "Teacher");
        }
Ejemplo n.º 37
0
        public JsonResult DeleteTitle(int id)
        {
            var result = new TitleRepository().RemoveByID(id);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult CreateTeacher(TeacherCreateTeacherVM model)
        {
            UnitOfWork unitOfWork = new UnitOfWork();
            Teacher teacher = new Teacher();
            UserRepository<Teacher> teacherRepo = new UserRepository<Teacher>(unitOfWork);
            TitleRepository titleRepo = new TitleRepository(unitOfWork);

            if (!ModelState.IsValid)
            {
                model.TitleList = TeacherTitle();

                return View(model);
            }

            try
            {
                teacher.Username = model.FirstName;
                teacher.FirstName = model.FirstName;
                teacher.LastName = model.LastName;

                int tittleId = Convert.ToInt32(model.selectedValueID);

                Title title = titleRepo.GetByID(tittleId);

                teacher.Title = title;

                UniversitySystem.Hasher.Passphrase hash = UniversitySystem.Hasher.PasswordHasher.Hash("password");
                teacher.Hash = hash.Hash;
                teacher.Salt = hash.Salt;
                teacher.Active = true;

                teacherRepo.Save(teacher);

                unitOfWork.Commit();
            }

            catch (Exception)
            {
                unitOfWork.RollBack();
                throw;
            }

            return RedirectToAction("ListTeachers", "Teacher");
        }
        public List<SelectListItem> TeacherTitle()
        {
            TitleRepository titleRepo = new TitleRepository();
            List<SelectListItem> list = new List<SelectListItem>();

            var title = titleRepo.GetAll();

            foreach (var item in title)
            {
                list.Add(new SelectListItem() { Text = item.Name, Value = item.ID.ToString() });
            }
            return list;
        }
        public ActionResult EditTitles(int id)
        {
            Title title = new Title();
            TitleRepository titleRepository = new TitleRepository();
            AdminControllerTitleVM titleModel = new AdminControllerTitleVM();

            if (id > 0)
            {
                title = titleRepository.GetById(id);
                titleModel.Title = title.Name;
                titleModel.TitleID = id;
            }

            if (id == 0)
            {
                title.Name = titleModel.Title;
            }
            return View(titleModel);
        }
 public void TestInitialize()
 {
     // Arrange
     context         = new ApplicationDbContext();
     titleRepository = new TitleRepository(context);
 }
        public ActionResult EditTeachers(int id, AdminControllerTeacherVM teacherModel)
        {
            UnitOfWork uOw = new UnitOfWork();
            Teacher teacher = null;
            Title title = new Title();
            TitleRepository titleRepository = new TitleRepository(uOw);
            TeacherRepository teacherRepository = new TeacherRepository(uOw);

            TryUpdateModel(teacherModel);
            if (teacherModel.ListItems == null)
            {
                teacherModel.TitleList = titleRepository.GetAll();
                List<SelectListItem> SelectListTitle = new List<SelectListItem>();

                foreach (var item in teacherModel.TitleList)
                {
                    SelectListTitle.Add(new SelectListItem() { Text = item.Name, Value = item.Id.ToString() });
                }
                teacherModel.ListItems = SelectListTitle;
            }

            if (ModelState.IsValid)
            {
                if (id > 0)
                {
                    teacher = teacherRepository.GetById(id);
                    teacher.FirstName = teacherModel.FirstName;
                    teacher.LastName = teacherModel.LastName;
                    teacher.UserName = teacherModel.UserName;
                    teacher.Password = teacherModel.Password;
                    title = titleRepository.GetById(teacherModel.TitleID);
                    teacher.Title = title;
                    teacher.IsActive = teacherModel.isActive;
                    teacherRepository.Save(teacher);
                    uOw.Commit();
                    return RedirectToAction("ManageTeachers");
                }
                else
                {
                    teacher = teacherRepository.GetAll(filter: t => t.UserName == teacherModel.UserName).FirstOrDefault();
                    if (teacher == null)
                    {
                        teacher = new Teacher();
                        teacher.FirstName = teacherModel.FirstName;
                        teacher.LastName = teacherModel.LastName;
                        teacher.UserName = teacherModel.UserName;
                        teacher.Password = SecurityService.CreateHash(teacherModel.Password);
                        title = titleRepository.GetById(teacherModel.TitleID);
                        teacher.Title = title;
                        teacher.IsActive = teacherModel.isActive;
                        teacherRepository.Save(teacher);
                        uOw.Commit();
                        return RedirectToAction("ManageTeachers");
                    }
                    else
                    {
                        throw new ArgumentException("Invalid username !");
                    }
                }
            }
            return View(teacherModel);
        }
        public JsonResult DeleteTitle(int id)
        {
            bool TitleInUse = false;
            Title title = new Title();
            TitleRepository titleRepository = new TitleRepository();
            TeacherRepository teacherRepository = new TeacherRepository();
            title = titleRepository.GetById(id);
            Teacher teacher = teacherRepository.GetAll(filter: t => t.Title.Id == id).FirstOrDefault();
            if (teacher == null)
            {
                titleRepository.Delete(title);
            }
            else
            {
                TitleInUse = true;
            }

            //return RedirectToAction("ManageTitles");
            return Json(TitleInUse, JsonRequestBehavior.AllowGet);
        }
        public ActionResult EditTeachers(int id)
        {
            TeacherRepository teacherRepository = new TeacherRepository();
            TitleRepository titleRepository = new TitleRepository();
            Teacher teacher = new Teacher();
            AdminControllerTeacherVM teacherModel = new AdminControllerTeacherVM();
            List<SelectListItem> SelectListTitle = new List<SelectListItem>();
            SelectListItem select = null;
            Title title = new Title();
            teacher.Title = title;

            if (id > 0)
            {
                teacher = teacherRepository.GetById(id);
                select = new SelectListItem() { Text = teacher.Title.Name, Value = teacher.Title.Id.ToString() };
                SelectListTitle.Add(select);
            }

            teacherModel.TitleList = titleRepository.GetAll();
            foreach (var item in teacherModel.TitleList)
            {
                if (item.Id != teacher.Title.Id)
                {
                    select = new SelectListItem() { Text = item.Name, Value = item.Id.ToString() };
                    SelectListTitle.Add(select);
                }
            }

            if (id > 0)
            {
                teacher = teacherRepository.GetById(id);
                teacherModel.FirstName = teacher.FirstName;
                teacherModel.LastName = teacher.LastName;
                teacherModel.UserName = teacher.UserName;
                teacherModel.Password = teacher.Password;
                teacherModel.isActive = teacher.IsActive;
                teacherModel.Id = id;
            }

            if (id == 0)
            {
                teacher.FirstName = teacherModel.FirstName;
                teacher.LastName = teacherModel.LastName;
                teacher.UserName = teacherModel.UserName;
                teacher.Password = teacherModel.Password;
                teacher.IsActive = teacherModel.isActive;
            }
            teacherModel.ListItems = SelectListTitle;
            return View(teacherModel);
        }
Ejemplo n.º 45
0
 public TitleService(ApplicationDbContext context)
 {
     this.titleRepository = new TitleRepository(context);
 }
 public ActionResult ManageTitles()
 {
     TitleRepository titleRepository = new TitleRepository();
     AdminControllerTitleVM titleModel = new AdminControllerTitleVM();
     titleModel.titleList = titleRepository.GetAll();
     return View(titleModel);
 }