Beispiel #1
0
        public async Task <SystemSucceededTask> EditSystem(EditSystemViewModel model, string userName)
        {
            var oldSystem = _systemRepository.GetById(model.Id);

            if (oldSystem == null)
            {
                _logger.ErrorLog("Edit System: " + model.Name + " does not exists", "Edit Database System",
                                 "Database System " + model.Name + "does not exist", userName);
                return(SystemSucceededTask.Failed("Edit " + model.Name + " unsuccessful",
                                                  "Database System " + model.Name + "does not exist", false, true));
            }

            try
            {
                oldSystem.Name                = model.Name;
                oldSystem.Description         = model.Description;
                oldSystem.Active              = model.Active;
                oldSystem.Vendor              = _vendorRepository.GetById(model.VendorId);
                oldSystem.ConfigurationType   = _configurationTypeRepository.GetById(model.ConfigTypeId);
                oldSystem.DatabaseEnvironment = _dataBaseEnvironment.GetById(model.EnvironmentId);
                oldSystem.UpdatedOn           = DateTimeOffset.Now;

                await _systemRepository.SaveChangesAsync();

                _logger.InformationLog("Edit Database System: " + model.Name, "Edit Database System", string.Empty,
                                       userName);
                return(SystemSucceededTask.Success("System " + model.Name + " edited succesfully"));
            }
            catch (Exception ex)
            {
                if (ex.InnerException.Source.Contains("sql"))
                {
                    _logger.ErrorLog(ex.Message, "Edit Database System", ex.InnerException.Message, userName);
                    return(SystemSucceededTask.Failed("Edit {oldSystem.Name} unsuccessful", ex.InnerException.Message,
                                                      false, true));
                }

                _logger.ErrorLog(ex.Message, "Edit Database System", ex.InnerException.Message, userName);
                return(SystemSucceededTask.Failed("Edit {oldSystem.Name} unsuccessful", ex.InnerException.Message,
                                                  false, true));
            }
        }
        public async Task <IActionResult> EditSystemViewPost(EditSystemViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToPage("/get/system/" + model.Id.ToString()));
            }
            var res = await _monitor.EditSystem(model, GetCurrentUserAsync().Result.UserName);

            if (res.Succeeded)
            {
                _toastNotification.AddSuccessToastMessage(res.OkMessage, new ToastrOptions()
                {
                    PositionClass = ToastPositions.TopCenter
                });
                return(RedirectToAction("ListSystem"));
            }
            _toastNotification.AddErrorToastMessage(res.Errors, new ToastrOptions()
            {
                PositionClass = ToastPositions.TopCenter
            });
            return(RedirectToPage("/get/system/" + model.Id.ToString()));
        }