Example #1
0
        public PurchaseOrderStatusViewModel ToViewModel(TblPurchaseOrder Model, List <TblLookup> Status)
        {
            PurchaseOrderStatusViewModel ToReturn = new PurchaseOrderStatusViewModel();

            ToReturn.ApplicationUserId = Model.ApplicationUser.Id.ToString();
            ToReturn.Id = Model.ID.ToString();

            foreach (var S in Status)
            {
                ToReturn.NewStatus.Add(S.Value);
            }

            ToReturn.Budget          = Model.Budget;
            ToReturn.Code            = Model.Code;
            ToReturn.DateFullfilled  = Model.DateFullfilled;
            ToReturn.DateRaised      = Model.DateRaised;
            ToReturn.DateRequired    = Model.DateRequired;
            ToReturn.InvoiceToDetail = Model.InvoiceToDetail;
            ToReturn.Note            = Model.Note;
            ToReturn.Price           = Model.Price;
            ToReturn.Status          = Model.Status;
            ToReturn.Tax             = Model.Tax;
            ToReturn.Total           = Model.Total;
            return(ToReturn);
        }
        private async Task <DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // Call LUIS, try and identify what the user is trying to do.
            //If the entities are included in the response, convert them to a viewmodel and use them in the next prompt, otherwise prompt the user for the missing data.
            var luisResult = await _luisRecognizer.RecognizeAsync <IVR>(stepContext.Context, cancellationToken);

            switch (luisResult.TopIntent().intent)
            {
            case IVR.Intent.TaxForms:
                await stepContext.Context.SendActivityAsync(VoiceFactory.TextAndVoice(TaxFormsResponse), cancellationToken);

                break;

            case IVR.Intent.POStatus:
                var poStatusResult    = luisResult.Entities.ToObject <POStatusModel>();
                var poStatusViewModel = new PurchaseOrderStatusViewModel();

                if (poStatusResult.PONumber != null && poStatusResult.PONumber.Length > 0)
                {
                    poStatusViewModel.PONumber = poStatusResult.PONumber.First();
                }

                return(await stepContext.ReplaceDialogAsync(nameof(PurchaseOrderStatusDialog), poStatusViewModel));

            case IVR.Intent.LeavePolicy:
                var leavePolicyResult    = luisResult.Entities.ToObject <LeavePolicyModel>();
                var leavePolicyViewModel = new LeavePolicyViewModel();

                if (leavePolicyResult.LeaveOfAbscensePolicies != null && leavePolicyResult.LeaveOfAbscensePolicies.Length > 0)
                {
                    leavePolicyViewModel.LeaveOfAbscensePolicy = leavePolicyResult.LeaveOfAbscensePolicies.First().First();
                }

                return(await stepContext.ReplaceDialogAsync(nameof(LeavePolicyDialog), leavePolicyViewModel));

            case IVR.Intent.Cancel:
                //If the user indicates that they are done with the call, leave a message and hangup.
                var goodbyeMessage = VoiceFactory.TextAndVoice(HangupText, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(goodbyeMessage, cancellationToken);

                await Task.Delay(3000);     // Temporary hack to make sure that the message has finished being read.Bug is tracked to fix this issue.

                //End of conversation activity currently causes a HangUp. This functionality is experimental, and the API might change.
                await stepContext.Context.SendActivityAsync(Activity.CreateEndOfConversationActivity(), cancellationToken);

                return(await stepContext.EndDialogAsync());

            default:
                // Catch all for unhandled intents
                var didntUnderstandMessageText = $"Sorry, I didn't get that. Please try asking in a different way (intent was {luisResult.TopIntent().intent}). What I heard was {stepContext.Context.Activity.Text}";
                var didntUnderstandMessage     = VoiceFactory.TextAndVoice(didntUnderstandMessageText, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(didntUnderstandMessage, cancellationToken);

                break;
            }

            return(await stepContext.NextAsync(null, cancellationToken));
        }
        public async Task <IActionResult> CreatePurchaseOrderStatusAsync([FromBody] PurchaseOrderStatusViewModel value)
        {
            var response = new SingleModelResponse <PurchaseOrderStatusViewModel>() as ISingleModelResponse <PurchaseOrderStatusViewModel>;

            try
            {
                var entity = await Task.Run(() =>
                {
                    return(_RESTfulAPI_Repository.AddPurchaseOrderStatus(value.ToEntity()));
                });

                if (response.DidError == false)
                {
                    response.Model = entity.ToViewModel();
                }
            }
            catch (Exception ex)
            {
                string webRoot   = _hostingEnvironment.WebRootPath;
                string errorGuid = String.Format(Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 16));

                HttpContext.Session.SetString("ErrorGuid", errorGuid);
                ViewBag.ErrorGuid = HttpContext.Session.GetString("ErrorGuid");

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    using (StreamWriter w = new StreamWriter(webRoot + "\\log.txt", append: true))
                    {
                        Log.Logging(ex.ToString(), w, ViewBag.ErrorGuid);
                    }
                }

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    using (StreamWriter w = new StreamWriter(webRoot + "/log.txt", append: true))
                    {
                        Log.Logging(ex.ToString(), w, ViewBag.ErrorGuid);
                    }
                }


                response.DidError = true;
                //response.ErrorMessage = ex.ToString();


                return(this.Json(new { timestamp = DateTime.Now, errorGuid = ViewBag.ErrorGuid, status = HttpStatusCode.InternalServerError, info = "Error logged in log file." }));
            }



            response.Info = "Client " + " " + HttpContext.Connection.RemoteIpAddress.ToString();

            return(response.ToHttpResponse());
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        public static PurchaseOrderStatus ToEntity(this PurchaseOrderStatusViewModel viewModel)
        {
            return(viewModel == null ? null : new PurchaseOrderStatus
            {
                Id = viewModel.Id,
                Status = viewModel.Status


                         //
                         //RowGuid = viewModel.RowGuid,
                         //ModifiedDate = viewModel.ModifiedDate
            });
        }
        public async Task <IActionResult> UpdatePurchaseOrderStatusAsync(Int32 id, [FromBody] PurchaseOrderStatusViewModel value)
        {
            var response = new SingleModelResponse <PurchaseOrderStatusViewModel>() as ISingleModelResponse <PurchaseOrderStatusViewModel>;

            try
            {
                var entity = await Task.Run(() =>
                {
                    return(_RESTfulAPI_Repository.UpdatePurchaseOrderStatus(id, value.ToEntity()));
                });



                response.Model = entity.ToViewModel();
                response.Info  = "The record was updated successfully";
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.ToHttpResponse());
        }