コード例 #1
0
        public async Task <IActionResult> AddWorkOrder([FromBody] NewWorkOrderViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(StatusCode(400, ModelState));
                }

                var result = await _service.AddProjectWorkOrder(workOrderId : model.WorkOrderId,
                                                                projectId : model.ProjectId);

                if (!result)
                {
                    return(StatusCode(400, new { Message = $"Unable to add new WorkOrder: {model.WorkOrderId} to Project: {model.ProjectId}", Status = 400 }));
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                _logger.LogError(ex.StackTrace);

                return(StatusCode(500));
            }
        }
コード例 #2
0
 public ActionResult New()
 {
     using (var context = new WorkOrderContext()) {
         var crews      = context.Crews.OrderBy(c => c.Name).ToList();
         var categories = context.WorkOrderCategories.OrderBy(c => c.Name).ToList();
         var durations  = new string[] { "", "1h", "2h", "4h", "1d", "2d", "3d", "4d", "5d" };
         var viewModel  = new NewWorkOrderViewModel {
             Title      = "New Work Order",
             Date       = DateTime.Today.ToString("dd-MMM-yyyy"),
             Crews      = crews,
             Durations  = durations,
             Categories = categories
         };
         return(View(viewModel));
     }
 }