public ResultViewModel <JobEditViewModel> Post(JobEditViewModel model) { ResultViewModel <JobEditViewModel> result = new ResultViewModel <JobEditViewModel>(); try { if (!ModelState.IsValid) { result.Message = "In Valid Model State"; } else { JobEditViewModel selectedUser = JobService.Add(model); result.Successed = true; result.Data = selectedUser; } } catch (Exception ex) { result.Successed = false; result.Message = "حدث خطأ ما"; } return(result); }
public IActionResult Create(JobViewModel model) { if (!ModelState.IsValid) { return(View(model)); } _service.Add(model); return(RedirectToAction("Index")); }
public async Task <ActionResult> Post([FromBody] Job model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _jobService.Add(model); return(Ok()); }
// GET: Job public ActionResult Add(JobModel item) { if (ModelState.IsValid) { JobService.Add(item); } else { return(View(item)); } return(RedirectToAction("index")); }
public async Task GetAllJobs_ExistingJobs_NoError() { // Arrange DbContextOptions <YellowJacketContext> options = new DbContextOptionsBuilder <YellowJacketContext>() .UseInMemoryDatabase("GetAllJob_ExistingJobs_NoError") .Options; List <JobModel> expectedJobs = new List <JobModel> { new JobModel { Name = "JobA" }, new JobModel { Name = "JobB" } }; using (YellowJacketContext context = new YellowJacketContext(options)) { IJobRepository jobRepository = new JobRepository(context); IJobService service = new JobService(jobRepository, GetMapper()); foreach (JobModel model in expectedJobs) { await service.Add(model); } context.SaveChanges(); } List <JobModel> actualJobs; // Act using (YellowJacketContext context = new YellowJacketContext(options)) { IJobRepository jobRepository = new JobRepository(context); IJobService service = new JobService(jobRepository, GetMapper()); actualJobs = await service.GetAll(); } Assert.That( actualJobs.Count, Is.EqualTo(2), $"The actual job list count {actualJobs.Count} should be equal to the expected one {expectedJobs.Count}"); }
public async Task AddJob_ValidJob_NoError() { // Arrange DbContextOptions <YellowJacketContext> options = new DbContextOptionsBuilder <YellowJacketContext>() .UseInMemoryDatabase("AddJob_ValidJob_NoError") .Options; const string jobName = "MyJob"; JobModel model = new JobModel { Name = jobName, Features = new List <string>(), PackageName = "MyPackage.zip", }; // Act using (YellowJacketContext context = new YellowJacketContext(options)) { IJobRepository jobRepository = new JobRepository(context); IJobService service = new JobService(jobRepository, GetMapper()); await service.Add(model); } // Assert using (YellowJacketContext context = new YellowJacketContext(options)) { const int expectedCount = 1; Assert.That( expectedCount, Is.EqualTo(Convert.ToInt32(context.Jobs.Count())), $"The job count should be {expectedCount}."); Assert.That( jobName, Is.EqualTo(context.Jobs.Single().Name), $"The expected job name {jobName} doesn't match the actual value {context.Jobs.Single().Name}"); } }
private async Task Save() { if (SelectedChores != null) { JobModel.Chores = Chores?.Where(pieceofwork => SelectedChores.Contains(pieceofwork.Id)).ToList(); } else { JobModel.Chores = null; } JobModel.EmployeeId = Employees?.SingleOrDefault(employee => employee.Id.Equals(EmployeeId))?.Id; if (Id != 0) { await JobService.Update(JobModel); } else { await JobService.Add(JobModel); } NavigationService.Previous(); }
public HttpResponseMessage AddJob([FromBody] JobDto jobDto) { return(HandleRequestSafely(() => { IEnumerable <string> tokenValues = new List <string>(); Request.Headers.TryGetValues(Settings.TokenKey, out tokenValues); var user = _userService.GetUserByEmail(JwtManager.GetEmailFromToken(tokenValues.First())); if (user.UserType != UserType.Provider) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Only providers can create jobs"); } var job = new JobFactory().GetJobFromDto(jobDto); job.Owner = user; job.Asignee = null; if (jobDto.Skills != null) { job.RequiredSkills = jobDto.Skills.Select(skill => _skillService.GetSkillByName(skill)).ToList(); } _jobService.Add(job); return Request.CreateResponse(HttpStatusCode.OK); })); }
public static void GetPublishedJobTable_All() { DateTime excelLastTime = DateTime.MinValue; object obj = SQLiteDbHelper.ExecuteScalar("select max([Excel时间]) from job"); DataTable excelTable = SQLiteDbHelper.ExecuteDataTable("select Excel文件 from job group by excel文件"); if (obj != null) { DateTime.TryParse(obj.ToString(), out excelLastTime); } //检索Excel文件 FileInfo[] files = new DirectoryInfo(@"\\128.1.30.112\Downloads").GetFiles("*.xls"); foreach (FileInfo file in files) { //删除超过日期的信息 if (file.LastWriteTime < excelLastTime) { continue; } //判断Excel文件名是否存在 string excelFileName = Path.GetFileNameWithoutExtension(file.FullName); DataRow[] rows = excelTable.Select("[Excel文件]='" + excelFileName + "'"); //如果不存在,则添加 if (rows == null || rows.Length == 0) { //读取Excel里面的作业信息,并返回一个DataTable DataTable dt_excel = GetPublishDataTableFromExcelFile(file.FullName); if (dt_excel != null) { //添加 JobService.Add(dt_excel); } } } }