public async Task <IActionResult> OnPostAsync() { try { dbContext.Menu.Add(new Menu { VcMenNameSq = Input.MenuName_Sq, VcMenuNameEn = Input.MenuName_En, VcIcon = Input.Icon, DtInserted = DateTime.Now, NInsertedId = User.FindFirstValue(ClaimTypes.NameIdentifier) }); await dbContext.SaveChangesAsync(); error = new Error { nError = 1, errorDescription = "Te dhenat jane regjistruar me sukses!" }; } catch (Exception ex) { dbContext = new ESMSContext(); error = new Error { nError = 4, errorDescription = "Ka ndodhur nje gabim gjate ruajtjes se te dhenave!" }; } menus = dbContext.Menu.ToList(); subMenus = dbContext.SubMenu.ToList(); return(Page()); }
public static List <SelectListItem> GetContries() { using (ESMSContext dbContext = new ESMSContext()) { List <SelectListItem> countries = new List <SelectListItem> { new SelectListItem { Value = "247", Text = "Kosovë" } }; countries.AddRange(dbContext.Contries.Where(R => R.Id != 247).Select(R => new SelectListItem { Text = R.Name, Value = R.Id.ToString() }).ToList()); return(countries); } }
public async Task <IActionResult> OnPostAsync() { var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.")); } if (!ModelState.IsValid) { await LoadAsync(user); return(Page()); } var phoneNumber = await _userManager.GetPhoneNumberAsync(user); if (Input.PhoneNumber != phoneNumber) { var setPhoneResult = await _userManager.SetPhoneNumberAsync(user, Input.PhoneNumber); if (!setPhoneResult.Succeeded) { var userId = await _userManager.GetUserIdAsync(user); throw new InvalidOperationException($"Unexpected error occurred setting phone number for user with ID '{userId}'."); } } using (ESMSContext eSMSContext = new ESMSContext()) { var dataToBeChanged = eSMSContext.AspNetUsers.Where(A => A.Id == _userManager.GetUserId(User)).FirstOrDefault(); dataToBeChanged.FirstName = Input.FirstName; dataToBeChanged.LastName = Input.LastName; await eSMSContext.SaveChangesAsync(); } user.FirstName = Input.FirstName; user.LastName = Input.LastName; await _signInManager.RefreshSignInAsync(user); StatusMessage = Resource.perditesimiMeSukses; return(RedirectToPage()); }
public async Task <IActionResult> OnPost() { policies = dbContext.Policy.ToList(); if (!ModelState.IsValid) { error = new Error { nError = 4, ErrorDescription = "Te dhenat nuk jane ne rregull!" }; return(Page()); } try { if (dbContext.Policy.Any(P => P.VcPolicyName == Input.policyName)) { error = new Error { nError = 4, ErrorDescription = "Keni shtypur te dhena egzistuese!" }; return(Page()); } dbContext.Policy.Add(new Policy { VcPolicyName = Input.policyName, VcClaimValue = Input.ClaimValue, VcClaimType = Input.ClaimType, BActive = true, DtInserted = DateTime.Now, NInsertedId = User.FindFirstValue(ClaimTypes.NameIdentifier) }); await dbContext.SaveChangesAsync(); error = new Error { nError = 1, ErrorDescription = "Te dhenat jane regjistruar me sukses!" }; policies = dbContext.Policy.ToList(); } catch (Exception ex) { dbContext = new ESMSContext(); error = new Error { nError = 4, ErrorDescription = "Ka ndodhur nje gabim gjate ruajtjes se te dhenave!" }; } return(Page()); }
public static List <SelectListItem> GetGroups(int nCase, string UID) { using (ESMSContext dbContext = new ESMSContext()) { switch (nCase) { case 1: return(dbContext.AspNetRoles.Select(R => new SelectListItem { Text = R.Name, Value = R.Id }).ToList()); case 2: string[] userGroupd = null; if (UID == "Administrator") { userGroupd = new string[] { "a15cae60-f564-4b36-9c60-5cb9d7eb7f1e", "dbc05ab9-f41f-493f-b3e6-689d14e88dda", "be007199-39b1-4557-b10f-cc4e6dc47b49", "423a5ce2-3024-47d1-b486-4dcd3951871b", "58cfa2e9-9eeb-4fcd-b87c-6d0b676fb066" } } ; else if (UID == "Menagjer_IT") { userGroupd = new string[] { "a15cae60-f564-4b36-9c60-5cb9d7eb7f1e" } } ; else if (UID == "Menagjer_Financa") { userGroupd = new string[] { "dbc05ab9-f41f-493f-b3e6-689d14e88dda" } } ; else if (UID == "Burimet_Njerzore") { userGroupd = new string[] { "a15cae60-f564-4b36-9c60-5cb9d7eb7f1e", "dbc05ab9-f41f-493f-b3e6-689d14e88dda", "be007199-39b1-4557-b10f-cc4e6dc47b49", "423a5ce2-3024-47d1-b486-4dcd3951871b", "58cfa2e9-9eeb-4fcd-b87c-6d0b676fb066" } } ; return(dbContext.AspNetRoles.Where(R => userGroupd.Contains(R.Id)).Select(R => new SelectListItem { Text = R.Name, Value = R.Id }).ToList()); } return(null); } }
public void OnPageHandlerExecuting(PageHandlerExecutingContext context) { dbContext = new ESMSContext(); }
public BaseModel(SignInManager <ApplicationUser> signInManager, UserManager <ApplicationUser> userManager) { this.signInManager = signInManager; this.userManager = userManager; dbContext = new ESMSContext(); }