public async Task <IActionResult> OnPostAsync(string returnUrl = null) { try { int menuId = Confidenciality.Decrypt <int>(Input.MEnc); var menuToChange = dbContext.Menu.Where(t => t.NMenuId == menuId).FirstOrDefault(); menuToChange.VcMenNameSq = Input.MenuName_Sq; menuToChange.VcMenuNameEn = Input.MenuName_En; menuToChange.VcIcon = Input.Icon; menuToChange.DtModify = DateTime.Now; menuToChange.NModifyId = User.FindFirstValue(ClaimTypes.NameIdentifier); await dbContext.SaveChangesAsync(); TempData.Set("error", new Error { nError = 1, ErrorDescription = "Te dhenat jane ruajtur me sukses!" }); } catch (Exception ex) { TempData.Set("error", new Error { nError = 4, ErrorDescription = "Ka ndodhur nje gabim gjate ruajtjes!" }); } return(RedirectToPage("./Menu")); }
public void OnGet(string UIEnc) { string UserId = Confidenciality.Decrypt <string>(UIEnc); Input = dbContext.AspNetUsers.Where(U => U.Id == UserId).Select(U => new InputClass { UIEnc = UIEnc, Adress = U.Address, AdressOpsional = U.Address2, BirthDate = U.BirthDate, City = dbContext.Cities.Where(C => C.Id == U.City).Select(S => S.Name).FirstOrDefault(), Contry = dbContext.Contries.Where(C => C.Id == U.Country).Select(S => S.Name).FirstOrDefault(), EmailAdress = U.Email, //EmploymentDate = U.EmploymentDate, DtFrom = U.DtFrom, DtTo = U.DtTo, FirstName = U.FirstName, Gender = U.Gender, IBANCode = U.IbanCode, JobTitle = U.JobTitle, LastName = U.LastName, PersonalNumber = U.PersonalNumber, PhoneNumber = U.PhoneNumber, salary = U.Salary, PostalCode = (int)U.PostCode, Position = U.AspNetUserRoles.FirstOrDefault().RoleId }).FirstOrDefault(); }
public async Task <IActionResult> OnPostAsync() { try { int subMenuId = Confidenciality.Decrypt <int>(Input.SMEnc); if (ModelState.IsValid) { var subMenu = dbContext.SubMenu.Where(S => S.NSubMenuId == subMenuId).FirstOrDefault(); subMenu.VcController = Input.Controller; subMenu.VcPage = Input.Page; subMenu.VcSubMenuSq = Input.SubMenu_Sq; subMenu.VcSubMenuEn = Input.SubMenu_En; subMenu.DtModify = DateTime.Now; await dbContext.SaveChangesAsync(); } TempData.Set("error", new Error { nError = 1, ErrorDescription = "Te dhenat jane ruajtur me sukses!" }); } catch (Exception ex) { TempData.Set("error", new Error { nError = 4, ErrorDescription = "Ka ndodhur nje gabim gjate ruajtjes!" }); } return(RedirectToPage("./Menu")); }
public void OnGet(string MEnc) { int menuId = Confidenciality.Decrypt <int>(MEnc); Input = dbContext.Menu.Where(M => M.NMenuId == menuId).Select(M => new InputModel { Icon = M.VcIcon, MenuName_En = M.VcMenuNameEn, MenuName_Sq = M.VcMenNameSq, MEnc = MEnc }).FirstOrDefault(); }
public void OnGet(string MEncId) { int menuId = Confidenciality.Decrypt <int>(MEncId); Input = new InputModel { MenuName = dbContext.Menu.Where(t => t.NMenuId == menuId).FirstOrDefault().VcMenNameSq, MEnc = MEncId }; }
public void OnGet(string SMEnc) { int subMenuId = Confidenciality.Decrypt <int>(SMEnc); Input = dbContext.SubMenu.Where(S => S.NSubMenuId == subMenuId).Select(S => new InputModel { Controller = S.VcController, Page = S.VcPage, MenuName = S.NMenu.VcMenNameSq, SubMenu_En = S.VcSubMenuEn, SubMenu_Sq = S.VcSubMenuSq, SMEnc = SMEnc }).FirstOrDefault(); }
public IActionResult OnGetDocument(string UIE, int docType) { string userId = Confidenciality.Decrypt <string>(UIE); if (docType == 1) { var filePath = dbContext.EmployeeDocuments.Where(u => u.Employee == userId).Select(S => new { S.Name, S.Path, S.DtInserted }).OrderByDescending(D => D.DtInserted).FirstOrDefault(); var fileBytes = ShowFile(filePath.Path); return(File(fileBytes, "application/pdf", filePath.Name)); } else if (docType == 2) { var imgBytes = dbContext.AspNetUsers.Where(U => U.Id == userId).Select(U => U.UserProfile).FirstOrDefault(); return(File(imgBytes, "application/jpeg", "UserProfile.jpeg")); } return(null); }
public async Task <JsonResult> OnPostDeleteSub(string SMEnc) { Error error = new Error { nError = 1, ErrorDescription = "Te dhenat jane ruajtur me sukses!" }; try { int subMenuId = Confidenciality.Decrypt <int>(SMEnc); dbContext.SubMenu.Remove(dbContext.SubMenu.Where(S => S.NSubMenuId == subMenuId).FirstOrDefault()); await dbContext.SaveChangesAsync(); } catch (Exception ex) { error = new Error { nError = 4, ErrorDescription = "Ka ndodhur nje gabim gjate ruajtjes!" }; } return(new JsonResult(error)); }
public JsonResult OnPostFshije(string MEnc) { Error error = new Error { nError = 1, errorDescription = "Te dhenat jane ruajtur me sukses!" }; try { int menuId = Confidenciality.Decrypt <int>(MEnc); dbContext.Menu.Remove(dbContext.Menu.Find(menuId)); dbContext.SaveChanges(); } catch (Exception ex) { error = new Error { nError = 4, errorDescription = "Ka ndodhur nje gabim gjate ruajtjes!" }; } return(new JsonResult(error)); }
public async Task <IActionResult> OnPost() { try { if (dbContext.SubMenu.Any(S => S.VcClaim == Input.Claim)) { TempData.Set("error", new Error { nError = 4, ErrorDescription = "Claim vlera egziston ne sistem." }); return(RedirectToPage("Menu")); } int menuId = Confidenciality.Decrypt <int>(Input.MEnc); dbContext.SubMenu.Add(new SubMenu { DtInserted = DateTime.Now, NInsertedId = User.FindFirstValue(ClaimTypes.NameIdentifier), NMenuId = menuId, VcController = Input.Controller, VcPage = Input.Page, VcSubMenuSq = Input.SubMenu_Sq, VcSubMenuEn = Input.SubMenu_En, VcClaim = Input.Claim }); await dbContext.SaveChangesAsync(); TempData.Set("error", new Error { nError = 1, ErrorDescription = "Te dhenat jane ruajtur me sukses!" }); } catch (Exception ex) { TempData.Set("error", new Error { nError = 4, ErrorDescription = "Ka ndodhur nje gabim gjate ruajtjes!" }); } return(RedirectToPage("Menu")); }
public async Task <JsonResult> OnPostChangePermission(string groupId, string PEnc) { Error error = new Error { nError = 1, ErrorDescription = Resource.msgRuajtjaSukses }; bool access = false; try { int policyId = Confidenciality.Decrypt <int>(PEnc); if (dbContext.AspNetRoleClaims.Any(T => T.RoleId == groupId && T.ClaimType == dbContext.Policy.Where(P => P.NPolicyId == policyId).Select(P => P.VcClaimType).FirstOrDefault())) { dbContext.AspNetRoleClaims.Remove(dbContext.AspNetRoleClaims.Where(R => R.RoleId == groupId && R.ClaimType == dbContext.Policy.Where(P => P.NPolicyId == policyId).Select(P => P.VcClaimType).FirstOrDefault()).FirstOrDefault()); dbContext.AspNetUserClaims.RemoveRange(dbContext.AspNetUserClaims.Where(C => C.ClaimType == dbContext.Policy.Where(P => P.NPolicyId == policyId).Select(P => P.VcClaimType).FirstOrDefault() && C.User.AspNetUserRoles.Where(R => R.RoleId == groupId).FirstOrDefault().RoleId == groupId)); await dbContext.SaveChangesAsync(); } else { access = true; var policy = dbContext.Policy.Where(P => P.NPolicyId == policyId).FirstOrDefault(); dbContext.AspNetRoleClaims.Add(new AspNetRoleClaims { ClaimType = policy.VcClaimType, ClaimValue = policy.VcClaimValue, RoleId = groupId }); var users = dbContext.AspNetUserRoles.Where(R => R.RoleId == groupId).Select(R => R.User); foreach (var userToChange in users) { userToChange.AspNetUserClaims.Add(new AspNetUserClaims { ClaimType = policy.VcClaimType, ClaimValue = policy.VcClaimValue }); } } await dbContext.SaveChangesAsync(); var user = await _userManager.FindByNameAsync(User.Identity.Name); await _signInManager.RefreshSignInAsync(user); string policyName = dbContext.Policy.Where(P => P.NPolicyId == policyId).Select(S => S.VcPolicyName).FirstOrDefault(); List <Notifications> notifications = dbContext.AspNetUserRoles.Where(UR => UR.RoleId == groupId).Select(R => new Notifications { DtInserted = DateTime.Now, Title = access?"Eshte shtuar qasja":"Eshte larguar qasja", VcIcon = access? "zmdi zmdi-lock-open" : "zmdi zmdi-lock", VcInsertedUser = User.FindFirstValue(ClaimTypes.NameIdentifier), VcUser = R.UserId, VcText = "Eshte " + (access?"shtuar":"larguar") + " qasja per " + policyName }).ToList(); if (notifications.Count() > 0) { dbContext.Notifications.AddRange(notifications); await dbContext.SaveChangesAsync(); } await _hubContext.Clients.All.SendAsync(groupId, (access ? "Eshte shtuar qasja" : "Eshte larguar qasja") + " për " + policyName, "Qasja!", "info", "/"); } catch (Exception ex) { error = new Error { nError = 4, ErrorDescription = Resource.msgGabimRuajtja }; } return(new JsonResult(error)); }
public async Task <IActionResult> OnPost() { string userId = ""; try { if (ModelState.IsValid) { userId = Confidenciality.Decrypt <string>(Input.UIEnc); var user = dbContext.AspNetUsers.Where(U => U.Id == userId).FirstOrDefault(); dbContext.AspNetUsersHistory.Add(new AspNetUsersHistory { Id = user.Id, JobTitle = user.JobTitle, LastName = user.LastName, LockoutEnabled = user.LockoutEnabled, LockoutEnd = user.LockoutEnd, AccessFailedCount = user.AccessFailedCount, NormalizedEmail = user.NormalizedEmail, NormalizedUserName = user.NormalizedUserName, Address = user.Address, Address2 = user.Address2, BirthDate = user.BirthDate, City = user.City, ConcurrencyStamp = user.ConcurrencyStamp, Country = user.Country, Email = user.Email, EmailConfirmed = user.EmailConfirmed, EmployeeStatus = user.EmployeeStatus, DtFrom = user.DtFrom, DtTo = user.DtTo, FirstName = user.FirstName, Gender = user.Gender, IbanCode = user.IbanCode, PasswordHash = user.PasswordHash, PersonalNumber = user.PersonalNumber, PhoneNumber = user.PhoneNumber, PhoneNumberConfirmed = user.PhoneNumberConfirmed, PostCode = user.PostCode, Salary = user.Salary, SecurityStamp = user.SecurityStamp, TwoFactorEnabled = user.TwoFactorEnabled, UserName = user.UserName, UserProfile = user.UserProfile }); await dbContext.SaveChangesAsync(); byte[] userImages = null; if (Input.UserProfileImg != null) { userImages = new byte[Input.UserProfileImg.Length]; BinaryReader imageBinary = new BinaryReader(Input.UserProfileImg.OpenReadStream()); userImages = imageBinary.ReadBytes((int)Input.UserProfileImg.Length); } user.JobTitle = Input.JobTitle; user.Salary = Input.salary; user.PostCode = Input.PostalCode; user.Address = Input.Adress; user.Address2 = Input.AdressOpsional; user.PhoneNumber = Input.PhoneNumber; user.IbanCode = Input.IBANCode; user.UserProfile = userImages != null ? userImages : user.UserProfile; var applicationUser = await _userManager.FindByIdAsync(user.Id); var roleId = await _userManager.GetRolesAsync(applicationUser); if (roleId[0] != dbContext.AspNetRoles.Where(R => R.Id == Input.Position).FirstOrDefault().Name) { string currentBeAdded = dbContext.AspNetRoles.Where(R => R.Id == user.AspNetUserRoles.FirstOrDefault().RoleId).FirstOrDefault().Name; string RoleToBeAdded = dbContext.AspNetRoles.Where(R => R.Id == Input.Position).FirstOrDefault().Name; await _userManager.RemoveFromRoleAsync(applicationUser, currentBeAdded); await _userManager.AddToRoleAsync(applicationUser, RoleToBeAdded); foreach (var claim in dbContext.AspNetRoleClaims.Where(R => R.Role.Id == Input.Position).ToList()) { await _userManager.AddClaimAsync(applicationUser, new Claim(claim.ClaimType, claim.ClaimValue)); } } if (Input.Contract != null) { var pathOfSavedFile = SaveFiles(Input.Contract, FType.ContractFile, configuration); dbContext.EmployeeDocuments.Add(new EmployeeDocuments { DtInserted = DateTime.Now, NInsertedId = User.FindFirstValue(ClaimTypes.NameIdentifier), Employee = user.Id, Name = Input.Contract.FileName, Path = pathOfSavedFile, Type = (int)FType.ContractFile }); } dbContext.Notifications.Add(new Notifications { DtInserted = DateTime.Now, Title = "Përditësim i të dhënave!", VcIcon = "zmdi zmdi-edit", VcInsertedUser = User.FindFirstValue(ClaimTypes.NameIdentifier), VcText = "Janë ndryshuar të dhënat në llogarinë tuaj nga përdoruesi: " + User.FindFirstValue(ClaimTypes.GivenName) + " " + User.FindFirstValue(ClaimTypes.Surname), VcUser = userId }); await dbContext.SaveChangesAsync(); await _hubContext.Clients.All.SendAsync(user.Id, "Janë ndryshuar të dhënat në llogarinë tuaj nga përdoruesi: " + User.FindFirstValue(ClaimTypes.GivenName) + " " + User.FindFirstValue(ClaimTypes.Surname), "Janë përditësuar të dhënat.", "info", "/"); } else { error = new Error { nError = 4, ErrorDescription = "Te dhenat nuk jane valide!" }; return(Page()); } } catch (Exception ex) { error = new Error { nError = 4, ErrorDescription = Resource.msgGabimRuajtja }; return(Page()); } TempData.Set <Error>("error", new Error { nError = 1, ErrorDescription = Resource.perditesimiMeSukses }); return(RedirectToPage("List")); }