public AmpluaPrincipal(AccountRoles accountRole, IIdentity identity) { Require.NotNull(identity, nameof(identity)); _accountRole = accountRole; Identity = identity; }
private static AccountRolesDto ConvertFromRepositoryEntity(AccountRoles accountRoles) { if (accountRoles == null) { return(null); } var rolesDto = new AccountRolesDto { Id = accountRoles.Id, AccountID = accountRoles.AccountID, HotelID = accountRoles.HotelID, RoleID = accountRoles.RoleID }; if (accountRoles.CreateTime != null) { rolesDto.CreateTime = accountRoles.CreateTime.Value; } else { rolesDto.CreateTime = DateTime.MinValue; } if (accountRoles.UpdateTime != null) { rolesDto.UpdateTime = accountRoles.UpdateTime.Value; } else { rolesDto.UpdateTime = DateTime.MinValue; } return(rolesDto); }
protected void Page_Load(object sender, System.EventArgs e) { aid = Convert.ToInt32(Request.QueryString["AccountID"]); if (aid == 0) { Page_Error("AccountID Missing"); } if (aid == 1) { bnRemove.Visible = false; } account = new Account(appEnv.GetConnection()); property = new AccountProperty(appEnv.GetConnection()); roles = new AccountRoles(appEnv.GetConnection()); dr = account.GetAccountForID(aid); if (!IsPostBack) { tbUserID.Text = dr["UserName"].ToString().Trim(); tbUserName.Text = property.GetValue(aid, "UserName").Trim(); tbEmail.Text = dr["Email"].ToString().Trim(); DataTable roledt = roles.GetRolesForID(aid); string Cmd = "Select * FROM Roles"; SqlDataAdapter DAdpt = new SqlDataAdapter(Cmd, appEnv.GetConnection()); DataSet ds = new DataSet(); DAdpt.Fill(ds, "Roles"); DataTable allRolesdt = ds.Tables["Roles"]; foreach (DataRow drr in allRolesdt.Rows) { ListItem li = new ListItem(drr["Role"].ToString()); foreach (DataRow adr in roledt.Rows) { if (drr["Role"].ToString().Equals(adr["Role"].ToString())) { li.Selected = true; } } lbRoles.Items.Add(li); } if (aid == 1) { bnRemove.Visible = false; lbRoles.Enabled = false; } } }
public async Task UpdateStausTestPositive(AccountRoles accountRole, OrderStatuses previousOrderStatus, OrderStatuses nextStatus) { //Arrange var owner = EntitiesCreationService.GetOwner(); owner.HashedPassword = "******"; var restaurant = EntitiesCreationService.GetRestaurant(); owner.Restaurants = new List <Restaurant>() { restaurant }; owner = await accountsRepository.AddAsync(owner); var account = EntitiesCreationService.GetOwner(); account.HashedPassword = "******"; account.Role = accountRole; var order = EntitiesCreationService.GetOrder(); var orderStatus = EntitiesCreationService.GetOrderStatus(); orderStatus.Status = previousOrderStatus; order.OrderStatuses = new List <OrderStatus>() { orderStatus }; order.RestaurantId = owner.Restaurants[0].RestaurantId; account.Orders = new List <Order>() { order }; account = await accountsRepository.AddAsync(account); try { //Act await orderService.UpdateStaus(account.AccountId, account.Orders[0].EntityId, nextStatus); //Assert var statuses = ordersStatusRepository.GetAllStatusesForOrder(account.Orders[0].EntityId); Assert.Contains(statuses, s => s.Status == nextStatus); var orders = ordersRepository.GetAllOrdersForRegularUser(account.EntityId); Assert.Equal(orders[0].LatestOrderStatus, nextStatus); } finally { //Clear accountsRepository.Remove(account); accountsRepository.Remove(owner); } }
public Account(AccountId accountId, Username username, AccountRoles roles) { Contract.Requires(accountId != null); Contract.Requires(username != null); Contract.Requires(roles != null); AccountId = accountId; Username = username; _roles = roles; }
public static bool CheckToMask(this AccountRoles role, AccountRoles mask) { if (mask.HasFlag(AccountRoles.Anonymous) || mask.HasFlag(AccountRoles.Banned)) { // Commands with these roles are accessible for everyone (even for banned users) return(true); } return(!role.HasFlag(AccountRoles.Banned) && (role & mask) != 0); }
public AuthorizationTokenInfo(int userId, AccountRoles role, string token, DateTime creationTime) { Require.Positive(userId, nameof(userId)); Require.NotNull(token, nameof(token)); UserId = userId; Role = role; Token = token; CreationTime = creationTime; }
public void Send() { AppEnv appenv = new AppEnv(m_context); string SMTPServer = appenv.GetAppSetting("smtpserver").Trim(); if (SMTPServer.Length <= 0) { return; // do not use email notifications } SmtpMail.SmtpServer = SMTPServer; Account account = new Account(appenv.GetConnection()); MailMessage mail = new MailMessage(); DataRow dr = account.GetAccountForID(1); // Admin account mail.From = dr["Email"].ToString().Trim(); mail.Subject = generateSubject(); mail.Body = m_body; mail.BodyFormat = MailFormat.Text; if (m_towho != 0) { dr = account.GetAccountForID(m_towho); mail.To = dr["Email"].ToString().Trim(); try { SmtpMail.Send(mail); } catch { } } else { AccountRoles roles = new AccountRoles(new AppEnv(m_context).GetConnection()); DataTable dt = roles.GetAllRole(getRoleForCode()); foreach (DataRow drr in dt.Rows) { dr = account.GetAccountForID(Convert.ToInt32(drr["AccountID"])); mail.To = dr["Email"].ToString().Trim(); try { SmtpMail.Send(mail); } catch { } } } }
public NotAuthorizedModel(AccountRoles userRole) { if (userRole == AccountRoles.Carer) { _headBackRoute = OBSSecurity.CarerHeadBackRoute; } else if (userRole == AccountRoles.User) { _headBackRoute = OBSSecurity.UserHeadBackRoute; } }
override protected void OnInit(EventArgs e) { base.OnInit(e); AccountRoles accountRoles = new AccountRoles(appEnv.GetConnection()); if (!accountRoles.Authorization(Roles(), User.Identity.Name)) { Page_Error(accountRoles.Message); } }
private bool IsChangeAllowed(AccountRoles role, OrderStatuses nextOrderStatus) { if (role == AccountRoles.RegularUser) { return(nextOrderStatus == OrderStatuses.Canceled || nextOrderStatus == OrderStatuses.Received); } return(nextOrderStatus == OrderStatuses.Processed || nextOrderStatus == OrderStatuses.InRoute || nextOrderStatus == OrderStatuses.Delivered); }
private void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) { string Cmd = "Select * FROM Roles"; SqlDataAdapter DAdpt = new SqlDataAdapter(Cmd, appEnv.GetConnection()); DataSet ds = new DataSet(); DAdpt.Fill(ds, "Roles"); DataTable dt = ds.Tables["Roles"]; foreach (DataRow dr in dt.Rows) { lbRoles.Items.Add(dr["Role"].ToString()); } } else { account = new Account(appEnv.GetConnection()); property = new AccountProperty(appEnv.GetConnection()); accountRoles = new AccountRoles(appEnv.GetConnection()); Page.Validate(); if (Page.IsValid) { try { if (account.GetAccountID(tbUserID.Text) > 0) { lblError.Text = "UserID already in use"; } } catch (Exception) { try { account.Insert(tbUserID.Text, tbPassword.Text, tbEmail.Text); int AccountID = account.GetAccountID(tbUserID.Text); ProcessUserName(AccountID); ProcessAccountRoles(AccountID); } catch (Exception err) { Page_Error("The following error occurred " + err.Message); } Response.Redirect("AdmAcntList.aspx"); } } } }
protected void bnRemove_Click(object sender, System.EventArgs e) { int id = Convert.ToInt32(dr["AccountID"]); AccountRoles roles = new AccountRoles(appEnv.GetConnection()); roles.Remove(id); property.Remove(id); account.Remove(id); Response.Redirect("AdmAcntList.aspx"); }
override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); SqlConnection connection = new AppEnv(Context).GetConnection(); account = new Account(connection); property = new AccountProperty(connection); role = new AccountRoles(connection); }
public async Task UpdateStausTestNegative(AccountRoles accountRole, OrderStatuses previousOrderStatus, OrderStatuses nextStatus) { //Arrange var owner = EntitiesCreationService.GetOwner(); owner.HashedPassword = "******"; var restaurant = EntitiesCreationService.GetRestaurant(); owner.Restaurants = new List <Restaurant>() { restaurant }; owner = await accountsRepository.AddAsync(owner); var account = EntitiesCreationService.GetOwner(); account.HashedPassword = "******"; account.Role = accountRole; var order = EntitiesCreationService.GetOrder(); var orderStatus = EntitiesCreationService.GetOrderStatus(); orderStatus.Status = previousOrderStatus; order.OrderStatuses = new List <OrderStatus>() { orderStatus }; order.RestaurantId = owner.Restaurants[0].RestaurantId; account.Orders = new List <Order>() { order }; account = await accountsRepository.AddAsync(account); try { //Act //Assert await Assert.ThrowsAnyAsync <Exception>(async() => await orderService.UpdateStaus(account.AccountId, account.Orders[0].EntityId, nextStatus)); } finally { //Clear accountsRepository.Remove(account); } }
public async Task <AccountRoles> Create(AccountRoles inputModel) { try { var result = await _unitOfWork.AccountRolesRepository.Add(inputModel); await _unitOfWork.SaveChange(); return(result); } catch (Exception ex) { throw ex; } }
public Account( MailAddress email, Password password, DateTime registrationTime, AccountRoles role, ConfirmationStatus confirmationStatus) { Require.NotNull(email, nameof(email)); Require.NotNull(password, nameof(password)); Email = email; Password = password; RegistrationTime = registrationTime; Profile = new Profile(); Profile.Tags = new HashSet <Tag>(); Role = role; ConfirmationStatus = confirmationStatus; }
public async Task Update(AccountRoles inputModel) { await _unitOfWork.CreateTransaction(); try { await _unitOfWork.AccountRolesRepository.Update(inputModel); await _unitOfWork.Commit(); await _unitOfWork.SaveChange(); } catch (Exception ex) { await _unitOfWork.Rollback(); throw ex; } }
public async Task CreateList(long accountId, List <long> listRoleId) { try { foreach (var roleId in listRoleId) { AccountRoles accountRoles = new AccountRoles(); accountRoles.RoleId = roleId; accountRoles.AccountId = accountId; await _unitOfWork.AccountRolesRepository.Add(accountRoles); await _unitOfWork.SaveChange(); } } catch (Exception ex) { throw ex; } }
public static HashSet <string> ToRoleSet(this AccountRoles roles) { var res = new HashSet <string>(); foreach (AccountRoles token in Enum.GetValues(typeof(AccountRoles))) { if (token == AccountRoles.None) { continue; } if (roles.HasFlag(token)) { res.Add(token.ToString()); } } return(res); }
private static AccountRoles ConvertFromDto(AccountRolesDto rolesDto) { if (rolesDto == null) { return(null); } var accountRole = new AccountRoles { Id = rolesDto.Id, AccountID = rolesDto.AccountID, HotelID = rolesDto.HotelID, RoleID = rolesDto.RoleID }; if ((rolesDto?.CreateTime ?? DateTime.MinValue) > DateTime.MinValue) { accountRole.CreateTime = rolesDto.CreateTime; } if ((rolesDto?.UpdateTime ?? DateTime.MinValue) > DateTime.MinValue) { accountRole.UpdateTime = rolesDto.UpdateTime; } return(accountRole); }
protected void Page_Load(object sender, System.EventArgs e) { aid = Convert.ToInt32(Request.QueryString["AccountID"]); if (aid == 0) { Page_Error("AccountID Missing"); } if (aid == 1) { bnRemove.Visible = false; } account = new Account(appEnv.GetConnection()); property = new AccountProperty(appEnv.GetConnection()); roles = new AccountRoles(appEnv.GetConnection()); dr = account.GetAccountForID(aid); lbUserID.Text = dr["UserName"].ToString(); lbUserName.Text = property.GetValue(aid, "UserName"); lbEmail.Text = dr["Email"].ToString(); DataTable roledt = roles.GetRolesForID(aid); foreach (DataRow drr in roledt.Rows) { lbRoles.Items.Add(drr["Role"].ToString()); } if (roledt.Rows.Count == 0) { lbRoles.Items.Add("User"); } }
public static bool IsInRole(this IPrincipal principal, AccountRoles role) { return((principal as AmpluaPrincipal)?.IsInRole(role) ?? false); }
public void CheckRole(AccountRoles role) { CheckUser(); Try.Condition((role & Context.CurrentUser.Role) > 0, NotEnoughRightsMessageText); }
public AuthorizationAttribute(AccountRoles accountRole) { _accountRole = accountRole; }
public bool IsInRole(string roleId) { var retVal = AccountRoles.Contains(roleId) || AccountRoles.Contains(roleId.ToLowerInvariant()); return(retVal); }
public void CheckRoles(AccountRoles accountRole, long installationID, InInstallationRoles inInstallationRole) { CheckRole(accountRole); CheckRoleInInstallation(installationID, inInstallationRole); }
private void Page_Load(object sender, System.EventArgs e) { bool authorized = false; XmlReader reader = new XmlTextReader(File.OpenRead(Server.MapPath("..\\XMLFiles\\CMAMenu.xml"))); XmlDocument doc = new XmlDocument(); doc.Load(reader); reader.Close(); string expand = Request.QueryString["Expand"]; int ExpandWhich; if (expand == null) { ExpandWhich = -1; } else { ExpandWhich = Convert.ToInt16(expand); } TableCell cell; HyperLink link; XmlNodeList Menus = doc.GetElementsByTagName("Menu"); for (int i = 0; i < Menus.Count; i++) { int currnode = 0; XmlNodeList MenuNodes = Menus[i].ChildNodes; if (MenuNodes[currnode].Name.Equals("authorization")) { AppEnv appEnv = new AppEnv(Context); AccountRoles accountRoles = new AccountRoles(appEnv.GetConnection()); if (accountRoles.Authorization( Roles(MenuNodes[currnode++].InnerText), User.Identity.Name)) { authorized = true; } else { authorized = false; } } else { authorized = true; } if (authorized) { TableRow row = new TableRow(); tblMenu.Rows.Add(row); if (ExpandWhich == i) { cell = new TableCell(); cell.Width = Unit.Percentage(1.0); cell.Controls.Add(AddImage("Images/minus.gif")); row.Cells.Add(cell); link = new HyperLink(); link.Text = MenuNodes[currnode++].InnerText; link.NavigateUrl = "NavBar.aspx?Expand=-1"; cell = new TableCell(); cell.Width = Unit.Percentage(99.0); cell.Controls.Add(link); row.Cells.Add(cell); // start at 1 since 0 is the Menu Name for (int j = currnode; j < MenuNodes.Count; j++) { row = new TableRow(); tblMenu.Rows.Add(row); cell = new TableCell(); cell.Width = Unit.Percentage(1.0); cell.Controls.Add(AddImage("Images/blank.gif")); row.Cells.Add(cell); link = new HyperLink(); link.Text = MenuNodes[j].ChildNodes[0].InnerText; link.NavigateUrl = MenuNodes[j].ChildNodes[1].InnerText; link.Target = "main"; cell = new TableCell(); cell.Width = Unit.Percentage(99.0); cell.Controls.Add(link); row.Cells.Add(cell); } } else { cell = new TableCell(); cell.Width = Unit.Percentage(1.0); cell.Controls.Add(AddImage("Images/plus.gif")); row.Cells.Add(cell); link = new HyperLink(); link.Text = MenuNodes[currnode++].InnerText; link.NavigateUrl = "NavBar.aspx?Expand=" + i; cell = new TableCell(); cell.Width = Unit.Percentage(99.0); cell.Controls.Add(link); row.Cells.Add(cell); } } } }
private static AccountManagement.Account MapAccount(Account dbAccount) { var roles = new AccountRoles(dbAccount.Roles.Select(BuildRoleFromDBRole)); return new AccountManagement.Account(new AccountId(dbAccount.AccountId), new Username(dbAccount.Username), roles); }
public void SetRole(Guid roleId) { AccountRoles.Add(new AccountRole(Id, roleId)); }
public SignUpViewModel(AccountRoles role) { this.Role = role; }
public IAccountBuilder SetRoles(IEnumerable <Guid> roles) { Roles = new AccountRoles(roles); return(this); }
//public ActionResult GetNhaJson(int status, decimal giaTu, decimal giaDen) public ActionResult GetNhaJson(int status) { try { string drawReturn = "1"; int skip = 0; int take = 10; string start = Request.Params["start"]; //Đang hiển thị từ bản ghi thứ mấy string length = Request.Params["length"]; //Số bản ghi mỗi trang string draw = Request.Params["draw"]; //Số lần request bằng ajax (hình như chống cache) string key = Request.Params["search[value]"]; //Ô tìm kiếm string orderDir = Request.Params["order[0][dir]"]; //Trạng thái sắp xếp xuôi hay ngược: asc/desc orderDir = string.IsNullOrEmpty(orderDir) ? "asc" : orderDir; string orderColumn = Request.Params["order[0][column]"]; //Cột nào đang được sắp xếp (cột thứ mấy trong html table) orderColumn = string.IsNullOrEmpty(orderColumn) ? "1" : orderColumn; string orderKey = Request.Params["columns[" + orderColumn + "][data]"]; //Lấy tên của cột đang được sắp xếp orderKey = string.IsNullOrEmpty(orderKey) ? "UpdateDate" : orderKey; if (!string.IsNullOrEmpty(start)) { skip = Convert.ToInt16(start); } if (!string.IsNullOrEmpty(length)) { take = Convert.ToInt16(length); } if (!string.IsNullOrEmpty(draw)) { drawReturn = draw; } //Ghi chú string ghiChu = ""; string objectGhiChu = Request.Params["objectGhiChu"]; if (!string.IsNullOrEmpty(objectGhiChu)) { ghiChu = objectGhiChu.ToString(); } //Quận long quanId = 0; string objectQuan = Request.Params["objectQuan"]; if (!string.IsNullOrEmpty(objectQuan)) { long.TryParse(objectQuan.ToString(), out quanId); } //Đường long duongId = 0; string objectDuong = Request.Params["objectDuong"]; if (!string.IsNullOrEmpty(objectDuong)) { long.TryParse(objectDuong.ToString(), out duongId); } //Mặt tièn float matTienTu = 0; string objectMatTienTu = Request.Params["objectMatTienTu"]; if (!string.IsNullOrEmpty(objectMatTienTu)) { float.TryParse(objectMatTienTu.ToString(), out matTienTu); } float matTienDen = 0; string objectMatTienDen = Request.Params["objectMatTienDen"]; if (!string.IsNullOrEmpty(objectMatTienDen)) { float.TryParse(objectMatTienDen.ToString(), out matTienDen); } if (matTienDen == 0) { matTienDen = float.MaxValue; } //Giá thuê decimal giaThueTu = 0; string objectGiaThueTu = Request.Params["objectGiaThueTu"]; if (!string.IsNullOrEmpty(objectGiaThueTu)) { decimal.TryParse(objectGiaThueTu.ToString(), out giaThueTu); } decimal giaThueDen = 0; string objectGiaThueDen = Request.Params["objectGiaThueDen"]; if (!string.IsNullOrEmpty(objectGiaThueDen)) { decimal.TryParse(objectGiaThueDen.ToString(), out giaThueDen); } if (giaThueDen == 0) { giaThueDen = decimal.MaxValue; } //DTSD tầng 1 float dtsdt1Tu = 0; string objectDTSDT1Tu = Request.Params["objectDTSDT1Tu"]; if (!string.IsNullOrEmpty(objectDTSDT1Tu)) { float.TryParse(objectDTSDT1Tu.ToString(), out dtsdt1Tu); } float dtsdt1Den = 0; string objectDTSDT1Den = Request.Params["objectDTSDT1Den"]; if (!string.IsNullOrEmpty(objectDTSDT1Den)) { float.TryParse(objectDTSDT1Den.ToString(), out dtsdt1Den); } if (dtsdt1Den == 0) { dtsdt1Den = float.MaxValue; } //Trạng thái bài viết string objectStatus = Request.Params["objectStatus"];//Lọc trạng thái bài viết if (!string.IsNullOrEmpty(objectStatus)) { int.TryParse(objectStatus.ToString(), out status); } //Tổng DTSD float tongDTSDTu = 0; string objectTongDTSDTu = Request.Params["objectTongDTSDTu"]; if (!string.IsNullOrEmpty(objectTongDTSDTu)) { float.TryParse(objectTongDTSDTu.ToString(), out tongDTSDTu); } float tongDTSDDen = 0; string objectTongDTSDDen = Request.Params["objectTongDTSDDen"]; if (!string.IsNullOrEmpty(objectTongDTSDDen)) { float.TryParse(objectTongDTSDDen.ToString(), out tongDTSDDen); } if (tongDTSDDen == 0) { tongDTSDDen = float.MaxValue; } Paging paging = new Paging() { TotalRecord = 0, Skip = skip, Take = take, OrderDirection = orderDir }; bool isAdmin = AccountRoles.Any(t => t.RoleId == 1); //o => (key == null ||key == "") && var articles = _repository.GetRepository <Nha>().GetAll(ref paging, orderKey, o => o.TrangThai == status && (ghiChu != "" ? o.GhiChu.Contains(ghiChu) : true) && (quanId != 0 ? o.QuanId == quanId : true) && (duongId != 0 ? o.DuongId == duongId : true) && (matTienTu <= o.MatTienTreoBien && o.MatTienTreoBien <= matTienDen) && (giaThueTu <= o.TongGiaThue && o.TongGiaThue <= giaThueDen) && (dtsdt1Tu <= o.DienTichDatSuDungTang1 && o.DienTichDatSuDungTang1 <= dtsdt1Den) && (tongDTSDTu <= o.TongDienTichSuDung && o.TongDienTichSuDung <= tongDTSDDen) && (isAdmin ? true : o.NguoiPhuTrachId == AccountId)) .Join(_repository.GetRepository <Quan>().GetAll(), b => b.QuanId, e => e.Id, (b, e) => new { Nha = b, Quan = e }) .Join(_repository.GetRepository <Duong>().GetAll(), b => b.Nha.DuongId, g => g.Id, (b, g) => new { Nha = b, Duong = g }).ToList(); //.Join(_repository.GetRepository<CapDoTheoDoi>().GetAll(), b => b.Nha.Nha.CapDoTheoDoiId, y => y.Id, (b, y) => new { Nha = b, CapDoTheoDoi = y }).ToList(); return(Json(new { draw = drawReturn, recordsTotal = paging.TotalRecord, recordsFiltered = paging.TotalRecord, data = articles.Select(o => new { o.Nha.Nha.Id, Quan = o.Nha.Quan.Name, Duong = o.Duong.Name, o.Nha.Nha.TenNguoiLienHeVaiTro, o.Nha.Nha.SoDienThoai, o.Nha.Nha.TongGiaThue, TrangThai = o.Nha.Nha.TrangThai == 0 ? "Chờ duyệt" : "Đã duyệt", MatTien = o.Nha.Nha.MatTienTreoBien, DTSDT1 = o.Nha.Nha.DienTichDatSuDungTang1, TongDTSD = o.Nha.Nha.TongDienTichSuDung //o.Nha.Nha.Nha.Id, //Quan = o.Nha.Nha.Quan.Name, //Duong = o.Nha.Duong.Name, //o.Nha.Nha.Nha.TenNguoiLienHeVaiTro, //o.Nha.Nha.Nha.SoDienThoai, //o.Nha.Nha.Nha.TongGiaThue, //CapDoTheoDoi = o.CapDoTheoDoi.Name, //TrangThai = o.Nha.Nha.Nha.TrangThai == 0 ? "Chờ duyệt" : "Đã duyệt", //MatTien = o.Nha.Nha.Nha.MatTienTreoBien, //DTSDT1 = o.Nha.Nha.Nha.DienTichDatSuDungTang1, //TongDTSD = o.Nha.Nha.Nha.TongDienTichSuDung }) }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { throw; } }
private static AccountManagement.Account MapAccount(Account dbAccount) { var roles = new AccountRoles(dbAccount.Roles.Select(BuildRoleFromDBRole)); return(new AccountManagement.Account(new AccountId(dbAccount.AccountId), new Username(dbAccount.Username), roles)); }