public async Task <SystemSucceededTask> CreateInstance(CreateInstanceViewModel model, string userName) { var newInstance = new Instance { Active = model.Active, Service = _serviceRepository.GetById(model.ServiceId), Hostname = model.Hostname, Ip = model.Ip, LoginName = model.LoginName, Name = model.Name, Named = model.Named, LoginPassword = _customRepository.SetEncryption(model.LoginPassword) }; _instanceRepository.Add(newInstance); try { await _instanceRepository.SaveChangesAsync(); _logger.InformationLog("Instance: " + model.Name + " created successfully", "Create Service", string.Empty, userName); return(SystemSucceededTask.Success("Instance: " + model.Name + " created successfully")); } catch (Exception ex) { _logger.InformationLog(ex.Message, "Create Instance", ex.InnerException.Message, userName); return(SystemSucceededTask.Failed("Service: " + model.Name + " created unsuccessfully", ex.InnerException.Message, true, false)); } }
public IActionResult CreateInstance(long?id) { ViewBag.ServiceList = _monitor.ServiceList(id ?? -1); ViewBag.ServiceId = id; var instance = new CreateInstanceViewModel(); if (id != null) { instance.ServiceId = id.Value; } instance.Active = true; return(View(instance)); }
public async Task <IActionResult> CreateInstance(CreateInstanceViewModel model) { var result = await _monitor.CreateInstance(model, GetCurrentUserAsync().Result.UserName); if (result.Succeeded) { _toastNotification.AddSuccessToastMessage(result.OkMessage, new ToastrOptions() { PositionClass = ToastPositions.TopCenter }); return(RedirectToAction("ListInstance", new { id = model.ServiceId })); } _toastNotification.AddErrorToastMessage(result.Errors, new ToastrOptions() { PositionClass = ToastPositions.TopCenter }); ViewBag.DataBaseList = _monitor.ServiceList(-1); return(View(model)); }
public async Task <IActionResult> Create(CreateInstanceViewModel instanceViewModel) { if (this.ModelState.IsValid) { var instance = new Instance(); if (instanceViewModel != null) { instance.ModifiedDate = instance.CreatedDate = DateTime.UtcNow; instance.Description = instanceViewModel.Description; instance.Name = instanceViewModel.Name; } this.DatabaseContext.Add(instance); await this.DatabaseContext.SaveChangesAsync(); return(this.RedirectToAction(nameof(this.Index))); } return(this.View(instanceViewModel)); }
public async Task <IActionResult> Create(CreateInstanceViewModel instanceViewModel) { var dataUtils = new DataUtils(); if (ModelState.IsValid) { var atendee = new Instance(); if (instanceViewModel != null) { atendee.ModifiedDate = atendee.CreatedDate = DateTime.UtcNow; atendee.Description = instanceViewModel.Description; atendee.Name = instanceViewModel.Name; } _context.Add(atendee); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(instanceViewModel)); }
public IActionResult Create() { var viewModel = new CreateInstanceViewModel(); return(this.View(viewModel)); }