public static bool ModifyBaseData(BaseDataEntity baseDataEntity) { int result = 0; if (baseDataEntity != null) { BaseDataRepository mr = new BaseDataRepository(); BaseDataInfo baseDataInfo = TranslateBaseDataInfo(baseDataEntity); if (baseDataEntity.ID > 0) { result = mr.ModifyData(baseDataInfo); } else { baseDataInfo.CreateDate = DateTime.Now; result = mr.CreateNew(baseDataInfo); } List <BaseDataInfo> miList = mr.GetAllData();//刷新缓存 Cache.Add("BaseDataALL", miList); } return(result > 0); }
public MedicineBusinesslogic(BaseDataRepository dataAccessObj) { dataAccess = dataAccessObj; medicineList.Add(new Medicine() { Id = 1, Name = "Medicine1", Brand = "Brand1", ExpiryDate = new DateTime(2021, 07, 22).ToString(), Notes = "This is Brand1", Price = 302.08, Quantity = 10 }); medicineList.Add(new Medicine() { Id = 2, Name = "Medicine2", Brand = "Brand2", ExpiryDate = new DateTime(2021, 03, 22).ToString(), Notes = "This is Brand2", Price = 402.79, Quantity = 4 }); medicineList.Add(new Medicine() { Id = 3, Name = "Medicine3", Brand = "Brand3", ExpiryDate = new DateTime(2021, 04, 22).ToString(), Notes = "This is Brand3", Price = 102.39, Quantity = 2 }); medicineList.Add(new Medicine() { Id = 4, Name = "Medicine4", Brand = "Brand4", ExpiryDate = new DateTime(2021, 08, 22).ToString(), Notes = "This is Brand4", Price = 702.19, Quantity = 1 }); medicineList.Add(new Medicine() { Id = 5, Name = "Medicine5", Brand = "Brand5", ExpiryDate = new DateTime(2021, 11, 22).ToString(), Notes = "This is Brand5", Price = 52.34, Quantity = 7 }); }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { var userManager = context.OwinContext.GetUserManager <ApplicationUserManager>(); ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password); if (user == null) { context.SetError("invalid_grant", "The user name or password is incorrect."); return; } var repo = new BaseDataRepository(DataContext.Create()); ClaimsIdentity oAuthIdentity = await repo.GenerateUserIdentityAsync(user, userManager, OAuthDefaults.AuthenticationType); ClaimsIdentity cookiesIdentity = await repo.GenerateUserIdentityAsync(user, userManager, CookieAuthenticationDefaults.AuthenticationType); AuthenticationProperties properties = CreateProperties(user.UserName); AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties); context.Validated(ticket); context.Request.Context.Authentication.SignIn(cookiesIdentity); }
public static BaseDataEntity GetBaseDataById(int id) { BaseDataEntity result = new BaseDataEntity(); BaseDataRepository mr = new BaseDataRepository(); BaseDataInfo info = mr.GetBaseDataByKey(id); result = TranslateBaseDataEntity(info); return(result); }
public static long CreateAttachment(AttachmentEntity attachmentInfo) { long result = 0; BaseDataRepository mr = new BaseDataRepository(); AttachmentInfo attachment = TranslateAttachmentEntity(attachmentInfo); attachment.CreateDate = DateTime.Now; result = mr.CreateNewAttachment(attachment); return(result); }
public static void AddVerificationCode(VerificationCodeEntity entity) { BaseDataRepository mr = new BaseDataRepository(); VerificationCodeInfo info = new VerificationCodeInfo(); info.Mobile = entity.Mobile; info.Email = entity.Email; info.VCode = entity.VCode; info.Status = entity.Status; info.DeadLine = entity.DeadLine; mr.AddVerificationCode(info); }
public async Task <IHttpActionResult> GetExternalLogin(string provider, string error = null) { if (error != null) { return(Redirect(Url.Content("~/") + "#error=" + Uri.EscapeDataString(error))); } if (!User.Identity.IsAuthenticated) { return(new ChallengeResult(provider, this)); } ExternalLoginData externalLogin = ExternalLoginData.FromIdentity(User.Identity as ClaimsIdentity); if (externalLogin == null) { return(InternalServerError()); } if (externalLogin.LoginProvider != provider) { Authentication.SignOut(DefaultAuthenticationTypes.ExternalCookie); return(new ChallengeResult(provider, this)); } ApplicationUser user = await UserManager.FindAsync(new UserLoginInfo(externalLogin.LoginProvider, externalLogin.ProviderKey)); bool hasRegistered = user != null; if (hasRegistered) { Authentication.SignOut(DefaultAuthenticationTypes.ExternalCookie); var repo = new BaseDataRepository(DataContext.Create()); ClaimsIdentity oAuthIdentity = await repo.GenerateUserIdentityAsync(user, UserManager, OAuthDefaults.AuthenticationType); ClaimsIdentity cookieIdentity = await repo.GenerateUserIdentityAsync(user, UserManager, CookieAuthenticationDefaults.AuthenticationType); AuthenticationProperties properties = ApplicationOAuthProvider.CreateProperties(user.UserName); Authentication.SignIn(properties, oAuthIdentity, cookieIdentity); } else { IEnumerable <Claim> claims = externalLogin.GetClaims(); ClaimsIdentity identity = new ClaimsIdentity(claims, OAuthDefaults.AuthenticationType); Authentication.SignIn(identity); } return(Ok()); }
public static VerificationCodeEntity CheckVerificationCode(string telephone, string vcode) { BaseDataRepository mr = new BaseDataRepository(); VerificationCodeInfo info = mr.CheckVerificationCode(telephone, vcode); VerificationCodeEntity entity = new VerificationCodeEntity(); if (info != null) { entity.Mobile = info.Mobile; entity.Email = info.Email; entity.VCode = info.VCode; entity.Status = info.Status; entity.DeadLine = info.DeadLine; } return(entity); }
public async Task <IAppBaseData> Create() { try { var crmService = StartupHelper.CreateCrmService(); IBaseDataRepository baseDataRepository = new BaseDataRepository(); IBaseDataService baseDataService = new BaseDataService(crmService, baseDataRepository); IAppBaseData app = new AppBaseData(baseDataService); return(app); } catch (Exception ex) { throw ex; } }
public static List <BaseDataEntity> GetBaseDataByRule(string desc) { List <BaseDataEntity> all = new List <BaseDataEntity>(); BaseDataRepository mr = new BaseDataRepository(); List <BaseDataInfo> miList = mr.GetBaseDataByRule(desc); if (!miList.IsEmpty()) { foreach (BaseDataInfo mInfo in miList) { BaseDataEntity BaseDataEntity = TranslateBaseDataEntity(mInfo); all.Add(BaseDataEntity); } } return(all); }
public static List <AttachmentEntity> GetAttachmentInfoByKyes(string ids) { List <AttachmentEntity> all = new List <AttachmentEntity>(); BaseDataRepository mr = new BaseDataRepository(); List <AttachmentInfo> miList = mr.GetAttachments(ids); if (!miList.IsEmpty()) { foreach (AttachmentInfo mInfo in miList) { AttachmentEntity attachEntity = TranslateAttachmentInfo(mInfo); all.Add(attachEntity); } } return(all); }
public static List <City> GetAllHasCity() { List <City> result = Cache.Get <List <City> >("GetAllHasCity") ?? new List <City>(); if (result.IsEmpty()) { BaseDataRepository mr = new BaseDataRepository(); List <CityInfo> cInfo = mr.GetAllHasCity(); foreach (var item in cInfo) { City c = new City(); c.CityID = item.CityID; c.CityName = item.CityName; c.ProvinceID = item.ProvinceID; result.Add(c); } Cache.Add("GetAllHasCity", result); } return(result); }
public static List <Province> GetAllProvince() { List <Province> result = Cache.Get <List <Province> >("ProvinceALL") ?? new List <Province>(); if (result.IsEmpty()) { BaseDataRepository mr = new BaseDataRepository(); List <ProvinceInfo> pInfo = mr.GetAllProvince(); foreach (var item in pInfo) { Province p = new Province(); p.ProvinceID = item.ProvinceID; p.ProvinceName = item.ProvinceName; result.Add(p); } Cache.Add("ProvinceALL", result); } return(result); }
public static List <BaseDataEntity> GetBaseDataAll() { List <BaseDataEntity> all = new List <BaseDataEntity>(); BaseDataRepository mr = new BaseDataRepository(); List <BaseDataInfo> miList = mr.GetAllData();//Cache.Get<List<BaseDataInfo>>("BaseDataALLN"); //if (miList.IsEmpty()) //{ // miList = mr.GetAllData(); // Cache.Add("BaseDataALL", miList); //} if (!miList.IsEmpty()) { foreach (BaseDataInfo mInfo in miList) { BaseDataEntity BaseDataEntity = TranslateBaseDataEntity(mInfo); all.Add(BaseDataEntity); } } return(all); }
public static List <City> GetAllCity() { List <City> result = Cache.Get <List <City> >("CityALL") ?? new List <City>(); List <Province> allProvinces = GetAllProvince(); if (result.IsEmpty()) { BaseDataRepository mr = new BaseDataRepository(); List <CityInfo> cInfo = mr.GetAllCity(); foreach (var item in cInfo) { City c = new City(); c.CityID = item.CityID; c.CityName = item.CityName; c.ProvinceID = item.ProvinceID; c.ProvinceInfo = allProvinces.FirstOrDefault(t => t.ProvinceID == item.ProvinceID) ?? new Province(); result.Add(c); } Cache.Add("CityALL", result); } return(result); }
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 public void ConfigureAuth(IAppBuilder app) { var container = CastleHelper.Container; container.Register( Component .For <IAppBuilder>() .Instance(app), Component .For <IDbContext>() .ImplementedBy <DataContext>() .DependsOn(Dependency.OnValue <string>("DefaultConnection")) .LifestyleTransient(), Component .For <IUserStore <ApplicationUser, int> >() .ImplementedBy <UserStore <ApplicationUser, Role, int, UserLogin, UserRole, UserClaim> >() .DependsOn(Dependency.OnComponent <DbContext, DataContext>()) .LifestyleTransient(), Component .For <ApplicationUserManager>() .UsingFactoryMethod(kernel => CreateCustomUserManager( kernel.Resolve <IUserStore <ApplicationUser, int> >(), kernel.Resolve <IAppBuilder>())) .LifestyleTransient(), Component .For <IRoleStore <Role, int> >() .ImplementedBy <RoleStore <Role, int, UserRole> >() .DependsOn(Dependency.OnComponent <DbContext, DataContext>()) .LifestyleTransient(), //Component // .For<ApplicationRoleManager>() // .LifestyleTransient(), Component .For <IAuthenticationManager>() .UsingFactoryMethod(kernel => HttpContext.Current.GetOwinContext().Authentication) .LifestyleTransient() //Component // .For<ApplicationSignInManager>() // .LifestyleTransient()); , Component .For <IDataSerializer <AuthenticationTicket> >() .ImplementedBy <TicketSerializer>() , Component .For <ISecureDataFormat <AuthenticationTicket> >() .ImplementedBy <TicketDataFormat>() , Component .For <IDataProtector>() .UsingFactoryMethod(kernel => new DpapiDataProtectionProvider().Create("ASP.NET Identity")) ); // builder.RegisterType<TicketSerializer>() //.As<IDataSerializer<AuthenticationTicket>>(); // builder.Register(c => new DpapiDataProtectionProvider().Create("ASP.NET Identity")) // .As<IDataProtector>(); app.CreatePerOwinContext(() => container.Resolve <ApplicationUserManager>()); // Configure the db context and user manager to use a single instance per request //app.CreatePerOwinContext(DataContext.Create); //app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); BaseDataRepository repo = new BaseDataRepository(DataContext.Create()); // Enable the application to use a cookie to store information for the signed in user // and to use a cookie to temporarily store information about a user logging in with a third party login provider app.UseCookieAuthentication(new CookieAuthenticationOptions { Provider = new CookieAuthenticationProvider { OnValidateIdentity = SecurityStampValidator .OnValidateIdentity <ApplicationUserManager, ApplicationUser, int>( validateInterval: TimeSpan.FromMinutes(30), regenerateIdentityCallback: (manager, user) => repo.GenerateUserIdentityAsync(user, manager, DefaultAuthenticationTypes.ApplicationCookie), getUserIdCallback: (id) => (id.GetUserId <int>())) } }); app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); // Configure the application for OAuth based flow PublicClientId = "self"; OAuthOptions = new OAuthAuthorizationServerOptions { TokenEndpointPath = new PathString("/Token"), Provider = new ApplicationOAuthProvider(PublicClientId), AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"), AccessTokenExpireTimeSpan = TimeSpan.FromDays(1), // In production mode set AllowInsecureHttp = false AllowInsecureHttp = true, }; // Enable the application to use bearer tokens to authenticate users app.UseOAuthBearerTokens(OAuthOptions); // Uncomment the following lines to enable logging in with third party login providers //app.UseMicrosoftAccountAuthentication( // clientId: "", // clientSecret: ""); //app.UseTwitterAuthentication( // consumerKey: "", // consumerSecret: ""); //app.UseFacebookAuthentication( // appId: "", // appSecret: ""); //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() //{ // ClientId = "", // ClientSecret = "" //}); }
public static void GetAllTest() { BaseDataRepository mr = new BaseDataRepository(); DataSet ds = mr.GetAllTest(); DataTable dt = ds.Tables[0]; List <Province> proList = GetAllProvince(); List <City> cList = GetAllCity(); List <CarrierEntity> carrList = CarrierService.GetCarrierAll(); List <StorageEntity> storageList = StorageService.GetStorageAll(); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { //ReceiverRepository mrs = new ReceiverRepository(); //ReceiverInfo info = new ReceiverInfo(); //List<CustomerEntity> listCus = CustomerService.GetCustomerByRule(dr["客户名称"].ToString(), -1); //if (listCus != null && listCus.Count > 0) //{ // info.CustomerID = listCus[0].CustomerID; //} //info.ReceiverName = dr["门店名称"].ToString(); //info.ReceiverNo = dr["门店编号"].ToString(); //info.Address = dr["门店地址"].ToString(); //Province pInfo = proList.Find(p => p.ProvinceName.Equals(dr["所属省份"].ToString().Replace("省", "").Replace("市", ""))); //info.ProvinceID = pInfo != null ? pInfo.ProvinceID : 0; //info.ReceiverType = "门店"; //City cInfo = cList.Find(p => p.CityName.Equals(dr["所属市区"].ToString().Replace("市", ""))); //info.CityID = cInfo != null ? cInfo.CityID : 0; //info.Address = dr["门店地址"].ToString(); //info.OperatorID = 1; //info.Remark = dr["门店描述"].ToString(); //CarrierEntity centity = carrList.Find(p => p.CarrierShortName.Equals(dr["默认承运商简称"].ToString())); //info.DefaultCarrierID = centity != null ? centity.CarrierID : 0; //StorageEntity sEntity = storageList.Find(p => p.StorageName.Equals(dr["默认出库仓"])); //info.DefaultStorageID = sEntity != null ? sEntity.StorageID : 0; //info.Status = 1; //info.CreateDate = DateTime.Now; //info.ChangeDate = DateTime.Now; //long id = mrs.CreateNew(info); List <ReceiverEntity> list = ReceiverService.GetReceiverByRule(dr["门店名称"].ToString(), "", "", -1); long id = list != null && list.Count > 0 ? list[0].ReceiverID : 0; ContactRepository cr = new ContactRepository(); ContactInfo contact = new ContactInfo(); if (!string.IsNullOrEmpty(dr["联系人"].ToString()) || !string.IsNullOrEmpty(dr["联系方式"].ToString())) { contact.ContactName = dr["联系人"].ToString(); contact.Mobile = dr["联系方式"].ToString(); contact.Telephone = dr["联系方式"].ToString(); contact.Email = ""; contact.Remark = ""; contact.UnionType = UnionType.Receiver.ToString();//客户 contact.UnionID = id; contact.CreateDate = DateTime.Now; contact.ChangeDate = DateTime.Now; cr.CreateNew(contact); } } } }
public static void Remove(int id) { BaseDataRepository mr = new BaseDataRepository(); mr.Remove(id); }