예제 #1
0
 public UnitOfWork()
 {
     _context = new ModelContainer();
     Media    = new MediaRepository(_context);
     Persons  = new PersonsRepository(_context);
     Events   = new EventsRepository(_context);
     Tags     = new TagsRepository(_context);
 }
예제 #2
0
 public bool UpdatePerson(PersonModel person)
 {
     if (PersonsRepository.Update(Core.Transformer.AsDatabaseModel(person)) != null)
     {
         return(true);
     }
     return(false);
 }
예제 #3
0
 internal UnitOfWork(KatSystemDbContext context)
 {
     this.context = context;
     Users        = new UsersRepository(context);
     Vehicles     = new VehiclesRepository(context);
     Persons      = new PersonsRepository(context);
     Fines        = new FinesRepository(context);
 }
예제 #4
0
        public bool DeletePerson(long id)
        {
            if (!PersonsRepository.PersonExists(id))
            {
                return(false);
            }

            PersonsRepository.DeletePerson(id);
            return(true);
        }
 public CodeCamperUnitOfWork(string nameOrConnectionString = "CodeCamper")
     : base(new CodeCamperDbContext(nameOrConnectionString))
 {
     RoomsRepository = new EntityFrameworkReadRepository<Room>(DbContext);
     TimeSlotsRepository = new EntityFrameworkReadRepository<TimeSlot>(DbContext);
     TracksRepository = new EntityFrameworkReadRepository<Track>(DbContext);
     PersonsRepository = new PersonsRepository(DbContext);
     SessionsRepository = new SessionsRepository(DbContext);
     AttendanceRepository = new AttendanceRepository(DbContext);
 }
        public void Delete_CallsContextDelete_WhenCalled(
            [NotNull, Frozen] IPersonsContext context,
            [NotNull] PersonsRepository sut)
        {
            // Arrange
            // Act
            sut.Delete(-1);

            // Assert
            context.Received().Delete(-1);
        }
예제 #7
0
        public void Setup()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            _context = new ApplicationDbContext(options);
            _repos   = new PersonsRepository <PersonsModel>(_context, _mapper);
            _service = new PersonsService(_context, _mapper, _repos);
            PrefillRepo();
        }
예제 #8
0
        public HttpResponseMessage UpdatePerson([FromUri] int id, [FromBody] ActualizarPersonaRequest request)
        {
            var alumno = PersonsRepository.ConsultarPersonaByID(id);

            if (alumno == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            PersonsRepository.ActualizarPersona(id, request.Nombre, request.idRol);
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        public void All_CallsContextPersons_WhenCalled(
            [NotNull, Frozen] IPersonsContext context,
            [NotNull] PersonsRepository sut)
        {
            // Arrange
            // Act
            // ReSharper disable once UnusedVariable
            IQueryable <IPerson> actual = sut.All;

            // Assert
            context.Received().Persons();
        }
예제 #10
0
        public void TestMethod2()
        {
            var repository = new PersonsRepository(connectionString);
            var result     = repository.LoadPagedAll("cl", 0, 5, "FirstName", "ASC");

            Assert.IsNotNull(result);

            Console.WriteLine($"{result.Count}");
            foreach (var person in result.Items)
            {
                Console.WriteLine($"{person.FirstName} {person.LastName}");
            }
        }
예제 #11
0
 public WorksService(
     WorksRepository worksRepository,
     MarksRepository marksRepository,
     WorkTypesRepository workTypesRepository,
     PersonsRepository personsRepository,
     IMemoryCache memoryCache)
 {
     _worksRepository     = worksRepository;
     _marksRepository     = marksRepository;
     _workTypesRepository = workTypesRepository;
     _personsRepository   = personsRepository;
     _memoryCache         = memoryCache;
 }
예제 #12
0
 public HttpResponseMessage GetPersons()
 {
     try
     {
         var listaPersons = PersonsRepository.ConsultarPersonas();
         return(Request.CreateResponse(HttpStatusCode.OK, listaPersons));
     }
     catch (Exception e)
     {
         Console.WriteLine($"An Exception has been caught: {e.Message}");
         return(Request.CreateResponse(HttpStatusCode.InternalServerError));
     }
 }
        public void Delete_ReturnsPerson_WhenCalled(
            [NotNull] IPerson person,
            [NotNull, Frozen] IPersonsContext context,
            [NotNull] PersonsRepository sut)
        {
            // Arrange
            context.Delete(Arg.Any <int>()).Returns(person);

            // Act
            IPerson actual = sut.Delete(-1);

            // Assert
            Assert.Equal(person,
                         actual);
        }
예제 #14
0
 public bool DeletePerson(int personID)
 {
     try {
         var updatePerson = PersonsRepository.Get().Where(m => m.Id == personID).FirstOrDefault();
         updatePerson.IsDeleted = true;
         if (PersonsRepository.Update(updatePerson) != null)
         {
             return(true);
         }
         return(false);
     }catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
        public void All_ReturnsPersons_WhenCalled(
            [NotNull, Frozen] IPersonsContext context,
            [NotNull] PersonsRepository sut)
        {
            // Arrange
            context.Persons().Returns(CreatePersons);

            // Act
            // ReSharper disable once UnusedVariable
            IQueryable <IPerson> actual = sut.All;

            // Assert
            Assert.Equal(2,
                         actual.Count());
        }
예제 #16
0
        public void AssignId_test()
        {
            //Arrange

            const int         expectedId = 1;
            PersonsRepository persons    = new PersonsRepository();

            //Act

            PrivateObject privateObject = new PrivateObject(persons);
            var           id            = privateObject.Invoke("AssignId");

            //Assert

            Assert.AreEqual(expectedId, id);
        }
 public bool InsertPerson(Persons entity)
 {
     try
     {
         bool isSuccess;
         using (var repo = new PersonsRepository())
         {
             isSuccess = repo.Insert(entity);
         }
         return(isSuccess);
     }
     catch (Exception ex)
     {
         LogHelper.Log(LogTarget.File, ExceptionHelper.ExceptionToString(ex), true);
         throw new Exception("BusinessLogic:PersonsBusiness::InsertPerson::Error occured.", ex);
     }
 }
예제 #18
0
        public bool DeletePersonById(int empId)
        {
            try
            {
                using (var repository = new PersonsRepository())
                {
                    return(repository.DeleteById(empId));
                }
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                throw new Exception("BusinessLogic:PersonsBusiness::DeletePersonById::Error occured.", ex);
            }
        }
 public bool DeletePersonById(int ID)
 {
     try
     {
         bool isSuccess;
         using (var repo = new PersonsRepository())
         {
             isSuccess = repo.DeletedById(ID);
         }
         return(isSuccess);
     }
     catch (Exception ex)
     {
         LogHelper.Log(LogTarget.File, ExceptionHelper.ExceptionToString(ex), true);
         throw new Exception("BusinessLogic:PersonsBusiness::DeletePerson::Error occured.", ex);
     }
 }
예제 #20
0
 public HttpResponseMessage GetPersonByID(int id)
 {
     try
     {
         var persona = PersonsRepository.ConsultarPersonaByID(id);
         if (persona == null)
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound));
         }
         return(Request.CreateResponse(HttpStatusCode.OK, persona));
     }
     catch (Exception e)
     {
         Console.WriteLine($"An Exception has been caught: {e.Message}");
         return(Request.CreateResponse(HttpStatusCode.InternalServerError));
     }
 }
예제 #21
0
 public bool AddPerson(PersonModel person)
 {
     try
     {
         var addPerson = PersonsRepository.Add(Core.Transformer.AsDatabaseModel(person));
         if (addPerson != null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
예제 #22
0
        public void TestPersonsRepositoryCRUDMethods()
        {
            bool CreateProfile;
            bool ReadProfile;
            bool UpdateProfile;
            bool DeleteProfile;

            var personsRepository = new PersonsRepository();

            var addProfileModel =
                new AddProfileModel
            {
                FirstName   = "test",
                LastName    = "test",
                Patronymic  = "test",
                PhoneNumber = "test"
            };
            var addedProfileId = personsRepository.AddProfile(addProfileModel);

            CreateProfile = addedProfileId > 0 ? true : false;

            var profile = personsRepository.GetProfile(addedProfileId);

            ReadProfile = !string.IsNullOrEmpty(profile?.FirstName) ? true : false;

            var updateProfileModel =
                new UpdateProfileModel
            {
                Id          = addedProfileId,
                FirstName   = "testUpdated",
                LastName    = "testUpdated",
                Patronymic  = "testUpdated",
                PhoneNumber = "testUpdated"
            };

            UpdateProfile = personsRepository.UpdateProfile(updateProfileModel);

            personsRepository.DeleteProfile(addedProfileId);
            DeleteProfile = true;

            Assert.IsTrue(CreateProfile && ReadProfile && UpdateProfile && DeleteProfile);
        }
예제 #23
0
        public bool UpdatePerson(PersonsEntity entity)
        {
            try
            {
                bool bOpDoneSuccessfully;
                using (var repository = new PersonsRepository())
                {
                    bOpDoneSuccessfully = repository.Update(entity);
                }

                return(bOpDoneSuccessfully);
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                throw new Exception("BusinessLogic:PersonsBusiness::UpdatePerson::Error occured.", ex);
            }
        }
예제 #24
0
        public PersonsEntity SelectPersonById(int personId)
        {
            try
            {
                PersonsEntity returnedEntity;
                using (var repository = new PersonsRepository())
                {
                    returnedEntity = repository.SelectById(personId);
                }

                return(returnedEntity);
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                throw new Exception("BusinessLogic:PersonsBusiness::SelectPersonById::Error occured.", ex);
            }
        }
 public Persons SelectPersonById(int personId)
 {
     try
     {
         Persons responseEntitiy;
         using (var repo = new PersonsRepository())
         {
             responseEntitiy = repo.SelectedById(personId);
             if (responseEntitiy == null)
             {
                 throw new NullReferenceException("Person doesnt exists!");
             }
         }
         return(responseEntitiy);
     }
     catch (Exception ex)
     {
         LogHelper.Log(LogTarget.File, ExceptionHelper.ExceptionToString(ex), true);
         throw new Exception("BusinessLogic:PersonsBusiness::SelectPersonById::Error occured.", ex);
     }
 }
        public List <Persons> SelectAllPersons()
        {
            var responseEntities = new List <Persons>();

            try
            {
                using (var repo = new PersonsRepository())
                {
                    foreach (var entity in repo.SelectAll())
                    {
                        responseEntities.Add(entity);
                    }
                }
                return(responseEntities);
            }
            catch (Exception ex)
            {
                LogHelper.Log(LogTarget.File, ExceptionHelper.ExceptionToString(ex), true);
                throw new Exception("BusinessLogic:PersonsBusiness::SelectAllPersons::Error occured.", ex);
            }
        }
예제 #27
0
        public void TestGetProfilesMethod()
        {
            bool Success;

            var personsRepository = new PersonsRepository();

            var addProfileModel =
                new AddProfileModel
            {
                FirstName   = "test",
                LastName    = "test",
                Patronymic  = "test",
                PhoneNumber = "test"
            };
            var addedProfileId = personsRepository.AddProfile(addProfileModel);
            var profilesList   = personsRepository.GetProfiles();

            Success = profilesList.Count > 0 ? true : false;
            personsRepository.DeleteProfile(addedProfileId);

            Assert.IsTrue(Success);
        }
예제 #28
0
        public List <PersonsEntity> SelectAllPersons()
        {
            var returnedEntities = new List <PersonsEntity>();

            try
            {
                using (var repository = new PersonsRepository())
                {
                    foreach (var entity in repository.SelectAll())
                    {
                        returnedEntities.Add(entity);
                    }
                }

                return(returnedEntities);
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                throw new Exception("BusinessLogic:PersonsBusiness::SelectAllPersons::Error occured.", ex);
            }
        }
 //Constructor that receives the PersonsDatabaseAccess variable
 public PersonsController(PersonsDatabaseAccess db)
 {
     personRepository = new PersonsRepository(db);
 }
예제 #30
0
        public HttpResponseMessage DeleteAlumno(int id)
        {
            PersonsRepository.EliminarPersona(id);

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
예제 #31
0
        public HttpResponseMessage CreatePerson([FromBody] CrearPersonaRequest request)
        {
            var persona = PersonsRepository.InsertarPersona(request.Nombre, request.idRol);

            return(Request.CreateResponse(HttpStatusCode.OK, persona));
        }