Beispiel #1
0
        public async Task <HttpStatusCode> UpdateWorkOrder(int userId, WorkOrder workOrder)
        {
            var statusCode = await _workOrderDL.GetWorkOrderStatusCode(workOrder.Id);

            var result = await _workOrderDL.UpdateWorkOrder(workOrder);

            // only log status change if the status actually changes
            // e.g. :the work order can be updated without changes to the status


            if (workOrder.Status.Id != statusCode)
            {
                var log = new WorkOrderStatusLog()
                {
                    WorkOrderId = workOrder.Id,
                    UserId      = userId,
                    StatusId    = workOrder.Status.Id
                };

                var logResult = await _workOrderDL.LogStatusChange(log);

                if (logResult == HttpStatusCode.BadRequest)
                {
                    return(HttpStatusCode.BadRequest);
                }
            }

            return(result);
        }
        public async Task <HttpStatusCode> LogStatusChange(WorkOrderStatusLog log)
        {
            HttpStatusCode httpStatus = HttpStatusCode.BadRequest;

            using (var conn = new SqlConnection(_config["ConnectionStrings:DefaultConnection"]))
            {
                var cmd = new SqlCommand("pr_logStatusChange", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@workOrderId", log.WorkOrderId));
                cmd.Parameters.Add(new SqlParameter("@userId", log.UserId));
                cmd.Parameters.Add(new SqlParameter("@statusId", log.StatusId));

                conn.Open();
                await cmd.ExecuteNonQueryAsync();

                httpStatus = HttpStatusCode.NoContent;
            }

            return(httpStatus);
        }