Example #1
0
        public ActionResult <SuccessMessageModel> Reschedule(int id, DateModel date)
        {
            try{
                int?employerId = ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)this.ControllerContext.HttpContext.User.Identity);

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

                WorkDAO          workDao = new WorkDAO(_connection);
                WorkDetailsModel work    = workDao.FindById(id, (int)employerId);

                if (work == null)
                {
                    return(BadRequest(new ErrorMessageModel("O trabalho não existe ou não está associado ao Employer!")));
                }

                bool updated = workDao.updateDate(id, date);

                if (updated)
                {
                    return(Ok(new SuccessMessageModel("Data atualizada com sucesso!")));
                }
                else
                {
                    return(BadRequest(new ErrorMessageModel("Erro! A data não foi atualizada!")));
                }
            } catch (Exception e) {
                return(BadRequest(new ErrorMessageModel(e.Message)));
            }
        }
Example #2
0
        public ActionResult <WorkDetailsModel> FindById(int id)
        {
            WorkDAO          workDao = new WorkDAO(_connection);
            WorkDetailsModel work    = workDao.FindById(id);

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

            return(Ok(work));
        }
        public void CanFindWorkByIdTest()
        {
            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 returned = MateDAO.Create(testMate);

            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 returnedEmp = 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(returnedEmp.Id, testPost);
            DateTime date        = new DateTime(2020, 01, 16);
            Job      job         = new Job();

            job.Date    = date;
            job.Mate    = returned.Id;
            job.JobPost = jobReturned.Id;
            job.FinishedConfirmedByEmployer = false;
            job.FinishedConfirmedByMate     = false;
            job.Employer = returnedEmp.Id;

            IWorkDAO         workDAO = new WorkDAO(_connection);
            Job              created = workDAO.Create(returnedEmp.Id, job);
            WorkDetailsModel found   = workDAO.FindById(created.Id);

            Assert.Equal(created.Date, found.Date);
            Assert.Equal(created.Mate, found.Mate.Id);
            Assert.Equal(created.JobPost, found.JobPost.Id);
            Assert.Equal(created.FinishedConfirmedByEmployer, found.FinishedConfirmedByEmployer);
            Assert.Equal(created.FinishedConfirmedByMate, found.FinishedConfirmedByMate);
            Assert.Equal(created.Employer, found.Employer.Id);

            _fixture.Dispose();
        }