/// <summary> /// 将指定的商品归类到指定的商品分类中。 /// </summary> /// <param name="product">需要归类的商品。</param> /// <param name="category">商品分类。</param> /// <returns>用以表述商品及其分类之间关系的实体。</returns> public Categorization Categorize(Product product, Category category) { if (product == null) { throw new ArgumentNullException("product"); } if (category == null) { throw new ArgumentNullException("category"); } var categorization = categorizationRepository.Find(Specification <Categorization> .Eval(c => c.ProductID == product.ID)); if (categorization == null) { categorization = Categorization.CreateCategorization(product, category); categorizationRepository.Add(categorization); } else { categorization.CategoryID = category.ID; categorizationRepository.Update(categorization); } repositoryContext.Commit(); return(categorization); }
public User AddUser(User user) { _context.Users.Add(user); _context.Commit(); return(user); }
/// <summary> /// 创建订单,涉及到的操作有2个:1. 把购物车中的项中购物车移除; 2.创建一个订单。 /// 这两个操作必须同时完成或失败。 /// </summary> /// <param name="user"></param> /// <param name="shoppingCart"></param> /// <returns></returns> public Order CreateOrder(User user, ShoppingCart shoppingCart) { var order = new Order(); var shoppingCartItems = _shoppingCartItemRepository.GetAll( new ExpressionSpecification <ShoppingCartItem>(s => s.ShoopingCart.Id == shoppingCart.Id)); if (shoppingCartItems == null || !shoppingCartItems.Any()) { throw new InvalidOperationException("购物篮中没有任何物品"); } order.OrderItems = new List <OrderItem>(); foreach (var shoppingCartItem in shoppingCartItems) { var orderItem = shoppingCartItem.ConvertToOrderItem(); orderItem.Order = order; order.OrderItems.Add(orderItem); _shoppingCartItemRepository.Remove(shoppingCartItem); } order.User = user; order.Status = OrderStatus.Paid; _orderRepository.Add(order); _repositoryContext.Commit(); return(order); }
public void ChangePassword(string oldPwd, string newPwd) { if (string.IsNullOrEmpty(oldPwd)) { throw new ArgumentNullException("旧密码不能为空"); } if (string.IsNullOrEmpty(newPwd)) { throw new ArgumentNullException("新密码不能为空"); } Blog blog = blogRepository.GetFirstItem(); if (blog == null) { throw new SQBlogException("不存在Blog信息"); } if (DES.DesEncrypt(oldPwd) != blog.Password) { throw new SQBlogException("旧密码不匹配"); } blog.ChangeBlogPassword(DES.DesEncrypt(newPwd)); blogRepository.Update(blog); repositoryContext.Commit(); }
public void Handle(InitiateThirdPartyProcessorPayment command) { var items = command.Items.Select(t => new PaymentItem(t.Description, t.Amount)).ToList(); var processor = new PaymentProcessor(command.PaymentId, command.PaymentSourceId, command.Description, command.TotalAmount, items); context.RegisterNew(processor.Payment); context.Commit(); }
/// <summary> /// 将活动指向消费者角色 /// </summary> /// <param name="hotelPromotionId"></param> /// <param name="CustomerRoleID"></param> public void AssignCustomerRole(Guid hotelPromotionId, Guid CustomerRoleID) { HotelPromotion hotelPromotion = hotelPromotionRepository.GetByKey(hotelPromotionId); CustomerRole customerRole = customerRoleRepository.GetByKey(CustomerRoleID); hotelPromotion.CustomerRoles.Add(customerRole); hotelPromotionRepository.Update(hotelPromotion); repositoryContext.Commit(); }
/// <summary> /// 将活动指向房间分类 /// </summary> /// <param name="hotelPromotionId"></param> /// <param name="HotelRoomCategoryID"></param> public void AssignHotelRoomCategory(Guid hotelPromotionId, Guid HotelRoomCategoryID) { HotelPromotion hotelPromotion = hotelPromotionRepository.GetByKey(hotelPromotionId); HotelRoomCategory hotelRoomCategory = hotelRoomCategoryRepository.GetByKey(HotelRoomCategoryID); hotelPromotion.HotelRoomCategorys.Add(hotelRoomCategory); hotelPromotionRepository.Update(hotelPromotion); repositoryContext.Commit(); }
/// <summary> /// 将酒店指向分类 /// </summary> /// <param name="hotelID"></param> /// <param name="categoryID"></param> public void AssignCategory(Guid hotelID, Guid categoryID) { Hotel hotel = hotelRepository.GetByKey(hotelID); HotelCategory hotelCategory = hotelCategoryRepository.GetByKey(categoryID); hotel.HotelCategorys.Add(hotelCategory); hotelRepository.Update(hotel); repositoryContext.Commit(); }
public void MongoDBRepositoryTests_FindAllByAscendingSorting() { List <Customer> customers = new List <Customer>(); for (int i = 0; i < 100; i++) { customers.Add(new Customer { FirstName = "sunny" + i.ToString(), LastName = "chen" + i.ToString(), Birth = DateTime.Now.AddDays(-i), Email = "sunnychen" + i.ToString() + "@163.com", Password = i.ToString(), Sequence = i, ID = Guid.NewGuid(), Username = "******" + i.ToString() }); } IRepositoryContext context = ServiceLocator.Instance.GetService <IRepositoryContext>(); IRepository <Customer> customerRepository = ServiceLocator.Instance.GetService <IRepository <Customer> >(new { context = context }); foreach (var customer in customers) { customerRepository.Add(customer); } context.Commit(); var foundCustomers = customerRepository.FindAll(sp => sp.Sequence, SortOrder.Ascending); Assert.AreEqual(100, foundCustomers.Count()); var firstCustomer = foundCustomers.First(); Assert.AreEqual("sunny0", firstCustomer.FirstName); }
public UserPasswordHistory SaveUserPreviousPassword(UserPasswordHistory userPassword) { _context.UserPasswordHistory.Add(userPassword); _context.Commit(); return(userPassword); }
public bool SaveImage(Image image) { _context.Images.Add(image); _context.Commit(); return(true); }
public void Test_CRUD_Item() { using (IRepositoryContext ctx = ServiceLocator.Instance.GetService <IRepositoryContext>("DapperRepositoryContext")) { IPostRepository postRep = (IPostRepository)ctx.GetRepository <Post>(); Post p1 = new Post(); p1.AuthorId = 1000; p1.TopicId = 1000; p1.Content = "Test CRUD Add Item" + Utils.GetUniqueIdentifier(5); p1.Status = new PostStatus(); p1.Status.InternalId = Guid.NewGuid(); p1.Status.InternalStatus = "NEW"; postRep.Add(p1); Post p2 = postRep.FindByKey(1017); p2.Content = "Test CRUD Update Item" + Utils.GetUniqueIdentifier(5); p2.Status.InternalStatus = "MODIFIED"; postRep.Update(p2); Post p3 = postRep.FindByKey(1038); postRep.Delete(p3); ctx.Commit(); } }
public Link SaveLink(Link link) { _repositoryContext.Links.Add(link); _repositoryContext.Commit(); return(link); }
public void AssignRole(Guid userID, Guid roleID) { AppUser appUser = appUserRepository.GetByKey(userID); appUser.AppRoleId = roleID; appUserRepository.Update(appUser); repositoryContext.Commit(); }
public void AssignRole(Guid userID, Guid roleID) { HotelUser hotelUser = hotelUserRepository.GetByKey(userID); hotelUser.HotelRoleId = roleID; hotelUserRepository.Update(hotelUser); repositoryContext.Commit(); }
public void AssignRole(Guid userID, Guid roleID) { Customer customer = customerRepository.GetByKey(userID); customer.CustomerRoleId = roleID; customerRepository.Update(customer); repositoryContext.Commit(); }
/// <summary> /// 将房间指向分类 /// </summary> /// <param name="RoomID"></param> /// <param name="categoryID"></param> public void AssignCategory(Guid RoomID, Guid categoryID) { Room room = roomRepository.GetByKey(RoomID); //HotelRoomCategory hotelRoomCategory = hotelRoomCategoryRepository.GetByKey(categoryID); room.HotelRoomCategoryId = categoryID; roomRepository.Update(room); repositoryContext.Commit(); }
public void CreateBlog() { IRepositoryContext repositoryContext = ServiceLocator.Instance.GetService <IRepositoryContext>(); IBlogRepository blogRepository = ServiceLocator.Instance.GetService <IBlogRepository>(); Blog blog = new Blog("Scott Qian", string.Empty, "Default", DES.DesEncrypt("123456")); blogRepository.Add(blog); repositoryContext.Commit(); }
public Post PublishPost(Topic topic, User author, string content) { Post post = Post.Create(topic, author, content); postRepository.Add(post); repositoryContext.Commit(); return(post); }
public void MongoDBRepositoryTests_DeleteDocument() { List <Customer> customers = new List <Customer>(); for (int i = 0; i < 100; i++) { customers.Add(new Customer { FirstName = "sunny" + i.ToString(), LastName = "chen" + i.ToString(), Birth = DateTime.Now.AddDays(-i), Email = "sunnychen" + i.ToString() + "@163.com", Password = i.ToString(), Sequence = i, ID = Guid.NewGuid(), Username = "******" + i.ToString() }); } IRepositoryContext context = ServiceLocator.Instance.GetService <IRepositoryContext>(); IRepository <Customer> customerRepository = ServiceLocator.Instance.GetService <IRepository <Customer> >(new { context = context }); foreach (var customer in customers) { customerRepository.Add(customer); } context.Commit(); Customer oneCustomer = customerRepository.Find(Specification <Customer> .Eval(c => c.Sequence == 50)); customerRepository.Remove(oneCustomer); context.Commit(); MongoClient client = new MongoClient(Helper.MongoDB_ConnectionString); //MongoServer server = MongoServer.Create(Helper.MongoDB_ConnectionString); MongoServer server = client.GetServer(); MongoDatabase database = server.GetDatabase(Helper.MongoDB_Database); MongoCollection collection = database.GetCollection("Customer"); var query = Query.EQ("Sequence", 50); var deletedCustomer = collection.FindOneAs <Customer>(query); Assert.IsNull(deletedCustomer); Assert.AreEqual(99, collection.Count()); }
public void MongoDBRepositoryTests_ModifyDocument() { List <Customer> customers = new List <Customer>(); for (int i = 0; i < 100; i++) { customers.Add(new Customer { FirstName = "sunny" + i.ToString(), LastName = "chen" + i.ToString(), Birth = DateTime.Now.AddDays(-i), Email = "sunnychen" + i.ToString() + "@163.com", Password = i.ToString(), Sequence = i, ID = Guid.NewGuid(), Username = "******" + i.ToString() }); } IRepositoryContext context = ServiceLocator.Instance.GetService <IRepositoryContext>(); IRepository <Customer> customerRepository = ServiceLocator.Instance.GetService <IRepository <Customer> >(new { context = context }); foreach (var customer in customers) { customerRepository.Add(customer); } context.Commit(); Customer oneCustomer = customerRepository.Find(Specification <Customer> .Eval(c => c.Sequence == 50)); oneCustomer.FirstName = "daxnet"; customerRepository.Update(oneCustomer); context.Commit(); MongoClient client = new MongoClient(Helper.MongoDB_ConnectionString); //MongoServer server = MongoServer.Create(Helper.MongoDB_ConnectionString); //MongoServer server = client.GetServer(); var database = client.GetDatabase(Helper.MongoDB_Database); var collection = database.GetCollection <Customer>("Customer"); var modifiedCustomer = collection.Find(c => c.Sequence == 50).FirstAsync().Result; Assert.AreEqual <string>("daxnet", modifiedCustomer.FirstName); }
public void Test_Delete_Item() { using (IRepositoryContext ctx = ServiceLocator.Instance.GetService <IRepositoryContext>("DapperRepositoryContext")) { IPostRepository postRep = (IPostRepository)ctx.GetRepository <Post>(); Post p = postRep.FindByKey(1021); postRep.Delete(p); ctx.Commit(); } }
public void Handle(OrderPlaced @event) { var manager = new RegistrationProcessManager(); manager.Handle(@event); context.RegisterNew(manager.ProcessInfo); context.Commit(); }
protected virtual async Task <LoginResult <TUser> > CreateLoginResultAsync(TUser user) { if (!user.IsActive) { return(new LoginResult <TUser>(LoginResultType.UserIsNotActive)); } if (await IsEmailConfirmationRequiredForLoginAsync() && !user.IsEmailConfirmed) { return(new LoginResult <TUser>(LoginResultType.UserEmailIsNotConfirmed)); } user.LastLoginTime = DateTime.Now; await UserManager.Store.UpdateAsync(user); // await UnitOfWorkManager.Current.SaveChangesAsync(); _repositoryContext.Commit(); return(new LoginResult <TUser>( user, await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie) )); }
public void Test_Update_Item() { using (IRepositoryContext ctx = ServiceLocator.Instance.GetService <IRepositoryContext>("DapperRepositoryContext")) { IPostRepository postRep = (IPostRepository)ctx.GetRepository <Post>(); Post p = postRep.FindByKey(1016); p.Content = "Test_Update_Item" + Utils.GetUniqueIdentifier(5); p.Status.InternalStatus = "MODIFIED"; postRep.Update(p); ctx.Commit(); } }
public void Handle(PostPublishCommand message) { //Post post = message.PostDataObject.MapTo(); //post.Publish(); using (IRepositoryContext repositoryContext = ServiceLocator.Instance.GetService <IRepositoryContext>()) { IPostRepository postRepository = (IPostRepository)repositoryContext.GetRepository <Post>(); Post post = message.PostDataObject.MapTo(); postRepository.Add(post); repositoryContext.Commit(); } }
public void Test_Add_Item() { using (IRepositoryContext ctx = ServiceLocator.Instance.GetService <IRepositoryContext>("DapperRepositoryContext")) { IPostRepository postRep = (IPostRepository)ctx.GetRepository <Post>(); Post p = new Post(); p.AuthorId = 1000; p.TopicId = 1000; p.Content = "Test Add_Post" + Utils.GetUniqueIdentifier(5); p.Status = new PostStatus(); p.Status.InternalId = Guid.NewGuid(); p.Status.InternalStatus = "NEW"; postRep.Add(p); ctx.Commit(); } }
public void CreateArticle(ArticleDTO articleDTO) { if (string.IsNullOrEmpty(articleDTO.Title)) { throw new ArgumentException("标题不能为空"); } if (string.IsNullOrEmpty(articleDTO.Category)) { throw new ArgumentException("类别不能为空"); } if (articleDTO.Id != Guid.Empty) { throw new ArgumentException("新文章不应该包含ID信息"); } articleRepository.Add(articleDTO.MapTo()); repositoryContext.Commit(); }
public void MongoDBRepositoryTests_InsertDocument() { List <Customer> customers = new List <Customer>(); for (int i = 0; i < 100; i++) { customers.Add(new Customer { FirstName = "sunny" + i.ToString(), LastName = "chen" + i.ToString(), Birth = DateTime.Now.AddDays(-i), Email = "sunnychen" + i.ToString() + "@163.com", Password = i.ToString(), Sequence = i, ID = Guid.NewGuid(), Username = "******" + i.ToString() }); } IRepositoryContext context = ServiceLocator.Instance.GetService <IRepositoryContext>(); IRepository <Customer> customerRepository = ServiceLocator.Instance.GetService <IRepository <Customer> >(new { context = context }); foreach (var customer in customers) { customerRepository.Add(customer); } context.Commit(); MongoClient client = new MongoClient(Helper.MongoDB_ConnectionString); //MongoServer server = MongoServer.Create(Helper.MongoDB_ConnectionString); //MongoServer server = client.GetServer(); var database = client.GetDatabase(Helper.MongoDB_Database); var collection = database.GetCollection <Customer>("Customer"); var count = collection.CountAsync(c => true).Result; Assert.AreEqual(100, count); }