public async Task <IActionResult> CreateWallet() { System.Security.Claims.ClaimsPrincipal currentUser = User; var UserId = _userManager.GetUserId(currentUser); // Reference logged in User ApplicationUser LoggedInUser = await _userManager.FindByIdAsync(UserId); var walletAddress = ( from w in _context.Wallets where w.Username == LoggedInUser.UserName select w.publicAddress).FirstOrDefault(); if (walletAddress == null) { Wallet newWallet = _flipChain.CreateAndStoreWalletInDatabase(LoggedInUser.UserName, LoggedInUser.Email); ViewBag.walletAddress = newWallet.publicAddress; _notyf.Success($"Wallet {newWallet.publicAddress} created!"); } else { ViewBag.newWalletAddress = $"Wallet for user {LoggedInUser.UserName} already exists."; ViewBag.walletAddress = walletAddress; _notyf.Error($"Wallet for user {LoggedInUser.UserName} already exists!"); } var wallet = (from w in _context.Wallets where w.Username == LoggedInUser.UserName select w).FirstOrDefault(); return(View("Wallet", wallet)); }
public async Task <IActionResult> ImportData(FileDTO fileDto) { try { if (!ModelState.IsValid) { string messages = string.Join("; ", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage)); throw new Exception("Please correct the following errors: " + Environment.NewLine + messages); } //Upload the Excel Spreadsheet of learners var path = _fileService.UploadFile(fileDto.File, _foldersConfigation.Uploads); //import the data if (path != null) { await _dataService.ImportExcelForLearners(path); _notyf.Success("File uploaded successfully..."); } else { _notyf.Error("Invalid file uploaded"); return(Json(new { Result = "ERROR", Message = "Invalid file uploaded" })); } return(Json(new { Result = "OK" })); } catch (Exception ex) { _notyf.Error("Something went wrong : " + ex.Message); return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public async Task <IActionResult> RequestLease(int?id) { System.Security.Claims.ClaimsPrincipal currentUser = User; var UserId = _userManager.GetUserId(currentUser); ApplicationUser LoggedInUser = await _userManager.FindByIdAsync(UserId); if (id == null) { return(NotFound()); } var art = await _context.Art .FirstOrDefaultAsync(m => m.Id == id); if (art == null) { return(NotFound()); } if (art.OwnerName == LoggedInUser.UserName) { _notyf.Error("You cannot Lease your own Artpiece!"); return(View("Lease", art)); } else { return(View(art)); } }
public IActionResult Index() { _notyf.Success("Success Notification"); _notyf.Error("Some Error Message"); _notyf.Information("Information Notification - closes in 4 seconds.", 4); _notyf.Custom("Custom Notification <br><b><i>closes in 5 seconds.</i></b></p>", 5, "indigo", "fa fa-gear"); return(View()); }
public IActionResult Index() { _notyf.Success("Success Notification"); _notyf.Success("Success Notification that closes in 10 Seconds.", 3); _notyf.Error("Some Error Message"); _notyf.Warning("Some Error Message"); _notyf.Information("Information Notification - closes in 4 seconds.", 4); _notyf.Custom("Custom Notification - closes in 5 seconds.", 5, "whitesmoke", "fa fa-gear"); _notyf.Custom("Custom Notification - closes in 5 seconds.", 10, "#B600FF", "fa fa-home"); return(View()); }
public void AddGenesisBlock() { // Check if GenesisBlock already exists var Block = ( from r in _context.Blocks select r).FirstOrDefault(); if (Block == null) { // Create GenesisBlock Block GenesisBlock = CreateGenesisBlock(); // Save GenesisBlock in database StoreBlockInDatabase(GenesisBlock); _notyf.Success("Genesis Block added to Database!"); } else { _notyf.Error("Genesis Block already exists!"); } }
public IActionResult InsertOrUpdateInstitutionType(InstitutionType institutionType) { Action action = Action.None; if (ModelState.IsValid) { if (institutionType.Id == 0) { action = Action.Create; _unitWork.InstitutionType.Add(institutionType); } else { action = Action.Update; _unitWork.InstitutionType.Update(institutionType); } try { _unitWork.Save(); if (action == Action.Create) { _notyfService.Success("Tipo de institución creada correctamente."); } if (action == Action.Update) { _notyfService.Success("Tipo de institución actualizada correctamente."); } return(RedirectToAction(nameof(Index))); } catch (DbUpdateException dbUpdateException) { if (dbUpdateException.InnerException.Message.Contains("IX_InstitutionTypes_Name")) { _notyfService.Error("Ya existe un tipo de institución con el mismo nombre."); return(View(institutionType)); } else { ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); } } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } } return(View(institutionType)); }
public async Task <IActionResult> Create(string name, int kitchen, int toilet, int room) { if (ModelState.IsValid) { var apartment = new Apartment { Name = name, Kitchen = kitchen, Toilet = toilet, Room = room }; var addApartment = await _data.CreateApartmentAsync(apartment, _user.UserName); if (addApartment == true) { _notyf.Success("Apartment added successfully!"); //return RedirectToAction(nameof(Index), TempData["user"] = _user.UserName); var vM = new GetApartmentsViewModel { Apartments = await _data.GetApartmentsAsync(_user.Id), Contributions = await _data.GetUserContributionsAsync(_user.Id) }; return(PartialView("GetApartments", vM)); } _notyf.Error("Something went wrong :( "); return(PartialView()); } _notyf.Warning("Insert all fields!!"); return(PartialView()); }
public IActionResult InsertOrUpdateSubmodality(Submodality submodality) { if (ModelState.IsValid) { Action action = Action.None; if (submodality.Id == 0) { action = Action.Create; _unitWork.Submodality.Add(submodality); } else { action = Action.Update; _unitWork.Submodality.Update(submodality); } try { _unitWork.Save(); if (action == Action.Create) { _notyfService.Success("Submodalidad creada correctamente."); } if (action == Action.Update) { _notyfService.Success("Submodalidad actualizada correctamente."); } return(RedirectToAction(nameof(Index))); } catch (DbUpdateException dbUpdateException) { if (dbUpdateException.InnerException.Message.Contains("IX_Submodalities_Name")) { _notyfService.Error("Ya existe una submodalidad con el mismo nombre."); return(View(submodality)); } else { ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); } } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } } return(View(submodality)); }
public IActionResult Register(string nick, string email, string password) { if (!string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(nick) && !string.IsNullOrEmpty(password)) { var result = _data.RegisterAsync(email, nick, password); if (result.Result.Equals("Success")) { _notyf.Success("Welcome to our service"); TempData["user"] = nick; return(RedirectToAction("Index", "Logged")); } if (result.Result.Equals("exists")) { _notyf.Error("User with this email or nick name already exists"); return(RedirectToAction(nameof(Index))); } _notyf.Error(result.Result); return(RedirectToAction(nameof(Index))); } _notyf.Error("Fill all fields!"); return(RedirectToAction(nameof(Index))); }
public IActionResult InsertOrUpdateGender(Gender gender) { if (ModelState.IsValid) { Action action = Action.None; if (gender.Id == 0) { action = Action.Create; _unitWork.Gender.Add(gender); } else { action = Action.Update; _unitWork.Gender.Update(gender); } try { _unitWork.Save(); if (action == Action.Create) { _notyfService.Success("Género creado correctamente."); } if (action == Action.Update) { _notyfService.Success("Género actualizado correctamente."); } return(RedirectToAction(nameof(Index))); } catch (DbUpdateException dbUpdateException) { if (dbUpdateException.InnerException.Message.Contains("IX_Genders_Name")) { _notyfService.Error("Ya existe un Género con el mismo nombre."); return(View(gender)); } else { ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); } } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } } return(View(gender)); }
public IActionResult InsertOrUpdateTeachingFunction(TeachingFunction teachingFunction) { if (ModelState.IsValid) { Action action = Action.None; if (teachingFunction.Id == 0) { action = Action.Create; _unitWork.TeachingFunction.Add(teachingFunction); } else { action = Action.Update; _unitWork.TeachingFunction.Update(teachingFunction); } try { _unitWork.Save(); if (action == Action.Create) { _notyfService.Success("Función docente creada correctamente."); } if (action == Action.Update) { _notyfService.Success("Función docente actualizada correctamente."); } return(RedirectToAction(nameof(Index))); } catch (DbUpdateException dbUpdateException) { if (dbUpdateException.InnerException.Message.Contains("IX_TeachingFunctions_Name")) { _notyfService.Error("Ya existe una función docente con el mismo nombre."); return(View(teachingFunction)); } else { ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); } } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } } return(View(teachingFunction)); }
public IActionResult Create(ContractEditViewModel cevm, Klant klant) { if (ModelState.IsValid) { try { Contract contract = new Contract(); ContractType type = _contractTypeRepository.GetContractType(cevm.ContractTypeId); MapContractEditViewModelToContract(cevm, contract); contract.ContractType = type; klant.VoegContractToe(contract); _gebruikerRepository.SaveChanges(); _notyf.Success($"Succesvol {contract.ContractTitel} aangemaakt!"); } catch { _notyf.Error("Oops.. contract is niet aangemaakt. Probeer opnieuw."); } return(RedirectToAction(nameof(Index))); } ViewData["contractTypes"] = GetContractTypesAsSelectList(); return(View(nameof(Create), cevm)); }
public IActionResult Create(TicketEditViewModel tevm, Klant klant) { if (ModelState.IsValid) { try { Ticket ticket = new Ticket(); MapTicketEditViewModelToTicket(tevm, ticket); TicketType ticketType = _ticketTypeRepository.GetBy(tevm.TicketTypeId); ticket.TicketType = ticketType; klant.AddTicketByContractId(tevm.ContractId, ticket); _gebruikerRepository.SaveChanges(); _notyf.Success("Ticket succesvol aangemaakt", 3); } catch { _notyf.Error("Er is iets misgelopen. Probeer opnieuw.", 3); } return(RedirectToAction(nameof(Index))); } ViewData["IsEdit"] = false; ViewData["ticketTypes"] = GetTicketTypesAsSelectList(); return(View(nameof(Edit), tevm)); }
public IActionResult ChangeQueue(int id) { if (id == 0) { return(NotFound()); } //Check if already connected RemoteConnection = new RemoteConnection(); RemoteConnection = _db.RemoteConnection.FirstOrDefault(u => u.Id == id); if (RemoteConnection == null) { return(NotFound()); } else { if (RemoteConnection.BagliKisi == User.Identity.Name) { _notyf.Error("Zaten bağlısınız."); return(RedirectToAction("Index")); } } Queue queue = new Queue(); //Check if already in queue: queue = _db.Queue.FirstOrDefault(i => i.RemoteConnectionId == id && i.BekleyenKisi == User.Identity.Name); if (queue == null) { //Not in queue. Add. Queue queue1 = new Queue(); queue1.BekleyenKisi = User.Identity.Name; queue1.RemoteConnectionId = id; _db.Queue.Add(queue1); _db.SaveChanges(); } else { //User in queue. Remove. _db.Queue.Remove(queue); _db.SaveChanges(); } return(RedirectToAction("Index")); }
public async Task <IActionResult> ConfirmRecruited(long id) { var learner = _context.Learner.FirstOrDefault(a => a.LearnerId == id); if (learner != null && learner.AppliedYn.Equals("Yes")) { learner.RecruitedYn = Const.TRUE; // await SendConfirmRequitmentMail(learner); _context.Update(learner); await _context.SaveChangesAsync(); } else { _notyf.Error("Please make sure you recruit Applied learners", 5); // return RedirectToAction("Index","Learners").WithSuccess("Not Recruited","Please make sure you recruit Applied learners"); } _notyf.Information("Learner will now be placed with a company", 5); ViewData["JobId"] = new SelectList(_context.Jobs, "JobId", "JobTitle"); return(RedirectToAction("Index", "Learners").WithSuccess("Recruited", "Learner will now be placed with a company")); }
public IActionResult InsertOrUpdatePersonTypePerson(PersonTypePersonViewModel personTypePersonViewModel) { if (ModelState.IsValid) { Action action = Action.None; if (personTypePersonViewModel.PersonTypePerson.Id == 0) { action = Action.Create; _unitWork.PersonTypePerson.Add(personTypePersonViewModel.PersonTypePerson); } else { action = Action.Update; _unitWork.PersonTypePerson.Update(personTypePersonViewModel.PersonTypePerson); } try { _unitWork.Save(); if (action == Action.Create) { _notyfService.Success("Asignación Tipo de Persona creaada correctamente."); } if (action == Action.Update) { _notyfService.Success("Asignación Tipo de Persona actualizada correctamente."); } return(RedirectToAction(nameof(Index))); } catch (DbUpdateException dbUpdateException) { if (dbUpdateException.InnerException.Message.Contains("IX_PersonTypePeople_PersonId_TypePersonId")) { _notyfService.Error("Ya existe una Persona con los mismos datos registrados"); personTypePersonViewModel.TypePersonList = _unitWork.TypePerson.GetAll().Select(tpe => new SelectListItem { Text = tpe.Name, Value = tpe.Id.ToString() }); personTypePersonViewModel.PersonList = _unitWork.Person.GetAll().Select(pe => new SelectListItem { Text = pe.Names + " " + pe.Surnames, Value = pe.Id.ToString() }).ToList(); return(View(personTypePersonViewModel)); } else { ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); } } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } } else { personTypePersonViewModel.TypePersonList = _unitWork.TypePerson.GetAll().Select(tpe => new SelectListItem { Text = tpe.Name, Value = tpe.Id.ToString() }); personTypePersonViewModel.PersonList = _unitWork.Person.GetAll(orderBy: pe => pe.OrderBy(pe => pe.Surnames + pe.Names)).Select(pe => new SelectListItem { Text = pe.Names + " " + pe.Surnames, Value = pe.Id.ToString() }); if (personTypePersonViewModel.PersonTypePerson.Id != 0) { personTypePersonViewModel.PersonTypePerson = _unitWork.PersonTypePerson.Get(personTypePersonViewModel.PersonTypePerson.Id); } } return(View(personTypePersonViewModel)); }
public IActionResult InsertOrUpdateCareerPerson(CareerPersonViewModel careerPersonViewModel) { if (ModelState.IsValid) { Action action = Action.None; if (careerPersonViewModel.CareerPerson.Id == 0) { action = Action.Create; _unitWork.CareerPerson.Add(careerPersonViewModel.CareerPerson); } else { action = Action.Update; _unitWork.CareerPerson.Update(careerPersonViewModel.CareerPerson); } try { _unitWork.Save(); if (action == Action.Create) { _notyfService.Success("Programa Persona creado correctamente."); } if (action == Action.Update) { _notyfService.Success("Programa Persona actualizado correctamente."); } return(RedirectToAction(nameof(Index))); } catch (DbUpdateException dbUpdateException) { if (dbUpdateException.InnerException.Message.Contains("IX_CareerPeople_CareerId_PersonId")) { _notyfService.Error("Ya existe una Persona con el mismo programa."); careerPersonViewModel.CareerList = _unitWork.Career.GetAll().Select(ca => new SelectListItem { Text = ca.Name, Value = ca.Id.ToString() }); careerPersonViewModel.PersonList = _unitWork.Person.GetAll().Select(pe => new SelectListItem { Text = pe.Names + " " + pe.Surnames, Value = pe.Id.ToString() }).ToList(); return(View(careerPersonViewModel)); } else { ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); } } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } } else { careerPersonViewModel.CareerList = _unitWork.Career.GetAll().Select(ca => new SelectListItem { Text = ca.Name, Value = ca.Id.ToString() }); careerPersonViewModel.PersonList = _unitWork.Person.GetAll(orderBy: pe => pe.OrderBy(pe => pe.Surnames + pe.Names)).Select(pe => new SelectListItem { Text = pe.Names + " " + pe.Surnames, Value = pe.Id.ToString() }); if (careerPersonViewModel.CareerPerson.Id != 0) { careerPersonViewModel.CareerPerson = _unitWork.CareerPerson.Get(careerPersonViewModel.CareerPerson.Id); } } return(View(careerPersonViewModel)); }
public IActionResult InsertOrUpdateCity(CityViewModel cityViewModel) { if (ModelState.IsValid) { Action action = Action.None; if (cityViewModel.City.Id == 0) { action = Action.Create; _unitWork.City.Add(cityViewModel.City); } else { action = Action.Update; _unitWork.City.Update(cityViewModel.City); } try { _unitWork.Save(); if (action == Action.Create) { _notyfService.Success("Ciudad creada correctamente."); } if (action == Action.Update) { _notyfService.Success("Ciudad actualizada correctamente."); } return(RedirectToAction(nameof(Index))); } catch (DbUpdateException dbUpdateException) { if (dbUpdateException.InnerException.Message.Contains("IX_Cities_Name_DepartmentId")) { _notyfService.Error("Ya existe un Ciudad con el mismo nombre."); cityViewModel.DepartmentList = _unitWork.Department.GetAll().Select(d => new SelectListItem { Text = d.Name, Value = d.Id.ToString() }); return(View(cityViewModel)); } else { ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); } } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } } else { cityViewModel.DepartmentList = _unitWork.Department.GetAll().Select(d => new SelectListItem { Text = d.Name, Value = d.Id.ToString() }); if (cityViewModel.City.Id != 0) { cityViewModel.City = _unitWork.City.Get(cityViewModel.City.Id); } } return(View(cityViewModel)); }
public IActionResult InsertOrUpdateProgramType(ProgramTypeViewModel programTypeViewModel) { if (ModelState.IsValid) { Action action = Action.None; if (programTypeViewModel.ProgramType.Id == 0) { action = Action.Create; _unitWork.ProgramType.Add(programTypeViewModel.ProgramType); } else { action = Action.Update; _unitWork.ProgramType.Update(programTypeViewModel.ProgramType); } try { _unitWork.Save(); if (action == Action.Create) { _notyfService.Success("Tipo de programa creado correctamente."); } if (action == Action.Update) { _notyfService.Success("Tipo de programa actualizado correctamente."); } return(RedirectToAction(nameof(Index))); } catch (DbUpdateException dbUpdateException) { if (dbUpdateException.InnerException.Message.Contains("IX_ProgramTypes_Name")) { _notyfService.Error("Ya existe un tipo de programa con el mismo nombre."); programTypeViewModel.EducationLevelList = _unitWork.EducationLevel.GetAll().Select(el => new SelectListItem { Text = el.Name, Value = el.Id.ToString() }); return(View(programTypeViewModel)); } else { ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); } } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } } else { programTypeViewModel.EducationLevelList = _unitWork.EducationLevel.GetAll().Select(el => new SelectListItem { Text = el.Name, Value = el.Id.ToString() }); if (programTypeViewModel.ProgramType.Id != 0) { programTypeViewModel.ProgramType = _unitWork.ProgramType.Get(programTypeViewModel.ProgramType.Id); } } return(View(programTypeViewModel)); }
public IActionResult InsertOrUpdateRecognition(RecognitionViewModel recognitionViewModel) { Action action = Action.None; if (ModelState.IsValid) { if (recognitionViewModel.Recognition.Id == 0) { action = Action.Create; _unitWork.Recognition.Add(recognitionViewModel.Recognition); } else { action = Action.Update; _unitWork.Recognition.Update(recognitionViewModel.Recognition); } try { _unitWork.Save(); if (action == Action.Create) { _notyfService.Success("Reconocimiento creado correctamente."); } if (action == Action.Update) { _notyfService.Success("Reconocimiento actualizado correctamente."); } return(RedirectToAction(nameof(Index))); } catch (DbUpdateException dbUpdateException) { if (dbUpdateException.InnerException.Message.Contains("IX_Recognitions_Name")) { _notyfService.Error("Ya existe un Reconocimiento con la misma descripción."); recognitionViewModel.EducationLevelList = _unitWork.EducationLevel.GetAll(orderBy: el => el.OrderBy(el => el.Name)).Select(el => new SelectListItem { Text = el.Name, Value = el.Id.ToString() }); return(View(recognitionViewModel)); } else { ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); } } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } } else { recognitionViewModel.EducationLevelList = _unitWork.EducationLevel.GetAll(orderBy: el => el.OrderBy(el => el.Name)).Select(el => new SelectListItem { Text = el.Name, Value = el.Id.ToString() }); if (recognitionViewModel.Recognition.Id != 0) { recognitionViewModel.Recognition = _unitWork.Recognition.Get(recognitionViewModel.Recognition.Id); } } return(View(recognitionViewModel)); }
public IActionResult InsertOrUpdatePerson(PersonViewModel personViewModel) { personViewModel.Person.DepartmentId = Convert.ToInt32(Request.Form["DepartmentId"]); personViewModel.Person.CityId = Convert.ToInt32(Request.Form["CityId"]); if (ModelState.IsValid) { Action action = Action.None; if (personViewModel.Person.Id == 0) { action = Action.Create; _unitWork.Person.Add(personViewModel.Person); } else { action = Action.Update; _unitWork.Person.Update(personViewModel.Person); } try { _unitWork.Save(); if (action == Action.Create) { _notyfService.Success("Persona creada correctamente."); } if (action == Action.Update) { _notyfService.Success("Persona actualizada correctamente."); } return(RedirectToAction(nameof(Index))); } catch (DbUpdateException dbUpdateException) { if (dbUpdateException.InnerException.Message.Contains("IX_People_IdentificationNumber")) { _notyfService.Error("Ya existe una Persona con el mismo número de identificacxión."); personViewModel.IdentityDocumentTypeList = _unitWork.IdentityDocumentType.GetAll().Select(idt => new SelectListItem { Text = idt.Name, Value = idt.Id.ToString() }); personViewModel.GenderList = _unitWork.Gender.GetAll().Select(ge => new SelectListItem { Text = ge.Name, Value = ge.Id.ToString() }); personViewModel.DepartmentList = _unitWork.Department.GetAll().Select(d => new SelectListItem { Text = d.Name, Value = d.Id.ToString() }); personViewModel.CityList = _unitWork.City.GetAll().OrderBy(ci => ci.Name).Select(ci => new SelectListItem { Text = ci.Name, Value = ci.Id.ToString() }); return(View(personViewModel)); } else { ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); } } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } } else { personViewModel.IdentityDocumentTypeList = _unitWork.IdentityDocumentType.GetAll().Select(idt => new SelectListItem { Text = idt.Name, Value = idt.Id.ToString() }); personViewModel.GenderList = _unitWork.Gender.GetAll().Select(ge => new SelectListItem { Text = ge.Name, Value = ge.Id.ToString() }); personViewModel.DepartmentList = _unitWork.Department.GetAll().Select(d => new SelectListItem { Text = d.Name, Value = d.Id.ToString() }); personViewModel.CityList = _unitWork.City.GetAll().Select(ci => new SelectListItem { Text = ci.Name, Value = ci.Id.ToString() }); if (personViewModel.Person.Id != 0) { personViewModel.Person = _unitWork.Person.Get(personViewModel.Person.Id); } } return(View(personViewModel)); }
public async Task <IActionResult> Register(RegisterUserDto input) { try { if (!ModelState.IsValid) { var messages = string.Join("; ", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage)); throw new Exception("Please correct the following errors: " + Environment.NewLine + messages); } ViewData["Name"] = new SelectList(_roleManager.Roles, "Name", "Name", input.Role); input.ActiveYn = "No"; if (await _userManager.FindByNameAsync(input.UserName) != null || await _userManager.FindByEmailAsync(input.Email) != null) { _notyf.Error("Username : "******" or Email : " + input.Email + " already exists", 10); _logger.LogError("Username or Email already exists"); return(View()); } _logger.LogInformation("--- Register(" + input.Email + ") Start --"); //Create a User object var user = new Users { UserName = input.UserName, Email = input.Email }; user.ActiveYn = Const.FALSE; //Create a User on DB var result = await _userManager.CreateAsync(user, input.Password); /* * _context.User.Update(user); * await _context.SaveChangesAsync();*/ //Add User to role await _userManager.AddToRoleAsync(user, input.Role); if (result.Succeeded) { _logger.LogInformation("User created a new account with password"); _logger.LogInformation("Send an activation email..."); await SendActivationMail(user); if (_userManager.Options.SignIn.RequireConfirmedAccount) { return(View("Login")); } await _signInManager.SignInAsync(user, true); if (await _lookUpService.GetPersonDetailsByEmail(input.Email) == null) { _notyf.Information("Your registration was successful", 10); _logger.LogInformation("--- Register(" + input.Email + ") Create Account Start --"); return(RedirectToRoute("", new { controller = "Person", action = "CreateAccount" })); } if (_roleManager.GetRoleNameAsync(new Roles { Name = input.Role }).Result .Equals(Const.ADMINISTRATOR_USER)) { _logger.LogInformation("--- Register(" + input.Email + ") Person Index Start --"); return(RedirectToRoute("", new { controller = "Person", action = "Index" })); } _logger.LogInformation("--- Register(" + input.Email + ") Login Start --"); return(View("Login")); } } catch (Exception ex) { _notyf.Error("Something went wrong..."); return(Json(new { Result = "ERROR", ex.Message })); } // If we got this far, something failed, redisplay form return(RedirectToPage("/Dashboard/Dashboard")); }
public IActionResult InsertOrUpdateCareer(CareerViewModel careerViewModel) { Action action = Action.None; if (ModelState.IsValid) { if (careerViewModel.Career.Id == 0) { action = Action.Create; _unitWork.Career.Add(careerViewModel.Career); } else { action = Action.Update; _unitWork.Career.Update(careerViewModel.Career); } try { _unitWork.Save(); if (action == Action.Create) { _notyfService.Success("Programa creado correctamente."); } if (action == Action.Update) { _notyfService.Success("Programa actualizado correctamente."); } return(RedirectToAction(nameof(Index))); } catch (DbUpdateException dbUpdateException) { if (dbUpdateException.InnerException.Message.Contains("IX_Careers_Name")) { _notyfService.Error("Ya existe un Programa con el mismo nombre."); careerViewModel.ProgramTypeList = _unitWork.ProgramType.GetAll().Select(pt => new SelectListItem { Text = pt.Name, Value = pt.Id.ToString() }); return(View(careerViewModel)); } else { ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); } } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } } else { careerViewModel.ProgramTypeList = _unitWork.ProgramType.GetAll().Select(pt => new SelectListItem { Text = pt.Name, Value = pt.Id.ToString() }); if (careerViewModel.Career.Id != 0) { careerViewModel.Career = _unitWork.Career.Get(careerViewModel.Career.Id); } } return(View(careerViewModel)); }
public IActionResult InsertOrUpdateInstitution(InstitutionViewModel institutionViewModel) { if (ModelState.IsValid) { Action action = Action.None; if (institutionViewModel.Institution.Id == 0) { action = Action.Create; _unitWork.Institution.Add(institutionViewModel.Institution); } else { action = Action.Update; institutionViewModel.Institution.Email = institutionViewModel.Institution.Email.ToLower(); _unitWork.Institution.Update(institutionViewModel.Institution); } try { _unitWork.Save(); if (action == Action.Create) { _notyfService.Success("Institución creada correctamente."); } if (action == Action.Update) { _notyfService.Success("Institución actualizada correctamente."); } return(RedirectToAction(nameof(Index))); } catch (DbUpdateException dbUpdateException) { if (dbUpdateException.InnerException.Message.Contains("IX_Institutions_Name")) { _notyfService.Error("Ya existe un Instución con el mismo nombre."); institutionViewModel.InstitutionTypeList = _unitWork.InstitutionType.GetAll().Select(it => new SelectListItem { Text = it.Name, Value = it.Id.ToString() }); return(View(institutionViewModel)); } else { ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); } } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } } else { institutionViewModel.InstitutionTypeList = _unitWork.InstitutionType.GetAll().Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }); if (institutionViewModel.Institution.Id != 0) { institutionViewModel.Institution = _unitWork.Institution.Get(institutionViewModel.Institution.Id); } } return(View(institutionViewModel)); }
public IActionResult InsertOrUpdateModality(ModalityViewModel modalityViewModel) { if (ModelState.IsValid) { Action action = Action.None; if (modalityViewModel.Modality.Id == 0) { action = Action.Create; _unitWork.Modality.Add(modalityViewModel.Modality); } else { action = Action.Update; _unitWork.Modality.Update(modalityViewModel.Modality); } try { _unitWork.Save(); if (action == Action.Create) { _notyfService.Success("Modalidad creada correctamente."); } if (action == Action.Update) { _notyfService.Success("Modalidad actualizada correctamente."); } return(RedirectToAction(nameof(Index))); } catch (DbUpdateException dbUpdateException) { if (dbUpdateException.InnerException.Message.Contains("IX_Modalities_Name")) { _notyfService.Error("Ya existe una modalidad con el mismo nombre."); modalityViewModel.EducationLevelList = _unitWork.EducationLevel.GetAll().Select(el => new SelectListItem { Text = el.Name, Value = el.Id.ToString() }); return(View(modalityViewModel)); } else { ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); } } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } } else { modalityViewModel.EducationLevelList = _unitWork.EducationLevel.GetAll().Select(el => new SelectListItem { Text = el.Name, Value = el.Id.ToString() }); if (modalityViewModel.Modality.Id != 0) { modalityViewModel.Modality = _unitWork.Modality.Get(modalityViewModel.Modality.Id); } } return(View(modalityViewModel)); }