示例#1
0
        public async Task <ActionResult> Create(UDFViewModel model, string updateButton)
        {
            if (updateButton.Equals("Cancel"))
            {
                return(Redirect(CacheHelper.GetPreviousPage(_cache)));
            }

            try
            {
                string js;

                if (model.UDFFile != null)
                {
                    using (var r = new StreamReader(model.UDFFile.OpenReadStream()))
                    {
                        js = await r.ReadToEndAsync();

                        if (String.IsNullOrWhiteSpace(js))
                        {
                            await FeedbackHelper.Channel.SendMessageAsync($"Error - We cannot read the content of the file {model.UDFFile.FileName}.", MessageType.Info);
                        }
                    }
                }
                else if (model.Content != null)
                {
                    js = model.Content;
                }
                else
                {
                    js = string.Empty;
                }

                var id = await DigitalTwinsHelper.CreateUserDefinedFunctionAsync(_cache, Loggers.SilentLogger, model.UDF, js);

                return(RedirectToAction(nameof(Edit), new { id = id }));
            }
            catch
            {
                return(Redirect(CacheHelper.GetPreviousPage(_cache)));
            }
        }