public async Task <ActionResult> Create(WorkAssignment assignment, string userName)
        {
            ModelState.ThrowIfInvalid();

            var modelIsValid = await _adaptor.TryUpdateModelAsync(this, assignment);

            if (modelIsValid)
            {
                assignment.workOrder = woServ.Get(assignment.workOrderID);
                var newAssignment = waServ.Create(assignment, userName);
                var result        = map.Map <WorkAssignment, ViewModel.WorkAssignmentMVC>(newAssignment);
                return(Json(new {
                    sNewRef = result.tabref,
                    sNewLabel = result.tablabel,
                    iNewID = result.ID
                }));
            }
            else
            {
                return(Json(new {
                    jobSuccess = false,
                    rtnMessage = $"{ModelState.GetErrorMessageIfInvalid()}"
                }));
            }
        }
Esempio n. 2
0
        public ActionResult Create(WorkAssignment assignment, string userName)
        {
            UpdateModel(assignment);
            assignment.workOrder = woServ.Get(assignment.workOrderID);
            var newAssignment = waServ.Create(assignment, userName);
            var result        = map.Map <WorkAssignment, ViewModel.WorkAssignment>(newAssignment);

            return(Json(new
            {
                sNewRef = result.tabref,
                sNewLabel = result.tablabel,
                iNewID = result.ID
            }));
        }
Esempio n. 3
0
 public FluentRecordBase AddWorkAssignment(
     string desc          = null,
     int?skill            = null,
     DateTime?datecreated = null,
     DateTime?dateupdated = null,
     string updatedby     = null,
     bool assignWorker    = false
     )
 {
     //
     // DEPENDENCIES
     if (_wo == null)
     {
         AddWorkOrder();
     }
     if (assignWorker == true && _w == null)
     {
         AddWorker();
     }
     _servWA = container.Resolve <IWorkAssignmentService>();
     //
     // ARRANGE
     _wa           = (WorkAssignment)Records.assignment.Clone();
     _wa.workOrder = _wo;
     if (assignWorker)
     {
         _wa.workerAssigned = _w;
     }
     if (datecreated != null)
     {
         _wa.datecreated = (DateTime)datecreated;
     }
     if (dateupdated != null)
     {
         _wa.dateupdated = (DateTime)dateupdated;
     }
     if (desc != null)
     {
         _wa.description = desc;
     }
     if (updatedby != null)
     {
         _user = updatedby;
     }
     if (skill != null)
     {
         _wa.skillID = (int)skill;
     }
     //
     // ACT
     _servWA.Create(_wa, _user);
     return(this);
 }
Esempio n. 4
0
        public WorkOrder Create(WorkOrder order, string user)
        {
            validateTransportRules(order);


            order.statusID = WorkOrder.iPending;
            var assignments = order.workAssignments;

            order.workAssignments = null;
            var entity = woserv.Create(order, user);

            foreach (var a in assignments)
            {
                a.workOrderID = entity.ID;
                a.workOrder   = entity;
                waserv.Create(a, user);
            }
            return(woserv.Get(entity.ID));
        }
Esempio n. 5
0
        /// <summary>
        /// A method to create a WorkOrder, along with associated WorkAssignments and WorkerRequests, in the database.
        /// </summary>
        /// <param name="workOrder">The work order to be created.</param>
        /// <param name="workerRequestList">A list of worker requests made by the employer.</param>
        /// <param name="username">User performing action</param>
        /// <param name="workAssignments">A collection representing the worker assignments for the work order.</param>
        /// <returns>The created WorkOrder.</returns>
        public WorkOrder Create(WorkOrder workOrder, List <WorkerRequest> workerRequestList, string username, ICollection <WorkAssignment> workAssignments = null)
        {
            workOrder.timeZoneOffset = Convert.ToDouble(cfg.getConfig(Cfg.TimeZoneDifferenceFromPacific));
            updateComputedValues(ref workOrder);
            workOrder.createdByUser(username);
            var createdWorkOrder = repo.Add(workOrder);

            createdWorkOrder.workerRequestsDDD = new Collection <WorkerRequest>();
            if (workerRequestList != null)
            {
                foreach (var workerRequest in workerRequestList)
                {
                    workerRequest.workOrder       = createdWorkOrder;
                    workerRequest.workerRequested = wServ.Get(workerRequest.WorkerID);
                    workerRequest.updatedByUser(username);
                    workerRequest.createdByUser(username);
                    createdWorkOrder.workerRequestsDDD.Add(workerRequest);
                }
            }
            uow.SaveChanges();

            if (createdWorkOrder.paperOrderNum == null || createdWorkOrder.paperOrderNum == 0)
            {
                createdWorkOrder.paperOrderNum = createdWorkOrder.ID;
            }
            if (workAssignments != null)
            {
                foreach (var workAssignment in workAssignments)
                {
                    workAssignment.ID          = default(int); //so EF Core will save the record; otherwise IDENTITY_INSERT fails
                    workAssignment.workOrderID = createdWorkOrder.ID;
                    workAssignment.workOrder   = createdWorkOrder;
                    waServ.Create(workAssignment, username);
                }
            }

            uow.SaveChanges();

            _log(workOrder.ID, username, "WorkOrder created");
            return(createdWorkOrder);
        }
Esempio n. 6
0
        /// <summary>
        /// Create Work Order
        /// </summary>
        /// <param name="workOrder">Work order to create</param>
        /// <param name="user">User performing action</param>
        /// <returns>Work Order object</returns>
        public WorkOrder Create(WorkOrder workOrder, List <WorkerRequest> wrList, string user, ICollection <WorkAssignment> was = null)
        {
            WorkOrder wo;

            workOrder.timeZoneOffset = Convert.ToDouble(cfg.getConfig(Cfg.TimeZoneDifferenceFromPacific));
            updateComputedValues(ref workOrder);
            workOrder.createdByUser(user);
            wo = repo.Add(workOrder);
            wo.workerRequests = new Collection <WorkerRequest>();
            if (wrList != null)
            {
                // New Worker Requests to add
                foreach (var workerRequest in wrList)
                {
                    workerRequest.workOrder       = wo;
                    workerRequest.workerRequested = wServ.Get(workerRequest.WorkerID);
                    workerRequest.updatedByUser(user);
                    workerRequest.createdByUser(user);
                    wo.workerRequests.Add(workerRequest);
                }
            }
            uow.SaveChanges();
            if (wo.paperOrderNum == null || wo.paperOrderNum == 0)
            {
                wo.paperOrderNum = wo.ID;
            }
            if (was != null)
            {
                foreach (var a in was)
                {
                    a.workOrderID = wo.ID;
                    a.workOrder   = wo;
                    waServ.Create(a, user);
                }
            }

            uow.SaveChanges();

            _log(workOrder.ID, user, "WorkOrder created");
            return(wo);
        }