Exemplo n.º 1
0
        public ActionResult AddNote(WorkOrderNoteModel model)
        {
            var workOrder = _repository.SearchFor <SageWorkOrder>(x => x.WorkOrder == model.WorkOrderId).SingleOrDefault();

            if (workOrder == null)
            {
                return(Error("Work Order does not exist", $"There are no Work Orders with ID: {model.WorkOrderId}. workOrder == null"));
            }

            var note           = Mapper.Map <SageNote>(model);
            var addNoteResult  = _sageApiProxy.AddNote(note);
            var getNotesResult = _sageApiProxy.GetNotes(note.TRANSNBR);

            if (addNoteResult.IsSucceed && getNotesResult.IsSucceed && getNotesResult.Entities != null)
            {
                workOrder.WorkNotes = getNotesResult.Entities;
                _repository.Update(workOrder);
                _hub.UpdateSageWorkOrder(workOrder);
            }
            else
            {
                _log.ErrorFormat("Was not able to add note to sage. !result.IsSucceed");
                return(Error("Note save failed", $"AddNote method IsSucceed==false. {addNoteResult?.ErrorMassage}"
                             ));
            }
            return(Success());
        }
Exemplo n.º 2
0
        public ActionResult AddWOItem(LaborPartsModel model)
        {
            var workOrder = repository.SearchFor <SageWorkOrder>(x => x.WorkOrder == model.WorkOrder).SingleOrDefault();

            if (workOrder == null)
            {
                return(Error("Work Order does not exist", $"There are no Work Orders with ID: {model.WorkOrder}. workOrder == null"));
            }

            var workOrderItem = Mapper.Map <SageWorkOrderItem>(model);

            workOrderItem.Employee = UserModel.Name;

            if (model.WorkOrderItem == 0)
            {
                workOrderItem.WorkOrder = model.WorkOrder;
                workOrderItem.TotalSale = workOrderItem.Quantity * workOrderItem.UnitSale;
                if (workOrderItem.ItemType == "Parts")
                {
                    workOrderItem.PartsSale = workOrderItem.UnitSale;
                }
                else
                {
                    workOrderItem.LaborSale = workOrderItem.UnitSale;
                }

                var result = sageApiProxy.AddWorkOrderItem(workOrderItem);
                if (result != null && result.IsSucceed && result.Entity != null)
                {
                    var woiResult = sageApiProxy.GetWorkorderItemsByWorkOrderId(workOrder.WorkOrder);
                    if (woiResult.IsSucceed)
                    {
                        workOrder.WorkOrderItems = woiResult.Entities;
                        repository.Update(workOrder);
                        _hub.UpdateSageWorkOrder(workOrder);
                    }
                }
                else
                {
                    _log.ErrorFormat("Was not able to save workorderItem to sage. !result.IsSucceed");
                    return(Error("Work order item save failed", $"AddWorkOrderItem method IsSucceed==false. {result?.ErrorMassage}"
                                 ));
                }
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var resultUpdate = sageApiProxy.EditWorkOrderItem(workOrderItem);
                if (resultUpdate != null && resultUpdate.IsSucceed && resultUpdate.Entity != null)
                {
                    var woiResult = sageApiProxy.GetWorkorderItemsByWorkOrderId(workOrder.WorkOrder);
                    if (woiResult.IsSucceed)
                    {
                        workOrder.WorkOrderItems = woiResult.Entities;
                        repository.Update(workOrder);
                    }
                }
                else
                {
                    _log.ErrorFormat("Was not able to update workorderItem to sage. !result.IsSucceed");
                    return(Error("Work order item update failed", $"EditWorkOrderItem method IsSucceed==false. {resultUpdate?.ErrorMassage}."
                                 ));
                }
                return(Json(resultUpdate, JsonRequestBehavior.AllowGet));
            }
        }