public override void OnActionExecuting(ActionExecutingContext context) { var roleUserList = SessionManager.GetRoleUsers(); if (roleUserList.Count <= 0 && SessionManager.GetLock() == null) { context.Result = new RedirectResult("/Error/Detail?ErrorNo=1"); return; } var roleArray = roleUserList.Select(m => m.RoleID).ToArray(); //页面权限控制 var path = context.HttpContext.Request.Path.ToString(); var privilegeList = _privilegeService.GetUrlPermissionItems(roleUserList[0].UserID, roleArray); PrivilegeDto privilege = null; if (path != "" && privilegeList != null && (privilege = privilegeList.Find(o => o.Url == path)) != null) { context.HttpContext.Items["UrlPermission"] = privilege; } else { context.Result = new RedirectResult("/Error/Detail?ErrorNo=5"); } }
public bool Update(PrivilegeDto dto) { var privilege = Mapper.Map <Privilege>(dto); _privilegeRepository.Update(privilege); return(_privilegeRepository.SaveChanges() > 0); }
public IActionResult Edit(int id, PrivilegeDto privilegeDto) { log.Info(nameof(PrivilegesController.Edit)); if (id != privilegeDto.Id) { log.Warn(nameof(PrivilegesController.Edit) + " id is not equal to privilegeDto.Id"); return(NotFound()); } if (ModelState.IsValid) { try { privilegeService.Update(privilegeDto); } catch (Exception e) { log.Error(e); return(BadRequest()); } return(RedirectToAction(nameof(Index))); } return(View(privilegeDto)); }
public void Update(PrivilegeDto privilegeDto) { var privilege = mapper.Map <PrivilegeDto, Privilege>(privilegeDto); uow.Privileges.Update(privilege); uow.Save(); }
public void AddPatientWithPrivilege() { TestPixServiceClient client = new TestPixServiceClient(); PatientDto patient = new PatientDto(); patient.FamilyName = "Жукин"; patient.GivenName = "Дмитрий"; patient.BirthDate = new DateTime(1983, 01, 07); patient.Sex = 1; patient.IdPatientMIS = "123456789010"; PrivilegeDto privilege = new PrivilegeDto(); privilege.DateStart = new DateTime(1993, 01, 02); privilege.DateEnd = new DateTime(2020, 01, 02); privilege.IdPrivilegeType = 10; patient.Privilege = privilege; client.AddPatient(Global.GUID, "1.2.643.5.1.13.3.25.78.118", patient); if (Global.errors == "") { Assert.Pass(); } else { Assert.Fail(Global.errors); } }
/// <summary> /// 更新 /// </summary> /// <param name="dto"></param> /// <returns></returns> public AjaxResult Update(PrivilegeDto dto) { var flag = _privilegeService.Update(dto); if (!flag) { return(AjaxResult.Error("修改用户失败")); } return(AjaxResult.Success()); }
/// <summary> /// 添加 /// </summary> /// <param name="dto"></param> /// <returns></returns> public AjaxResult Create(PrivilegeDto dto) { var privilege = _privilegeService.Create(dto); if (privilege == null) { return(AjaxResult.Error("添加用户失败")); } return(AjaxResult.Success(privilege.Id)); }
public Privilege Create(PrivilegeDto dto) { Privilege privilege = new Privilege { }; _privilegeRepository.Insert(privilege); if (_privilegeRepository.SaveChanges() > 0) { return(privilege); } return(null); }
public void Update(PrivilegeDto privilegeDto) { var validationResult = privilegeValidator.Validate(privilegeDto); if (!validationResult.IsValid) { throw new ArgumentException(validationResult.Errors.First().ErrorMessage); } var privilege = mapper.Map <PrivilegeDto, Privilege>(privilegeDto); uow.Privileges.Update(privilege); uow.Save(); }
/// <summary> /// 获取当前系统下的所有权限 /// </summary> /// <param name="SystemId"></param> /// <returns></returns> public IList <PrivilegeGroupAllDto> GetAllPrivileges(string SystemId) { IList <PrivilegeGroupAllDto> privileges = new List <PrivilegeGroupAllDto>(); IList <TPrivilegeGroup> privilegeGroups = IocUnity.Get <RepositoryPrivilegeGroup>().GetPrivilegeGroups(SystemId); IList <PrivilegeAllView> privilegeAllViews = IocUnity.Get <RepositoryPrivilegeGroup>().GetAllPrivileges(SystemId); int i = 0; foreach (TPrivilegeGroup group in privilegeGroups) { IList <PrivilegeDto> privilegeDtos = new List <PrivilegeDto>(); for (int j = i; j < privilegeAllViews.Count; j++) { if (privilegeAllViews[j].PrivilegeId != null) { PrivilegeDto privilegeDto = new PrivilegeDto { Id = privilegeAllViews[j].PrivilegeId, Code = privilegeAllViews[j].PrivilegeCode, OriginalCode = privilegeAllViews[j].OriginalCode, Name = privilegeAllViews[j].PrivilegeName, CreateTime = privilegeAllViews[j].PrivilegeCreateTime, UpdateTime = privilegeAllViews[j].PrivilegeUpdateTime, GroupId = privilegeAllViews[j].GroupId, Instruction = privilegeAllViews[j].Instruction }; privilegeDtos.Add(privilegeDto); } if (j + 1 == privilegeAllViews.Count || privilegeAllViews[j + 1].GroupId != privilegeAllViews[j].GroupId) { i = j + 1; break; } } privileges.Add(new PrivilegeGroupAllDto { Id = group.Id, Name = group.Name, UpdateTime = group.UpdateTime, CreateTime = group.CreateTime, Privileges = privilegeDtos }); } return(privileges); }
static public TestPrivilege BuildTestPrivilegeFromDataBase(string idPerson) { using (SqlConnection connection = Global.GetSqlConnection()) { string findPatient = "SELECT TOP(1) * FROM Privilege WHERE IdPrivilege = (SELECT MAX(IdPrivilege) FROM Privilege WHERE IdPerson = '" + idPerson + "')"; SqlCommand person = new SqlCommand(findPatient, connection); using (SqlDataReader privilegeReader = person.ExecuteReader()) { while (privilegeReader.Read()) { PrivilegeDto privilege = new PrivilegeDto(); privilege.DateStart = Convert.ToDateTime(privilegeReader["DateStart"]); privilege.DateEnd = Convert.ToDateTime(privilegeReader["DateEnd"]); privilege.IdPrivilegeType = Convert.ToByte(privilegeReader["IdPrivilegeType"]); TestPrivilege p = new TestPrivilege(privilege); return(p); } } } return(null); }
public static TestPrivilege BuildTestPrivilegeFromDataBase(string idPerson) { using (SqlConnection connection = Global.GetSqlConnection()) { string findPatient = "SELECT TOP(1) * FROM Privilege WHERE IdPrivilege = (SELECT MAX(IdPrivilege) FROM Privilege WHERE IdPerson = '" + idPerson + "')"; SqlCommand person = new SqlCommand(findPatient, connection); using (SqlDataReader privilegeReader = person.ExecuteReader()) { while (privilegeReader.Read()) { PrivilegeDto privilege = new PrivilegeDto(); privilege.DateStart = Convert.ToDateTime(privilegeReader["DateStart"]); privilege.DateEnd = Convert.ToDateTime(privilegeReader["DateEnd"]); privilege.IdPrivilegeType = Convert.ToByte(privilegeReader["IdPrivilegeType"]); TestPrivilege p = new TestPrivilege(privilege); return p; } } } return null; }
public PrivilegeServiceTests() { var mockRepository = new Mock <IRepository <Privilege, int> >(); var mockUnitOfWork = new Mock <IUnitOfWork>(); fakePrivileges = new List <Privilege> { new Privilege { Id = 1, Name = "Priv1", Coefficient = 0M }, new Privilege { Id = 2, Name = "Priv2", Coefficient = 0.3M }, new Privilege { Id = 3, Name = "Priv3", Coefficient = 1M } }; privilegeDto = new PrivilegeDto { Id = 4, Name = "Priv4", Coefficient = 0.3452M }; mockRepository.Setup(m => m.GetAll()).Returns(fakePrivileges.AsQueryable); mockRepository.Setup(m => m.Get(It.IsAny <int>())) .Returns <int>(id => fakePrivileges.Single(t => t.Id == id)); mockRepository.Setup(r => r.Create(It.IsAny <Privilege>())) .Callback <Privilege>(t => fakePrivileges.Add(privilege = t)); mockRepository.Setup(r => r.Update(It.IsAny <Privilege>())) .Callback <Privilege>(t => privilege = t); mockRepository.Setup(x => x.Delete(It.IsAny <int>())) .Callback <int>(id => fakePrivileges.Remove(fakePrivileges.Single(t => t.Id == id))); mockUnitOfWork.Setup(m => m.Privileges).Returns(mockRepository.Object); privilegeService = new PrivilegeService(mockUnitOfWork.Object); }
public IActionResult Create(PrivilegeDto privilegeDto) { log.Info(nameof(PrivilegesController.Create)); try { if (ModelState.IsValid) { privilegeService.Create(privilegeDto); return(RedirectToAction(nameof(Index))); } return(View(privilegeDto)); } catch (Exception e) { log.Error(e); return(BadRequest()); } }
protected override bool AuthorizeCore(HttpContextBase httpContext) { if (SessionManager.GetRoles() == null && SessionManager.GetLock() == null) { sessionUser = true; return(false); } //页面权限控制 var roleUser = SessionManager.GetRoles(); var path = HttpContext.Current.Request.Path.ToString(); var privilegeList = _privilegeService.GetUrlPermissionItems(roleUser.UserID, roleUser.RolesID); PrivilegeDto privilege = null; if (path != "" && privilegeList != null && (privilege = privilegeList.Find(o => o.Url == path)) != null) { httpContext.Items["UrlPermission"] = privilege; return(true); } return(false); }
public TestPrivilege(PrivilegeDto p) { privilege = p; }
public void AddFullPatient() { TestPixServiceClient client = new TestPixServiceClient(); PatientDto patient = new PatientDto(); patient.BirthDate = new DateTime(1983, 01, 07); patient.DeathTime = new DateTime(2020, 02, 15); patient.FamilyName = "Жукин"; patient.GivenName = "Дмитрий"; patient.IdBloodType = 1; patient.IdLivingAreaType = 1; patient.IdPatientMIS = "123456789010"; patient.MiddleName = "Артемович"; patient.Sex = 1; patient.SocialGroup = 2; patient.SocialStatus = "2.11"; PixServise.DocumentDto document = new PixServise.DocumentDto(); document.IdDocumentType = 14; document.DocS = "1311"; document.DocN = "113131"; document.ExpiredDate = new DateTime(1999, 11, 12); document.IssuedDate = new DateTime(2012, 11, 12); document.ProviderName = "УФМС"; document.RegionCode = "1221"; patient.Documents = new PixServise.DocumentDto[] { document }; PixServise.AddressDto address = new PixServise.AddressDto(); address.IdAddressType = 1; address.StringAddress = "Улица Ленина 47"; address.Street = "01000001000000100"; address.Building = "1"; address.City = "0100000000000"; address.Appartment = "1"; address.PostalCode = 1; address.GeoData = "1"; PixServise.AddressDto address2 = new PixServise.AddressDto(); address2.IdAddressType = 2; address2.StringAddress = "Улица Партизанская 47"; address2.Street = "01000001000000100"; address2.Building = "1"; address2.City = "0100000000000"; address2.Appartment = "1"; address2.PostalCode = 1; address2.GeoData = "1"; patient.Addresses = new PixServise.AddressDto[] { address, address2 }; BirthPlaceDto birthplace = new BirthPlaceDto(); birthplace.City = "Тутинск"; birthplace.Country = "маленькая"; birthplace.Region = "БОЛЬШОЙ"; patient.BirthPlace = birthplace; ContactDto contact = new ContactDto(); contact.IdContactType = 1; contact.ContactValue = "89626959434"; ContactDto contact2 = new ContactDto(); contact2.IdContactType = 1; contact2.ContactValue = "89525959544"; patient.Contacts = new ContactDto[] { contact, contact2 }; PixServise.JobDto job = new PixServise.JobDto(); job.OgrnCode = "0100000000000"; // некорректный код job.CompanyName = "OOO 'МИГ'"; job.Sphere = "Я"; job.Position = "Я"; job.DateStart = new DateTime(2003, 1, 1); job.DateEnd = new DateTime(2004, 1, 1); patient.Job = job; PrivilegeDto privilege = new PrivilegeDto(); privilege.DateStart = new DateTime(1993, 01, 02); privilege.DateEnd = new DateTime(2020, 01, 02); privilege.IdPrivilegeType = 10; patient.Privilege = privilege; client.AddPatient(Global.GUID, "1.2.643.5.1.13.3.25.78.118", patient); if (Global.errors == "") Assert.Pass(); else Assert.Fail(Global.errors); }
public void AddPatientWithPrivilege() { TestPixServiceClient client = new TestPixServiceClient(); PatientDto patient = new PatientDto(); patient.FamilyName = "Жукин"; patient.GivenName = "Дмитрий"; patient.BirthDate = new DateTime(1983, 01, 07); patient.Sex = 1; patient.IdPatientMIS = "123456789010"; PrivilegeDto privilege = new PrivilegeDto(); privilege.DateStart = new DateTime(1993, 01, 02); privilege.DateEnd = new DateTime(2020, 01, 02); privilege.IdPrivilegeType = 10; patient.Privilege = privilege; client.AddPatient(Global.GUID, "1.2.643.5.1.13.3.25.78.118", patient); if (Global.errors == "") Assert.Pass(); else Assert.Fail(Global.errors); }
public void AddFullPatient() { TestPixServiceClient client = new TestPixServiceClient(); PatientDto patient = new PatientDto(); patient.BirthDate = new DateTime(1983, 01, 07); patient.DeathTime = new DateTime(2020, 02, 15); patient.FamilyName = "Жукин"; patient.GivenName = "Дмитрий"; patient.IdBloodType = 1; patient.IdLivingAreaType = 1; patient.IdPatientMIS = "123456789010"; patient.MiddleName = "Артемович"; patient.Sex = 1; patient.SocialGroup = 2; patient.SocialStatus = "2.11"; PixServise.DocumentDto document = new PixServise.DocumentDto(); document.IdDocumentType = 14; document.DocS = "1311"; document.DocN = "113131"; document.ExpiredDate = new DateTime(1999, 11, 12); document.IssuedDate = new DateTime(2012, 11, 12); document.ProviderName = "УФМС"; document.RegionCode = "1221"; patient.Documents = new PixServise.DocumentDto[] { document }; PixServise.AddressDto address = new PixServise.AddressDto(); address.IdAddressType = 1; address.StringAddress = "Улица Ленина 47"; address.Street = "01000001000000100"; address.Building = "1"; address.City = "0100000000000"; address.Appartment = "1"; address.PostalCode = 1; address.GeoData = "1"; PixServise.AddressDto address2 = new PixServise.AddressDto(); address2.IdAddressType = 2; address2.StringAddress = "Улица Партизанская 47"; address2.Street = "01000001000000100"; address2.Building = "1"; address2.City = "0100000000000"; address2.Appartment = "1"; address2.PostalCode = 1; address2.GeoData = "1"; patient.Addresses = new PixServise.AddressDto[] { address, address2 }; BirthPlaceDto birthplace = new BirthPlaceDto(); birthplace.City = "Тутинск"; birthplace.Country = "маленькая"; birthplace.Region = "БОЛЬШОЙ"; patient.BirthPlace = birthplace; ContactDto contact = new ContactDto(); contact.IdContactType = 1; contact.ContactValue = "89626959434"; ContactDto contact2 = new ContactDto(); contact2.IdContactType = 1; contact2.ContactValue = "89525959544"; patient.Contacts = new ContactDto[] { contact, contact2 }; PixServise.JobDto job = new PixServise.JobDto(); job.OgrnCode = "0100000000000"; // некорректный код job.CompanyName = "OOO 'МИГ'"; job.Sphere = "Я"; job.Position = "Я"; job.DateStart = new DateTime(2003, 1, 1); job.DateEnd = new DateTime(2004, 1, 1); patient.Job = job; PrivilegeDto privilege = new PrivilegeDto(); privilege.DateStart = new DateTime(1993, 01, 02); privilege.DateEnd = new DateTime(2020, 01, 02); privilege.IdPrivilegeType = 10; patient.Privilege = privilege; client.AddPatient(Global.GUID, "1.2.643.5.1.13.3.25.78.118", patient); if (Global.errors == "") { Assert.Pass(); } else { Assert.Fail(Global.errors); } }