Esempio n. 1
0
        public IActionResult CreateInspectionOrder([FromBody] dynamic data)
        {
            try
            {
                if (data == null)
                {
                    return(BadRequest());
                }

                InspectionOrder inspectionOrder = Utils.ConvertTo <InspectionOrder>(data);
                if (inspectionOrder == null)
                {
                    return(BadRequest());
                }

                // Set status to pending assignment
                //inspectionOrder.Policy.InspectionStatusId = InspectionStatusConstants.PendingAssignment;

                if (string.IsNullOrEmpty(inspectionOrder.InspectorId.ToString()))
                {
                    inspectionOrder.AssignedDate = null;
                }
                else
                {
                    inspectionOrder.AssignedDate = DateTime.Now.Date;
                }

                inspectionOrder.CreatedDate = DateTime.Now.Date;

                var inspectionDate = (DateTime?)data.inspectionDate;

                if (inspectionDate == null)
                {
                    inspectionOrder.InspectionDate = null;
                }
                else
                {
                    if (inspectionOrder.Policy.InspectionStatusId.Equals("S"))
                    {
                        inspectionOrder.InspectionDate = inspectionDate;
                    }
                    else
                    {
                        inspectionOrder.InspectionDate = null;
                    }
                }

                var userId = _rivingtonContext.GetCurrentUser();
                inspectionOrder.CreatedById = userId;

                _inspectionOrderRepository.InsertOrUpdateIO(inspectionOrder);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
        }
        public string PolicyRequest(string Header, string Data)
        {
            try
            {
                var headerXml = new XmlDocument();
                headerXml.LoadXml(Header);

                var dataXml = new XmlDocument();
                dataXml.LoadXml(Data);

                var innerXML = dataXml.InnerXml;

                var policyXML = Utils.XmlToObject(innerXML, typeof(PolicyXMLResponse)).ConvertTo <PolicyXMLResponse>();

                var newIo = _thirdPartyRepository.ConvertToIO(policyXML);

                var isExist = _inspectionOrderRepository.RetrieveByPolicyNumber(newIo.Policy.PolicyNumber);

                if (isExist)
                {
                    return("Policy Number already exist");
                }

                _inspectionOrderRepository.InsertOrUpdateIO(newIo);

                return("Success");
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }