public async Task <RxJob> UpdateAsync(RxJob job) { _context.Update(job); await _context.SaveChangesAsync(); return(job); }
public static void UpdateJobStatus(RxJob job, string jobStatus) { if (job != null && GlobalObject.MapJobStatus.ContainsKey(jobStatus)) { job.StatusNum = GlobalObject.MapJobStatus[jobStatus]; job.Status = jobStatus; } }
public async Task <RxJob> AddAsync(RxJob job) { await _context.RxJob.AddAsync(job); await _context.SaveChangesAsync(); return(job); }
private void MapFromEntity(RxJob entity) { Id = entity.Id; Name = entity.Name; Floor = entity.Floor; Status = entity.Status; RoomName = entity.RoomType.Name; }
public JsonResult Complete(Guid id) { try { RxJob job = db.RxJobs.FirstOrDefault(val => val.Id == id); if (job == null) { return(Json(new { Success = false, Error = "Not found!" })); } //assume it should be a refbook the same as RoomTypes with parameters CanComplete and Completed for optimizing querying and code readability //but it is also out of scope of the test task //I wouldn't recomment to use this approach Dictionary <int, string> statuses = new Dictionary <int, string>() { { 1, "Complete" }, { 2, "Not Started" }, { 3, "In Progress" }, { 4, "Delayed" } }; int completedStatusId = 1; int[] canCompleteStatuses = new int[] { 3, 4 }; if (!job.StatusNum.HasValue || !canCompleteStatuses.Contains(job.StatusNum.Value)) { return(Json(new { Success = false, Error = "Not allowed!" })); } job.StatusNum = completedStatusId; job.Status = statuses[completedStatusId]; db.SaveChanges(); return(Json(new { Success = true, Job = job })); } catch (Exception ex) { //Log exception here logger.LogError(ex, "Exception in Jobs/Complete"); //Send more details about exception if necessary return(Json(new { Success = false, Error = "Unexpected exception!" })); } }
public void MarkJobAsCompleted() { string completedStatus = "Complete"; var jobInProgress = new RxJob() { Status = "In Progress" }; var jobNotStarted = new RxJob() { Status = "Not Started" }; jobInProgress.MarkAsCompleted(); jobNotStarted.MarkAsCompleted(); Assert.AreEqual(jobInProgress.Status, completedStatus); Assert.AreNotEqual(jobNotStarted.Status, completedStatus); }
public async void CompleteCompletedJobError() { ILogger <JobsController> logger = Mock.Of <ILogger <JobsController> >(); JobsController controller = new JobsController(context, logger); RxJob job = await context.RxJobs.FirstOrDefaultAsync(val => val.StatusNum == 1); // Act JsonResult result = controller.Complete(job.Id) as JsonResult; // Assert Assert.NotNull(result); Assert.NotNull(result.Value); JObject response = JObject.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(result.Value)); Assert.False(response.Value <bool>("Success")); }
public JobViewModel(RxJob entity) { MapFromEntity(entity); }
public void UpdateJobStatus_Should_UpdateJobStatus(RxJob job, string jobStatus, int expectedStatus) { RxJobHelpers.UpdateJobStatus(job, jobStatus); Assert.True(job.StatusNum == expectedStatus); }