Example #1
0
        public static JobDAO mapToJobDAO(jobDTO b)
        {
            JobDAO a = new JobDAO();

            if (b.client != null)
            {
                a.Client = Mapping.ClientMapper.MapToClientDAO(b.client);
            }
            a.ClientID          = b.ClientId;
            a.Complete          = b.Complete;
            a.EstimatedDuration = b.EstimatedDuration;
            a.Id            = b.Id;
            a.Notes         = b.Notes;
            a.ServiceTypeID = b.ServiceTypeId;
            if (b.StartDate != null)
            {
                a.StartDate = b.StartDate;
            }
            if (b.type != null)
            {
                a.ServiceType = Mapping.ServiceTypeMapper.MaptoServiceTypeDAO(b.type);
            }
            if (b.user != null)
            {
                a.User = Mapping.AspNetUserMapper.mapToUserDAO(b.user);
            }
            a.UserID = b.UserId;
            a.Hours  = b.Hours;
            return(a);
        }
Example #2
0
        public ActionResult <List <JobPostReturnedModel> > GetAvailableWorks([FromQuery(Name = "categories")] Categories[] categories, [FromQuery(Name = "address")] string address, [FromQuery(Name = "distance")] int?distance, [FromQuery(Name = "rating")] int?rating)
        {
            try
            {
                int?mateID = ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)this.ControllerContext.HttpContext.User.Identity);

                if (mateID == null)
                {
                    return(NotFound(new ErrorMessageModel("Utilizador não existe!")));
                }

                MateDAO mateDao = new MateDAO(_connection);
                Mate    mate    = mateDao.FindMateById((int)mateID);

                if (address == null)
                {
                    address = mate.Address;
                }

                IJobDAO jobDAO = new JobDAO(_connection);
                List <JobPostReturnedModel> postsList = _mapper.Map <List <JobPostReturnedModel> >(jobDAO.GetJobs(categories, address, distance, rating, (int)mateID));

                return(Ok(postsList));
            }
            catch (Exception ex)
            {
                return(UnprocessableEntity(new ErrorMessageModel(ex.Message)));
            }
        }
Example #3
0
        public void CanSearchJobPostWithTwoCategoryTest()
        {
            IEmployerDAO <Employer> EmployerDAO = new EmployerDAO(_connection);
            Employer testEmployer = new Employer();

            testEmployer.FirstName   = "Marcelo";
            testEmployer.LastName    = "Carvalho";
            testEmployer.UserName    = "******";
            testEmployer.Password    = "******";
            testEmployer.Email       = "*****@*****.**";
            testEmployer.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testEmployer.Address     = "Lixa";

            Employer returned = EmployerDAO.Create(testEmployer);

            IJobDAO jobPostDAO = new JobDAO(_connection);
            JobPost testPost   = new JobPost();

            testPost.Title         = "Canalização Estourada";
            testPost.Category      = Categories.PLUMBING;
            testPost.Description   = "Grande estouro nos canos da sanita";
            testPost.Tradable      = true;
            testPost.InitialPrice  = 60.6;
            testPost.Address       = "Rua sem fim";
            testPost.PaymentMethod = new[] { Payment.PAYPAL, Payment.MONEY };

            JobPost testPost2 = new JobPost();

            testPost2.Title         = "Cortar Relva";
            testPost2.Category      = Categories.GARDENING;
            testPost2.Description   = "Isto parece a amazonia!";
            testPost2.Tradable      = true;
            testPost2.InitialPrice  = 60.6;
            testPost2.Address       = "Rua sem fim";
            testPost2.PaymentMethod = new[] { Payment.PAYPAL, Payment.MONEY };

            jobPostDAO.Create(returned.Id, testPost);
            jobPostDAO.Create(returned.Id, testPost2);

            Categories[] categories = { Categories.PLUMBING, Categories.GARDENING };
            List <JobPostReturnedModel> jobPosts = jobPostDAO.GetJobs(categories, "", null, null, 1);

            JobPostReturnedModel[] jobPostsArray = jobPosts.ToArray();

            Assert.Equal("Canalização Estourada", jobPostsArray[0].Title);
            Assert.Equal(Categories.PLUMBING, jobPostsArray[0].Category);
            Assert.Equal("Grande estouro nos canos da sanita", jobPostsArray[0].Description);
            Assert.True(jobPostsArray[0].Tradable);
            Assert.Equal(60.6, jobPostsArray[0].InitialPrice);
            Assert.Equal("Rua sem fim", jobPostsArray[0].Address);

            Assert.Equal("Cortar Relva", jobPostsArray[1].Title);
            Assert.Equal(Categories.GARDENING, jobPostsArray[1].Category);
            Assert.Equal("Isto parece a amazonia!", jobPostsArray[1].Description);
            Assert.True(jobPostsArray[1].Tradable);
            Assert.Equal(60.6, jobPostsArray[1].InitialPrice);
            Assert.Equal("Rua sem fim", jobPostsArray[1].Address);

            _fixture.Dispose();
        }
Example #4
0
        public void CanFindJobPostByIdOrReturnNullWhenNotFoundTest()
        {
            IEmployerDAO <Employer> EmployerDAO = new EmployerDAO(_connection);
            Employer testEmployer = new Employer();

            testEmployer.FirstName   = "Marcelo";
            testEmployer.LastName    = "Carvalho";
            testEmployer.UserName    = "******";
            testEmployer.Password    = "******";
            testEmployer.Email       = "*****@*****.**";
            testEmployer.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testEmployer.Address     = "Lixa";

            Employer returned = EmployerDAO.Create(testEmployer);

            IJobDAO jobPostDAO = new JobDAO(_connection);
            JobPost testPost   = new JobPost();

            testPost.Title         = "Canalização Estourada";
            testPost.Category      = Categories.PLUMBING;
            testPost.Description   = "Grande estouro nos canos da sanita";
            testPost.Tradable      = true;
            testPost.InitialPrice  = 60.6;
            testPost.Address       = "Rua sem fim";
            testPost.PaymentMethod = new[] { Payment.PAYPAL, Payment.MONEY };

            JobPost returnedPost = jobPostDAO.Create(returned.Id, testPost);

            Assert.Equal(returnedPost.Id, jobPostDAO.FindById(returnedPost.Id).Id);

            //when not found
            Assert.Null(jobPostDAO.FindById(200));

            _fixture.Dispose();
        }
Example #5
0
        public IActionResult UploadImagesToPost(int id,
                                                [FromForm] IFormFileCollection images,
                                                [FromForm] IFormFile mainImage)
        {
            try
            {
                int?employerID = ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)this.ControllerContext.HttpContext.User.Identity);

                if (employerID == null)
                {
                    return(Unauthorized(new ErrorMessageModel("Não Autorizado!")));
                }

                IJobDAO jobDAO = new JobDAO(_connection, this._environment.ContentRootPath);

                if (jobDAO.FindById(id, (int)employerID) == null)
                {
                    return(NotFound(new ErrorMessageModel("Post não encontrado!")));
                }

                SuccessMessageModel message = jobDAO.UploadImagesToPost(id, images, mainImage);

                return(Ok(message));
            }
            catch (Exception e)
            {
                return(BadRequest(new ErrorMessageModel(e.Message)));
            }
        }
Example #6
0
 public ProjetoController(ProjetoDAO projetoDAO, JobDAO jobDAO, StatusDAO statusDAO, IHostingEnvironment hosting)
 {
     _projetoDAO = projetoDAO;
     _jobDAO     = jobDAO;
     _statusDAO  = statusDAO;
     _hosting    = hosting;
 }
Example #7
0
        public IActionResult deleteImage(int post, ImageName image)
        {
            int?id = ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)this.ControllerContext.HttpContext.User.Identity);

            if (id == null)
            {
                return(Unauthorized(new ErrorMessageModel("Sem Autorização ou sem sessão inciada")));
            }

            if (image == null)
            {
                return(BadRequest(new ErrorMessageModel("Nome de imagem não enviado!")));
            }

            try
            {
                JobDAO jobDAO  = new JobDAO(_connection, this._environment.ContentRootPath);
                bool   deleted = jobDAO.deleteImage((int)id, post, image);

                if (deleted == true)
                {
                    return(Ok(new SuccessMessageModel("Imagem apagada!")));
                }
                else
                {
                    return(BadRequest(new ErrorMessageModel("Imagem não apagada ou inexistente!")));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(new ErrorMessageModel(e.Message)));
            }
        }
Example #8
0
 public MemberBUS(MainBUS main)
 {
     this.mainBus   = main;
     this.memberDAO = new MemberDAO(this.mainBus.GetCommand());
     this.jobDAO    = new JobDAO(this.mainBus.GetCommand());
     this.data      = this.memberDAO.getAllMember();
 }
Example #9
0
        //private int ProjetoId;

        public JobController(JobDAO jobDAO, TarefaDAO tarefaDAO, DepartamentoDAO departamentoDAO, ProjetoDAO projetoDAO, StatusDAO statusDAO, IHostingEnvironment hosting)
        {
            _projetoDAO      = projetoDAO;
            _jobDAO          = jobDAO;
            _tarefaDAO       = tarefaDAO;
            _departamentoDAO = departamentoDAO;
            _statusDAO       = statusDAO;
            _hosting         = hosting;
        }
Example #10
0
        //private int JobId;

        public TarefaController(ProjetoDAO projetoDAO, JobDAO jobDAO, TarefaDAO tarefaDAO, FuncionarioDAO funcionarioDAO, StatusDAO statusDAO, IHostingEnvironment hosting)
        {
            _projetoDAO     = projetoDAO;
            _jobDAO         = jobDAO;
            _tarefaDAO      = tarefaDAO;
            _funcionarioDAO = funcionarioDAO;
            _statusDAO      = statusDAO;
            _hosting        = hosting;
        }
        public void CanMakeOfferOnJobWithoutPriceTest()
        {
            IEmployerDAO <Employer> EmployerDAO = new EmployerDAO(_connection);
            Employer testEmployer = new Employer();

            testEmployer.FirstName   = "Marcelo";
            testEmployer.LastName    = "Carvalho";
            testEmployer.UserName    = "******";
            testEmployer.Password    = "******";
            testEmployer.Email       = "*****@*****.**";
            testEmployer.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testEmployer.Address     = "Lixa";

            Employer returned = EmployerDAO.Create(testEmployer);

            IJobDAO jobPostDAO = new JobDAO(_connection);
            JobPost testPost   = new JobPost();

            testPost.Title         = "Canalização Estourada";
            testPost.Category      = Categories.PLUMBING;
            testPost.Description   = "Grande estouro nos canos da sanita";
            testPost.Tradable      = true;
            testPost.InitialPrice  = 60.6;
            testPost.Address       = "Rua sem fim";
            testPost.PaymentMethod = new[] { Payment.PAYPAL, Payment.MONEY };

            JobPost jobReturned = jobPostDAO.Create(returned.Id, testPost);

            IMateDAO <Mate> MateDAO  = new MateDAO(_connection);
            Mate            testMate = new Mate();

            testMate.FirstName   = "Miguel";
            testMate.LastName    = "Dev";
            testMate.UserName    = "******";
            testMate.Password    = "******";
            testMate.Email       = "*****@*****.**";
            testMate.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testMate.Address     = "Figueiró";
            testMate.Categories  = new[] { Categories.CLEANING, Categories.PLUMBING };
            testMate.Rank        = Ranks.SUPER_MATE;
            testMate.Range       = 20;

            Mate returnedMate = MateDAO.Create(testMate);

            Offer mateOffer = new Offer();

            mateOffer.Price   = 0;
            mateOffer.JobPost = jobReturned;
            Offer offer = jobPostDAO.makeOfferOnJob(mateOffer, returnedMate.Id);

            //Verificar que o preço foi estabelicido com o default
            Assert.Equal(testPost.InitialPrice, offer.Price);
            Assert.Equal(mateOffer.JobPost.Id, offer.JobPost.Id);
            Assert.False(offer.Approved);

            _fixture.Dispose();
        }
Example #12
0
        public void ReturnEmptyWhenSearchJobWithWrongLocationTest()
        {
            IEmployerDAO <Employer> EmployerDAO = new EmployerDAO(_connection);
            Employer testEmployer = new Employer();

            testEmployer.FirstName   = "Marcelo";
            testEmployer.LastName    = "Carvalho";
            testEmployer.UserName    = "******";
            testEmployer.Password    = "******";
            testEmployer.Email       = "*****@*****.**";
            testEmployer.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testEmployer.Address     = "Rua Eng. Luís Carneiro Leão, Figueiró";

            Employer returned = EmployerDAO.Create(testEmployer);

            IJobDAO jobPostDAO = new JobDAO(_connection);
            JobPost testPost   = new JobPost();

            testPost.Title         = "Canalização Estourada";
            testPost.Category      = Categories.PLUMBING;
            testPost.Description   = "Grande estouro nos canos da sanita";
            testPost.Tradable      = true;
            testPost.InitialPrice  = 60.6;
            testPost.Address       = "Rua sem fim";
            testPost.PaymentMethod = new[] { Payment.PAYPAL, Payment.MONEY };

            JobPost jobReturned = jobPostDAO.Create(returned.Id, testPost);

            IMateDAO <Mate> MateDAO  = new MateDAO(_connection);
            Mate            testMate = new Mate();

            testMate.FirstName   = "Miguel";
            testMate.LastName    = "Dev";
            testMate.UserName    = "******";
            testMate.Password    = "******";
            testMate.Email       = "*****@*****.**";
            testMate.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testMate.Address     = "Random City";
            testMate.Categories  = new[] { Categories.CLEANING, Categories.PLUMBING };
            testMate.Rank        = Ranks.SUPER_MATE;
            testMate.Range       = 20;

            Mate returnedMate = MateDAO.Create(testMate);

            Offer mateOffer = new Offer();

            mateOffer.Price    = 20;
            mateOffer.Approved = false;
            mateOffer.JobPost  = jobReturned;
            Offer offer = jobPostDAO.makeOfferOnJob(mateOffer, returnedMate.Id);

            Categories[] categories = { Categories.PLUMBING };
            Assert.Empty(jobPostDAO.GetJobs(categories, testMate.Address, 400, null, returnedMate.Id));

            _fixture.Dispose();
        }
Example #13
0
        public void CanSearchJobPostWithOneCategoryWithDistanceAndAddressTest()
        {
            IEmployerDAO <Employer> EmployerDAO = new EmployerDAO(_connection);
            Employer testEmployer = new Employer();

            testEmployer.FirstName   = "Marcelo";
            testEmployer.LastName    = "Carvalho";
            testEmployer.UserName    = "******";
            testEmployer.Password    = "******";
            testEmployer.Email       = "*****@*****.**";
            testEmployer.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testEmployer.Address     = "Rua Eng. Luís Carneiro Leão, Figueiró";

            Employer returned = EmployerDAO.Create(testEmployer);

            IJobDAO jobPostDAO = new JobDAO(_connection);
            JobPost testPost   = new JobPost();

            testPost.Title         = "Canalização Estourada";
            testPost.Category      = Categories.PLUMBING;
            testPost.Description   = "Grande estouro nos canos da sanita";
            testPost.Tradable      = true;
            testPost.InitialPrice  = 60.6;
            testPost.Address       = "Rua de Salgueiros, Penafiel";
            testPost.PaymentMethod = new[] { Payment.PAYPAL, Payment.MONEY };

            JobPost testPost2 = new JobPost();

            testPost2.Title         = "Canalização Estourada";
            testPost2.Category      = Categories.PLUMBING;
            testPost2.Description   = "Grande estouro nos canos da sanita";
            testPost2.Tradable      = true;
            testPost2.InitialPrice  = 60.6;
            testPost2.Address       = "London";
            testPost2.PaymentMethod = new[] { Payment.PAYPAL, Payment.MONEY };

            jobPostDAO.Create(returned.Id, testPost);
            jobPostDAO.Create(returned.Id, testPost2);

            Categories[] categories = { Categories.PLUMBING };

            List <JobPostReturnedModel> jobPosts = jobPostDAO.GetJobs(categories, testEmployer.Address, 400, null, 1);

            JobPostReturnedModel[] jobPostsArray = jobPosts.ToArray();

            Assert.Equal("Canalização Estourada", jobPostsArray[0].Title);
            Assert.Equal(Categories.PLUMBING, jobPostsArray[0].Category);
            Assert.Equal("Grande estouro nos canos da sanita", jobPostsArray[0].Description);
            Assert.True(jobPostsArray[0].Tradable);
            Assert.Equal(60.6, jobPostsArray[0].InitialPrice);
            Assert.Equal("Rua de Salgueiros, Penafiel", jobPostsArray[0].Address);
            Assert.Single(jobPostsArray);

            _fixture.Dispose();
        }
Example #14
0
        public void CanIgnoreValidJobTest()
        {
            IEmployerDAO <Employer> EmployerDAO = new EmployerDAO(_connection);
            Employer testEmployer = new Employer();

            testEmployer.FirstName   = "Marcelo";
            testEmployer.LastName    = "Carvalho";
            testEmployer.UserName    = "******";
            testEmployer.Password    = "******";
            testEmployer.Email       = "*****@*****.**";
            testEmployer.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testEmployer.Address     = "Rua Eng. Luís Carneiro Leão, Nº 54 4590-244 Porto, Portugal";

            Employer returned = EmployerDAO.Create(testEmployer);

            IJobDAO jobPostDAO = new JobDAO(_connection);
            JobPost testPost   = new JobPost();

            testPost.Title         = "Canalização Estourada";
            testPost.Category      = Categories.PLUMBING;
            testPost.Description   = "Grande estouro nos canos da sanita";
            testPost.Tradable      = true;
            testPost.InitialPrice  = 60.6;
            testPost.Address       = "Rua de Salgueiros, Penafiel";
            testPost.PaymentMethod = new[] { Payment.PAYPAL, Payment.MONEY };

            JobPost jobReturned = jobPostDAO.Create(returned.Id, testPost);

            IMateDAO <Mate> MateDAO  = new MateDAO(_connection);
            Mate            testMate = new Mate();

            testMate.FirstName   = "Miguel";
            testMate.LastName    = "Dev";
            testMate.UserName    = "******";
            testMate.Password    = "******";
            testMate.Email       = "*****@*****.**";
            testMate.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testMate.Address     = "Rua de Salgueiros, Penafiel";
            testMate.Categories  = new[] { Categories.CLEANING, Categories.PLUMBING };
            testMate.Rank        = Ranks.SUPER_MATE;
            testMate.Range       = 20;

            Mate returnedMate = MateDAO.Create(testMate);

            IgnoredJobModel job = new IgnoredJobModel();

            job.Id = jobReturned.Id;

            Assert.True(MateDAO.IgnoreJobPost(returnedMate.Id, job));

            Categories[] categories = { Categories.PLUMBING };
            Assert.Empty(jobPostDAO.GetJobs(categories, testMate.Address, 400, null, returnedMate.Id));

            _fixture.Dispose();
        }
        public void CanUpdatePostDetailsTest()
        {
            IEmployerDAO <Employer> EmployerDAO = new EmployerDAO(_connection);
            Employer testEmployer = new Employer();

            testEmployer.FirstName   = "Marcelo";
            testEmployer.LastName    = "Carvalho";
            testEmployer.UserName    = "******";
            testEmployer.Password    = "******";
            testEmployer.Email       = "*****@*****.**";
            testEmployer.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testEmployer.Address     = "Lixa";

            Employer returned = EmployerDAO.Create(testEmployer);

            IJobDAO jobPostDAO = new JobDAO(_connection);
            JobPost testPost   = new JobPost();

            testPost.Title         = "Canalização Estourada";
            testPost.Category      = Categories.PLUMBING;
            testPost.ImagePath     = "path/image";
            testPost.Description   = "Grande estouro nos canos da sanita";
            testPost.Tradable      = true;
            testPost.InitialPrice  = 60.6;
            testPost.Address       = "Rua sem fim";
            testPost.PaymentMethod = new[] { Payment.PAYPAL, Payment.MONEY };

            JobPost jobReturned = jobPostDAO.Create(returned.Id, testPost);

            //Change variables from old post to new ones
            JobPost OldPost = jobReturned;

            OldPost.Id            = jobReturned.Id;
            OldPost.Title         = "Cadeira dificil de Montar";
            OldPost.Category      = Categories.FURNITURE_ASSEMBLE;
            OldPost.ImagePath     = "";
            OldPost.Description   = "Cadeira super complicada";
            OldPost.Tradable      = true;
            OldPost.InitialPrice  = 63.6;
            OldPost.Address       = "Rua com fim";
            OldPost.PaymentMethod = new[] { Payment.PAYPAL, Payment.MONEY };

            JobPost newPost = jobPostDAO.UpdatePostDetails(OldPost);


            Assert.Equal(OldPost.Title, newPost.Title);
            Assert.Equal(OldPost.Category, newPost.Category);
            Assert.Equal(OldPost.ImagePath, newPost.ImagePath);
            Assert.Equal(OldPost.Description, newPost.Description);
            Assert.Equal(OldPost.Tradable, newPost.Tradable);
            Assert.Equal(OldPost.InitialPrice, newPost.InitialPrice);
            Assert.Equal(OldPost.Address, newPost.Address);

            _fixture.Dispose();
        }
Example #16
0
        public ActionResult <JobPost> GetById(int id)
        {
            IJobDAO jobDAO = new JobDAO(_connection);
            JobPost Post   = jobDAO.FindById(id);

            if (Post == null)
            {
                return(NotFound(new ErrorMessageModel("Post não encontrado!")));
            }

            return(Ok(Post));
        }
Example #17
0
 public IActionResult getMainPicture(int post)
 {
     try
     {
         JobDAO    jobDAO = new JobDAO(_connection, this._environment.ContentRootPath);
         ImageName image  = jobDAO.getMainImage(post);
         return(Ok(image));
     }
     catch (Exception e)
     {
         return(BadRequest(new ErrorMessageModel(e.Message)));
     }
 }
Example #18
0
        public ActionResult <List <JobPostReturnedModel> > GetAllEmployerPosts()
        {
            int?employerID = ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)this.ControllerContext.HttpContext.User.Identity);

            if (employerID == null)
            {
                return(Unauthorized());
            }

            IJobDAO jobDAO = new JobDAO(_connection);
            List <JobPostReturnedModel> listPosts = _mapper.Map <List <JobPostReturnedModel> >(jobDAO.GetEmployerPosts((int)employerID));

            return(Ok(listPosts));
        }
Example #19
0
        public IActionResult RemovePayment(int jobId, PaymentModel payment)
        {
            IJobDAO jobDAO = new JobDAO(_connection);
            JobPost post   = jobDAO.FindById(jobId);

            if (post == null)
            {
                return(NotFound(new ErrorMessageModel("Post não encontrado!")));
            }

            jobDAO.RemovePayment(jobId, payment);

            return(Ok(new SuccessMessageModel("Apagado!")));
        }
Example #20
0
        public ActionResult <Payment> AddPayment(int jobId, PaymentModel[] payment)
        {
            IJobDAO jobDAO = new JobDAO(_connection);
            JobPost post   = jobDAO.FindById(jobId);

            if (post == null)
            {
                return(NotFound(new ErrorMessageModel("Post não encontrado!")));
            }

            jobDAO.AddPayment(jobId, payment);

            return(Ok(payment));
        }
Example #21
0
        public bool PostJob(JobDAO job)
        {
            JobServiceClient client = new JobServiceClient();

            try
            {
                bool result = client.CreateJob(job);
                return result;
            }
            catch (FaultException<KaskServiceException> e)
            {
                throw new HttpException(e.Message);
            }
        }
Example #22
0
        public void CanReturnJobPostsFromEmployerTest()
        {
            IEmployerDAO <Employer> EmployerDAO = new EmployerDAO(_connection);
            Employer testEmployer = new Employer();

            testEmployer.FirstName   = "Marcelo";
            testEmployer.LastName    = "Carvalho";
            testEmployer.UserName    = "******";
            testEmployer.Password    = "******";
            testEmployer.Email       = "*****@*****.**";
            testEmployer.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testEmployer.Address     = "Lixa";

            Employer returned = EmployerDAO.Create(testEmployer);

            IJobDAO jobPostDAO = new JobDAO(_connection);
            JobPost testPost   = new JobPost();

            testPost.Title         = "Canalização Estourada";
            testPost.Category      = Categories.PLUMBING;
            testPost.Description   = "Grande estouro nos canos da sanita";
            testPost.Tradable      = true;
            testPost.InitialPrice  = 60.6;
            testPost.Address       = "Rua sem fim";
            testPost.PaymentMethod = new[] { Payment.PAYPAL, Payment.MONEY };

            JobPost testPost2 = new JobPost();

            testPost2.Title         = "Cortar Relva";
            testPost2.Category      = Categories.GARDENING;
            testPost2.Description   = "Isto parece a amazonia!";
            testPost2.Tradable      = true;
            testPost2.InitialPrice  = 60.6;
            testPost2.Address       = "Rua sem fim";
            testPost2.PaymentMethod = new[] { Payment.PAYPAL, Payment.MONEY };

            jobPostDAO.Create(returned.Id, testPost);
            jobPostDAO.Create(returned.Id, testPost2);

            List <JobPost> returnedList = jobPostDAO.GetEmployerPosts(returned.Id);

            Assert.Equal(2, returnedList.Count);
            Assert.Equal(testPost.Id, returnedList.Find(a => a.Id == testPost.Id).Id);
            Assert.Equal(testPost2.Id, returnedList.Find(a => a.Id == testPost2.Id).Id);

            _fixture.Dispose();
        }
Example #23
0
        public static jobDTO mapToJobDTO(JobDAO b)
        {
            jobDTO a = new jobDTO();

            a.client            = Mapping.ClientMapper.MapToClientDTO(b.Client);
            a.ClientId          = b.ClientID;
            a.Complete          = b.Complete;
            a.EstimatedDuration = b.EstimatedDuration;
            a.Id            = b.Id;
            a.Notes         = b.Notes;
            a.ServiceTypeId = b.ServiceTypeID;
            a.StartDate     = b.StartDate;
            a.type          = Mapping.ServiceTypeMapper.MaptoServiceTypeDTO(b.ServiceType);
            a.user          = Mapping.AspNetUserMapper.mapToAspNetUsers(b.User);
            a.UserId        = b.UserID;
            a.Hours         = b.Hours;
            return(a);
        }
Example #24
0
        public static ScheduleJob MapToJob(JobDAO job)
        {
            var c = new ScheduleJob();

            c.Id            = job.Id;
            c.ServiceTypeID = job.ServiceType.Id;
            c.ServiceType   = ServiceTypeMapper.MapToServiceType(job.ServiceType);
            c.ClientID      = job.Client.Id;
            c.Client        = ClientMapper.MapToClient(job.Client);
            c.UserID        = job.User.Id;
            //c.AspNetUser = UserMapper.MapToUser(job.User);
            c.StartDate         = job.StartDate;
            c.EndDate           = job.EndDate;
            c.EstimatedDuration = job.EstimatedDuration;
            c.Notes             = job.Notes;
            c.Hours             = job.Hours;
            c.Complete          = job.Complete;

            return(c);
        }
        public void CanAddPaymentTypeTest()
        {
            IEmployerDAO <Employer> employerDAO = new EmployerDAO(_connection);
            Employer testEmployer = new Employer();

            testEmployer.FirstName   = "Ema";
            testEmployer.LastName    = "Coelho";
            testEmployer.UserName    = "******";
            testEmployer.Password    = "******";
            testEmployer.Email       = "*****@*****.**";
            testEmployer.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testEmployer.Address     = "Lousada";

            Employer returnedEmployer = employerDAO.Create(testEmployer);

            IJobDAO jobPostDAO = new JobDAO(_connection);
            JobPost testPost   = new JobPost();

            testPost.Title         = "Canalização Estourada";
            testPost.Category      = Categories.PLUMBING;
            testPost.ImagePath     = "path/image";
            testPost.Description   = "Grande estouro nos canos da sanita";
            testPost.Tradable      = true;
            testPost.InitialPrice  = 60.6;
            testPost.Address       = "Lousada";
            testPost.PaymentMethod = new[] { Payment.PAYPAL, Payment.MONEY };

            JobPost jobReturned = jobPostDAO.Create(returnedEmployer.Id, testPost);

            PaymentModel paymentModel = new PaymentModel();

            paymentModel.payments = Payment.MBWAY;
            PaymentModel[] payments = { paymentModel };

            jobPostDAO.AddPayment(jobReturned.Id, payments);
            JobPost post = jobPostDAO.FindById(jobReturned.Id);

            Assert.Contains(Payment.MBWAY, post.PaymentMethod);

            _fixture.Dispose();
        }
Example #26
0
        public ActionResult <JobPost> Create(JobPostModel model)
        {
            try
            {
                int?employerID = ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)this.ControllerContext.HttpContext.User.Identity);

                if (employerID == null)
                {
                    return(Unauthorized());
                }

                JobPost post       = _mapper.Map <JobPost>(model);
                IJobDAO JobPostDAO = new JobDAO(_connection);
                JobPost JobPosts   = JobPostDAO.Create((int)employerID, post);
                return(Ok(JobPosts));
            }
            catch (Exception ex)
            {
                return(BadRequest(new ErrorMessageModel(ex.Message)));
            }
        }
Example #27
0
        public void Test_insertJob()
        {
            var data   = new EfData();
            var client = data.GetClients().Where(c => c.Id == 4).FirstOrDefault();
            var user   = data.GetUsers().Where(c => c.Id == "60d9002e-667f-4794-a9dd-670c0ecf56c9").FirstOrDefault();
            var st     = data.GetTypes().Where(c => c.Id == 1).FirstOrDefault();

            var client2 = ClientMapper.MapToClientDAO(client);
            var user2   = UserMapper.MapToUserDAO(user);
            var st2     = ServiceTypeMapper.MapToServiceTypeDAO(st);

            var j = new JobDAO();

            j.Client      = client2;
            j.User        = user2;
            j.ServiceType = st2;

            var actual = AddJob(j);

            Assert.True(actual);
        }
Example #28
0
        public static JobDAO MapToJobDAO(ScheduleJob job)
        {
            var ef = new EfData();
            var c  = new JobDAO();

            c.Id                = job.Id;
            c.ServiceTypeID     = job.ServiceTypeID;
            c.ServiceType       = ServiceTypeMapper.MapToServiceTypeDAO(job.ServiceType);
            c.ClientID          = job.ClientID;
            c.Client            = ClientMapper.MapToClientDAO(job.Client);
            c.User              = UserMapper.MapToUserDAO(ef.GetUsers().Where(x => x.Id == job.UserID).FirstOrDefault());
            c.UserID            = job.UserID;
            c.StartDate         = job.StartDate;
            c.EndDate           = job.EndDate;
            c.EstimatedDuration = job.EstimatedDuration;
            c.Notes             = job.Notes;
            c.Hours             = job.Hours;
            c.Complete          = job.Complete;

            return(c);
        }
Example #29
0
        public ActionResult <SuccessMessageModel> Delete(int id)
        {
            int?employerID = ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)this.ControllerContext.HttpContext.User.Identity);

            if (employerID == null)
            {
                return(Unauthorized());
            }

            string  rootPath = this._environment.ContentRootPath;
            IJobDAO JobDAO   = new JobDAO(_connection, rootPath);
            JobPost toDel    = JobDAO.FindById(id);

            if (toDel == null)
            {
                return(NotFound(new ErrorMessageModel("Post não encontrado!")));
            }

            JobDAO.Delete(toDel);
            return(Ok(new SuccessMessageModel("Apagado!")));
        }
        public void CanCreateJobPostTest()
        {
            IEmployerDAO <Employer> EmployerDAO = new EmployerDAO(_connection);
            Employer testEmployer = new Employer();

            testEmployer.FirstName   = "Marcelo";
            testEmployer.LastName    = "Carvalho";
            testEmployer.UserName    = "******";
            testEmployer.Password    = "******";
            testEmployer.Email       = "*****@*****.**";
            testEmployer.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testEmployer.Address     = "Lixa";

            Employer returned = EmployerDAO.Create(testEmployer);

            IJobDAO jobPostDAO = new JobDAO(_connection);
            JobPost testPost   = new JobPost();

            testPost.Title         = "Canalização Estourada";
            testPost.Category      = Categories.PLUMBING;
            testPost.ImagePath     = "path/image";
            testPost.Description   = "Grande estouro nos canos da sanita";
            testPost.Tradable      = true;
            testPost.InitialPrice  = 60.6;
            testPost.Address       = "Rua sem fim";
            testPost.PaymentMethod = new[] { Payment.PAYPAL, Payment.MONEY };

            JobPost jobReturned = jobPostDAO.Create(returned.Id, testPost);

            Assert.Equal(testPost.Title, jobReturned.Title);
            Assert.Equal(testPost.Category, jobReturned.Category);
            Assert.Equal(testPost.ImagePath, jobReturned.ImagePath);
            Assert.Equal(testPost.Description, jobReturned.Description);
            Assert.Equal(testPost.Tradable, jobReturned.Tradable);
            Assert.Equal(testPost.InitialPrice, jobReturned.InitialPrice);
            Assert.Equal(testPost.Address, jobReturned.Address);
            Assert.Equal(testPost.PaymentMethod, jobReturned.PaymentMethod);

            _fixture.Dispose();
        }
Example #31
0
        public IActionResult Update(int id, JobPostModel model)
        {
            try
            {
                int?employerID = ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)this.ControllerContext.HttpContext.User.Identity);

                if (employerID == null)
                {
                    return(Unauthorized());
                }

                IJobDAO JobPostDAO = new JobDAO(_connection);
                JobPost oldPost    = JobPostDAO.FindById(id, (int)employerID);

                if (oldPost == null)
                {
                    return(NotFound(new ErrorMessageModel("Post não encontrado!")));
                }

                JobPost newPost = _mapper.Map <JobPost>(model);

                oldPost.Title         = newPost.Title;
                oldPost.Category      = newPost.Category;
                oldPost.ImagePath     = newPost.ImagePath;
                oldPost.Description   = newPost.Description;
                oldPost.Tradable      = newPost.Tradable;
                oldPost.InitialPrice  = newPost.InitialPrice;
                oldPost.Address       = newPost.Address;
                oldPost.PaymentMethod = newPost.PaymentMethod;

                JobPost updatedPost = JobPostDAO.UpdatePostDetails(oldPost);

                return(Ok(updatedPost));
            }
            catch (Exception ex)
            {
                return(BadRequest(new ErrorMessageModel(ex.Message)));
            }
        }
Example #32
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                if (!string.IsNullOrEmpty(Request.Form["title"]))
                {
                    // save application form data back to database through service
                    using (HttpClient httpClient = new HttpClient())
                    {
                        httpClient.BaseAddress = new Uri("http://localhost:51309");
                        httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                        HttpResponseMessage result = new HttpResponseMessage();
                        string resultContent = "";

                        // gather JobOpening form data
                        JobDAO job = new JobDAO();
                        //jobOpening.OpenDate = Convert.ToDateTime(Request.Form["OpenDate"]);
                        job.Title = Request.Form["title"];

                        // post (save) JobOpening data
                        result = httpClient.PostAsJsonAsync(ServiceURIs.ServiceJobUri, job).Result;
                        resultContent = result.Content.ReadAsStringAsync().Result;
                    }

                    return RedirectToAction("Index", "Jobs");
                }
                else
                {
                    // TODO: validation later on...
                    return RedirectToAction("Create");
                }
            }
            catch
            {
                // TODO: validation later on...
                return RedirectToAction("Create");
            }
        }