예제 #1
0
        public async Task <IActionResult> AssignTask(AvailableTechniciansForRepairTaskViewModel availableTechniciansForRepairTaskViewModel, int id)
        {
            if (ModelState.IsValid == false)
            {
                availableTechniciansForRepairTaskViewModel.AvailableTechnicinsName = this.technicianService
                                                                                     .GetAllAvailableTechnicians()
                                                                                     .GetAwaiter()
                                                                                     .GetResult()
                                                                                     .Select(technician => technician.UserName)
                                                                                     .ToArray();
                return(this.View(availableTechniciansForRepairTaskViewModel));
            }

            RepairTask repairTask = this.repairTaskService.GetById(id);
            RepairTaskSimpleInfoViewModel repairTaskSimpleInfo = this.mapper.Map <RepairTaskSimpleInfoViewModel>(repairTask);

            this.partService.AllPartsForRepairTaskAreAvailable(repairTaskSimpleInfo);
            if (repairTaskSimpleInfo.CanBeAssigned == false || repairTask.Status != Models.Enums.Status.Pending)
            {
                TempData[StringConstants.TempDataKeyHoldingGenericErrorsForRepairTaskController] = StringConstants.RepairTaskGenericAssignmentFailure;
                return(this.RedirectToAction(StringConstants.ActionNameIndex, StringConstants.HomeControllerName));
            }
            await this.technicianService.AddTechniciansToRepairTaskAsync(availableTechniciansForRepairTaskViewModel.SelectedTechnicians,
                                                                         id);

            return(this.RedirectToAction(StringConstants.ActionNameRepairTaskDetails, new { id }));
        }
예제 #2
0
        public void AllPartsForRepairTaskAreAvailable(RepairTaskSimpleInfoViewModel repairTaskSimpleInfoViewModel)
        {
            bool repairTaskCanBeAssgned = true;

            foreach (Part requiredPart in repairTaskSimpleInfoViewModel.PartsRequired)
            {
                int orderedPartsOfType = this.dbContext
                                         .Orders
                                         .SelectMany(order => order.OrderedParts)
                                         .Where(part => part.Type == requiredPart.Type)
                                         .Sum(filteredParts => filteredParts.Quantity);
                int usedPartsOfType = this.dbContext
                                      .RepairTasks
                                      .Where(repairTask => repairTask.Status != Status.Pending)
                                      .SelectMany(filteredRepairTasks => filteredRepairTasks.PartsRequired)
                                      .Where(part => part.Type == PartType.CarBody)
                                      .Sum(filteredParts => filteredParts.Quantity);

                int totalAvailablePartsOfType = orderedPartsOfType - usedPartsOfType;
                if (requiredPart.Quantity > totalAvailablePartsOfType)
                {
                    repairTaskCanBeAssgned = false;
                    repairTaskSimpleInfoViewModel
                    .PartsMissingMeesage
                    .Add(String.Format(StringConstants.NotEnoughPartsAvailable, requiredPart.Type, requiredPart.Quantity - totalAvailablePartsOfType));
                }
                repairTaskSimpleInfoViewModel.CanBeAssigned = repairTaskCanBeAssgned;
            }
        }
예제 #3
0
        public void ReturnsTrueIfAllRequiredPartsAreAvailable()
        {
            Order order = new Order {
                OrderedParts = new Part[] {
                    new Part {
                        Type = PartType.CarBody, Quantity = 10
                    },
                    new Part {
                        Type = PartType.Chassis, Quantity = 10
                    },
                    new Part {
                        Type = PartType.Electronic, Quantity = 10
                    },
                    new Part {
                        Type = PartType.Interior, Quantity = 10
                    }
                }
            };

            this.dbContext.Orders.Add(order);
            this.dbContext.SaveChanges();
            RepairTaskSimpleInfoViewModel repairTaskSimpleInfoViewModel = new RepairTaskSimpleInfoViewModel {
                PartsRequired = new Part[] {
                    new Part {
                        Type = PartType.CarBody, Quantity = 5
                    },
                    new Part {
                        Type = PartType.Chassis, Quantity = 5
                    },
                    new Part {
                        Type = PartType.Electronic, Quantity = 5
                    },
                    new Part {
                        Type = PartType.Interior, Quantity = 5
                    }
                }
            };

            this.PartService.AllPartsForRepairTaskAreAvailable(repairTaskSimpleInfoViewModel);
            Assert.True(repairTaskSimpleInfoViewModel.CanBeAssigned);
        }
예제 #4
0
        public void ReturnsFalseIfNotAllRequiredPartsAreAvailable()
        {
            Part[] parts =
            {
                new Part {
                    Type = PartType.CarBody, Quantity = 10
                },
                new Part {
                    Type = PartType.Chassis, Quantity = 10
                },
                new Part {
                    Type = PartType.Electronic, Quantity = 10
                },
                new Part {
                    Type = PartType.Interior, Quantity = 10
                }
            };
            this.dbContext.Parts.AddRange(parts);
            this.dbContext.SaveChanges();
            RepairTaskSimpleInfoViewModel repairTaskSimpleInfoViewModel = new RepairTaskSimpleInfoViewModel {
                PartsRequired = new Part[] {
                    new Part {
                        Type = PartType.CarBody, Quantity = 11
                    },
                    new Part {
                        Type = PartType.Chassis, Quantity = 5
                    },
                    new Part {
                        Type = PartType.Electronic, Quantity = 5
                    },
                    new Part {
                        Type = PartType.Interior, Quantity = 5
                    }
                }
            };

            this.PartService.AllPartsForRepairTaskAreAvailable(repairTaskSimpleInfoViewModel);
            Assert.False(repairTaskSimpleInfoViewModel.CanBeAssigned);
        }
예제 #5
0
        public IActionResult AssignTask(int id)
        {
            RepairTask repairTask = this.repairTaskService.GetById(id);
            RepairTaskSimpleInfoViewModel repairTaskSimpleInfo = this.mapper.Map <RepairTaskSimpleInfoViewModel>(repairTask);

            this.partService.AllPartsForRepairTaskAreAvailable(repairTaskSimpleInfo);
            if (repairTaskSimpleInfo.CanBeAssigned == false || repairTask.Status != Models.Enums.Status.Pending)
            {
                TempData[StringConstants.TempDataKeyHoldingGenericErrorsForRepairTaskController] = StringConstants.RepairTaskGenericAssignmentFailure;
                return(this.RedirectToAction(StringConstants.ActionNameIndex, StringConstants.HomeControllerName));
            }
            AvailableTechniciansForRepairTaskViewModel availableTechnicians = new AvailableTechniciansForRepairTaskViewModel {
                TaskId = id,
                AvailableTechnicinsName = this.technicianService
                                          .GetAllAvailableTechnicians()
                                          .GetAwaiter()
                                          .GetResult()
                                          .Select(technician => technician.UserName)
                                          .ToArray()
            };

            return(this.View(availableTechnicians));
        }