コード例 #1
0
        public async Task <IActionResult> CreateRepairTask(RepairTaskInputModel repairTaskInputModel)
        {
            if (ModelState.IsValid == false)
            {
                return(this.View(repairTaskInputModel));
            }
            if (repairTaskInputModel.IsCarBodyPart == false &&
                repairTaskInputModel.IsChassisPart == false &&
                repairTaskInputModel.IsElectronicPart == false &&
                repairTaskInputModel.IsInteriorPart == false)
            {
                ModelState.AddModelError("", StringConstants.WrongRepairTask);
                return(this.View(repairTaskInputModel));
            }
            User user = await this.userManager.FindByNameAsync(this.User.Identity.Name);

            int repairTaskId = await this.repairTaskService.CreateRepairTaskAsync(repairTaskInputModel, user);

            return(this.RedirectToAction("repair-task-details", new { id = repairTaskId })); //TODO: Redirect to a detailed view of the order.
        } /*TODO: Check if all types of parts exists
コード例 #2
0
ファイル: RepairTaskService.cs プロジェクト: drumenov/Project
        public async Task <int> CreateRepairTaskAsync(RepairTaskInputModel repairTaskInputModel, User user)
        {
            RepairTask repairTask = new RepairTask {
                Status = Status.Pending,
                User   = user
            };

            if (repairTaskInputModel.IsCarBodyPart)
            {
                if (this.partService.PartTypeExists(PartType.CarBody) == false)
                {
                    throw new ArgumentNullException();
                }
                Part part = new Part {
                    Quantity = repairTaskInputModel.CarBodyPartAmount,
                    Type     = PartType.CarBody
                };
                repairTask.PartsRequired.Add(part);
            }
            if (repairTaskInputModel.IsChassisPart)
            {
                if (this.partService.PartTypeExists(PartType.Chassis) == false)
                {
                    throw new ArgumentNullException();
                }
                Part part = new Part {
                    Type     = PartType.Chassis,
                    Quantity = repairTaskInputModel.ChassisPartAmount
                };
                repairTask.PartsRequired.Add(part);
            }
            if (repairTaskInputModel.IsElectronicPart)
            {
                if (this.partService.PartTypeExists(PartType.Electronic) == false)
                {
                    throw new ArgumentNullException();
                }
                Part part = new Part {
                    Type     = PartType.Electronic,
                    Quantity = repairTaskInputModel.ElectronicPartAmount
                };
                repairTask.PartsRequired.Add(part);
            }
            if (repairTaskInputModel.IsInteriorPart)
            {
                if (this.partService.PartTypeExists(PartType.Interior) == false)
                {
                    throw new ArgumentNullException();
                }
                Part part = new Part {
                    Type     = PartType.Interior,
                    Quantity = repairTaskInputModel.InteriorPartAmount
                };
                repairTask.PartsRequired.Add(part);
            }
            this.dbContext.RepairTasks.Add(repairTask);
            if (await this.dbContext.SaveChangesAsync() == 0)
            {
                throw new ApplicationException();
            }
            return(repairTask.Id);
        }