public async Task <IActionResult> Create(WorkType workType, [Bind("WorkId,QuoteId,EndlasNumber,WorkDescription,Status,PurchaseOrderNum,NumWorkItems,DueDate,StartDate,PoDate,CompleteDate,UserId,CustomerId,SystemConfigurationPdfFile")] Work work)
        {
            ViewBag.WorkType = workType;
            var vm       = new WorkViewModel();
            var workList = await _repo.GetWorkWithEndlasNumber(work.EndlasNumber);

            var quotes = await _repo.GetQuotesWithEndlasNumber(work.EndlasNumber);

            if (workList.Any() || quotes.Count() > 1)
            {
                ViewBag.EndlasNumberConflict = true;
                ViewData["CustomerId"]       = new SelectList(await _repo.GetAllCustomers(), "CustomerId", "CustomerName");
                return(View(work));
            }
            if (ModelState.IsValid)
            {
                if (work.QuoteId == null && workType == WorkType.Job)
                {
                    ViewBag.NoQuoteWarning = true;
                    return(View(work));
                }
                work.WorkId = Guid.NewGuid();

                if (work.SystemConfigurationPdfFile != null)
                {
                    work.SystemConfigurationPdfBytes = await FileURL.GetFileBytes(work.SystemConfigurationPdfFile);
                }
                SetUIDs();

                if (workType == WorkType.Job)
                {
                    var quote = await _repo.GetQuote((Guid)work.QuoteId);

                    work.EndlasNumber = quote.EndlasNumber;
                    await _repo.AddJob(Job.CastWorkToJob(work));
                }
                else if (workType == WorkType.WorkOrder)
                {
                    await _repo.AddWorkOrder(WorkOrder.CastWorkToWorkOrder(work));
                }

                for (int i = 0; i < work.NumWorkItems; i++)
                {
                    WorkItem workItem = new WorkItem {
                        WorkItemId = Guid.NewGuid(), WorkId = work.WorkId
                    };
                    await _repo.AddWorkItem(workItem);
                }
                return(RedirectToAction(nameof(Index), new { workType = workType }));
            }
            await SetViewData();

            vm = new WorkViewModel(work, workType);
            return(View(vm));
        }