public ActionResult CreateWorkItem(AddWorkItem addWorkItem)
        {
            var workItem = new WorkItem(addWorkItem);

            _workItemService.InsertWorkItem(workItem);
            return(RedirectToAction("Index", "Home"));
        }
コード例 #2
0
ファイル: WorkItemService.cs プロジェクト: mhear22/NetCoreAPI
        public string AddItem(AddWorkItem model)
        {
            if (model.ServiceTypeId == null)
            {
                throw new ArgumentException("Service Type is required");
            }

            var car = Context.OwnedCars
                      .Include(x => x.ServiceReminders)
                      .FirstOrDefault(x => x.Vin == model.Vin);

            var Item = car.ServiceReminders.FirstOrDefault(x => x.ServiceTypeId == model.ServiceTypeId);

            if (Item == null)
            {
                Item = new ServiceReminderDto()
                {
                    OwnedCarId    = car.Id,
                    Id            = Guid.NewGuid().ToString(),
                    ServiceTypeId = model.ServiceTypeId
                };
                Context.ServiceReminders.Add(Item);
                Context.SaveChanges();
            }

            var receipt = new ServiceReceiptDto()
            {
                CurrentMiles      = mileageService.EstimateCurrent(car.Vin),
                Id                = Guid.NewGuid().ToString(),
                CreatedDate       = DateTime.UtcNow,
                ServiceReminderId = Item.Id
            };

            Context.ServiceReceipts.Add(receipt);
            Context.SaveChanges();
            return(Item.Id);
        }
コード例 #3
0
 public IActionResult CreateWorkItem([FromBody] AddWorkItem item) =>
 ReturnResult(() => this.workItemService.AddItem(item));