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))); } }
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 static void doLogOut() { if (Program.CurrentUserID != null) { Program.EndWorkTime = DateTime.Now; WorkDTO workDTO = new WorkDTO(); workDTO.UserID = Program.CurrentUserID; workDTO.TimeStart = Program.StartWorkTime; workDTO.TimeEnd = Program.EndWorkTime; workDTO.Computer = Environment.MachineName; WorkDAO.Insert(workDTO); } }
public ActionResult MarkJobAsDone(int Id) { try { int userId = (int)Helpers.ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)this.ControllerContext.HttpContext.User.Identity); WorkDAO workDAO = new WorkDAO(_connection); bool result = workDAO.MarkJobAsDone(Id, userId); return(Ok(new SuccessMessageModel("Result: " + result))); } catch (Exception ex) { return(UnprocessableEntity(new ErrorMessageModel(ex.Message))); } }
public WorkPage() { InitializeComponent(); connection = new ConnectionFactory(SqlServerConfiguration.Settings).GetConnection(typeof(SqlServerConnection)); itemDAO = new DAOFactory(connection).GetConnection(typeof(WorkDAO)) as WorkDAO; observer = new Observer(GetAll_Click); itemDAO.AddObserver(observer); Loaded += Page_Load; Get_.Click += Get_Click; GetAll.Click += GetAll_Click; Add.Click += Add_Click; Update.Click += Update_Click; Delete.Click += Delete_Click; }
public object GetConnection(Type type) { if (type == typeof(AuthorDAO)) { return(AuthorDAO.GetInstance(connection)); } else if (type == typeof(WorkDAO)) { return(WorkDAO.GetInstance(connection)); } else if (type == typeof(GenreDAO)) { return(GenreDAO.GetInstance(connection)); } return(null); }
private void searchWork() { if (radioButtonWorkDate.Checked) { DateTime startDate = dateTimePickerWorkAssignDate.Value.Date; startDate = new DateTime(startDate.Year, startDate.Month, startDate.Day, 0, 0, 0); DateTime endDate = dateTimePickerWorkAssignDate.Value.Date; endDate = new DateTime(endDate.Year, endDate.Month, endDate.Day, 23, 59, 59); dgvWorkList.DataSource = WorkDAO.GetDataByMultiDate(startDate, endDate); } else if (radioButtonWorkMultiDate.Checked) { DateTime startDate = dateTimePickerWorkAssignStartDate.Value.Date; startDate = new DateTime(startDate.Year, startDate.Month, startDate.Day, 0, 0, 0); DateTime endDate = dateTimePickerWorkAssignEndDate.Value.Date; endDate = new DateTime(endDate.Year, endDate.Month, endDate.Day, 23, 59, 59); dgvWorkList.DataSource = WorkDAO.GetDataByMultiDate(startDate, endDate); } }
public ActionResult <WorkModel> Create(WorkModel work) { int?employerId = ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)this.ControllerContext.HttpContext.User.Identity); if (employerId == null) { return(Unauthorized(new ErrorMessageModel("Utilizador não existe!"))); } IWorkDAO WorkDao = new WorkDAO(_connection); Job JobModel = _mapper.Map <Job>(work); WorkModel result = _mapper.Map <WorkModel>(WorkDao.Create((int)employerId, JobModel)); if (result == null) { return(BadRequest(new ErrorMessageModel("Mate ou Post não encontrados!"))); } return(Ok(result)); }
public void ReturnExceptionWhenJobIDisInvalidOnMarkJobAsDoneTest() { 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); IWorkDAO workDAO = new WorkDAO(_connection); Assert.Throws <Exception>(() => workDAO.MarkJobAsDone(1000, returnedEmp.Id)); Assert.Throws <Exception>(() => workDAO.MarkJobAsDone(1000, returned.Id)); _fixture.Dispose(); }
public void ReturnFalseWhenDeleteNonExistentWorkTest() { 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); Assert.False(workDAO.Delete(999)); _fixture.Dispose(); }
private void loadWorkList() { dgvWorkList.DataSource = WorkDAO.GetAllData(); }
public void CanMakePaymentPayPalTest() { IMateDAO <Mate> MateDAO = new MateDAO(_connection); Mate testMate = new Mate { FirstName = "Miguel", LastName = "Dev", UserName = "******", Password = "******", Email = "*****@*****.**", Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.", Address = "Figueiró", Categories = new[] { Categories.CLEANING, Categories.PLUMBING }, Rank = Ranks.SUPER_MATE, Range = 20 }; Mate returned = MateDAO.Create(testMate); IEmployerDAO <Employer> EmployerDAO = new EmployerDAO(_connection); Employer testEmployer = new Employer { FirstName = "Marcelo", LastName = "Carvalho", UserName = "******", Password = "******", Email = "*****@*****.**", Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.", Address = "Lixa" }; Employer returnedEmp = EmployerDAO.Create(testEmployer); IJobDAO jobPostDAO = new JobDAO(_connection); JobPost testPost = new JobPost { Title = "Canalização Estourada", Category = Categories.PLUMBING, ImagePath = "path/image", Description = "Grande estouro nos canos da sanita", Tradable = false, InitialPrice = 60.6, Address = "Rua sem fim", PaymentMethod = new[] { Payment.PAYPAL, Payment.MONEY } }; JobPost jobReturned = jobPostDAO.Create(returnedEmp.Id, testPost); DateTime date = new DateTime(2020, 01, 16); Job job = new Job { Date = date, Mate = returned.Id, JobPost = jobReturned.Id, FinishedConfirmedByEmployer = false, FinishedConfirmedByMate = false, Employer = returnedEmp.Id }; IWorkDAO workDAO = new WorkDAO(_connection); Job returnedJob = workDAO.Create(returnedEmp.Id, job); workDAO.MarkJobAsDone(returnedJob.Id, returnedEmp.Id); workDAO.MarkJobAsDone(returnedJob.Id, returned.Id); Invoice invoice = new Invoice { Value = 60.6, PaymentType = Payment.PAYPAL }; string email = "*****@*****.**"; string paypalLink = String.Format("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&amount={0}¤cy_code=EUR&business={1}&item_name={2}&return=Page", testPost.InitialPrice, email, testPost.Title); PaymentDAO paymentDAO = new PaymentDAO(_connection); Invoice result = paymentDAO.makePayment(invoice, returnedJob.Id, returnedEmp.Id); Assert.Equal(invoice.Value, result.Value); Assert.Equal(invoice.PaymentType, result.PaymentType); Assert.False(result.ConfirmedPayment); Assert.Equal(paypalLink, result.Link); _fixture.Dispose(); }