コード例 #1
0
        public virtual async Task <ActionResult> Editor(FileServerModel model, bool?saveAndContinue)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var record   = _fileServerModelFactory.PrepareTblFileServers(model);
            var recordId = model.Id;

            try
            {
                var server = _fileServersService.GetWebService(record);
                var result = await server.EnumerateFilesAsync("\\", "*.*", false, TimeSpan.Zero, 0).ConfigureAwait(false);

                server.Close();
            }
            catch (Exception ex)
            {
                var errorCode = ErrorLog.GetDefault(System.Web.HttpContext.Current).Log(new Error(ex, System.Web.HttpContext.Current));
                ModelState.AddModelError("", string.Format(_localizationService.GetResource("ErrorOnOperation"), ex.Message, errorCode));
                return(View(model));
            }

            try
            {
                if (model.Id == null)
                {
                    //Add new record
                    recordId = await _fileServersService.AddAsync(record);
                }
                else
                {
                    //Edit record
                    await _fileServersService.UpdateAsync(record);
                }
            }
            catch (Exception e)
            {
                var errorCode = ErrorLog.GetDefault(System.Web.HttpContext.Current).Log(new Error(e, System.Web.HttpContext.Current));
                ModelState.AddModelError("", string.Format(_localizationService.GetResource("ErrorOnOperation"), e.Message, errorCode));
                return(View(model));
            }

            if (saveAndContinue != null && saveAndContinue.Value)
            {
                return(RedirectToAction("Editor", "ManageFileServers", new { id = recordId }));
            }

            return(Content(@"<script language='javascript' type='text/javascript'>
                                window.close();
                                window.opener.refreshFileServersGrid();
                             </script>"));
        }