public ReturnType AddUserShop(UserShop usershop) { try { using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString())) { alading.AddToUserShop(usershop); if (alading.SaveChanges() == 1) { return(ReturnType.Success); } else { return(ReturnType.PropertyExisted); } } } catch (SqlException sex) { return(ReturnType.ConnFailed); } catch (Exception ex) { return(ReturnType.OthersError); } }
public string InsertUser(UserShop data) { var factory = new ConnectionFactory() { HostName = "localhost" }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { channel.QueueDeclare(queue: "User", durable: false, exclusive: false, autoDelete: false, arguments: null); var stocData = JsonConvert.SerializeObject(data); var body = Encoding.UTF8.GetBytes(stocData); channel.BasicPublish(exchange: "", routingKey: "User", basicProperties: null, body: body); return($"[x] Sent {data.name}"); } }
public ReturnType RemoveUserShop(long usershopId) { try { using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString())) { /*List<UserShop> list = alading.UserShop.Where(p => p.UserShopID == usershopID).ToList();*/ List <UserShop> list = alading.UserShop.Where(p => p.Id == usershopId).ToList(); if (list.Count == 0) { return(ReturnType.NotExisted); } else { UserShop sy = list.First(); alading.DeleteObject(sy); alading.SaveChanges(); return(ReturnType.Success); } } } catch (SqlException sex) { return(ReturnType.ConnFailed); } catch (System.Exception ex) { return(ReturnType.OthersError); } }
public async Task <IActionResult> PutUserShop(Guid id, UserShop userShop) { if (id != userShop.shopId) { return(BadRequest()); } _context.Entry(userShop).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserShopExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Link(CustomerLinkViewModel vm) { /**0. aim -> add new record to UserShop{user_id, shop_id} table * read user_id straight away from vm, * loop the shoplist to found out with shop is marked isPicked true */ //1. read data from request string user_id = vm.customer_id; //1-1. create filter IEnumerable <UserShop> query = await _userShopDataService.Query(us => us.user_id == user_id); List <int> exist_shopIds = query.Select(us => us.shop_id).ToList(); //2. update db foreach (var shop in vm.shop_info_list) { if (shop.isPicked == true && !exist_shopIds.Contains(shop.shop_id)) { UserShop new_usershop = new UserShop(); new_usershop.user_id = user_id; new_usershop.shop_id = shop.shop_id; await _userShopDataService.Create(new_usershop); } } //3. return to view add more return(View(vm)); }
private void CreateShop(ShopDTO ShopDto) { var newUserShop = new UserShop { ActionDate = DateTime.Now, Dislike = false, Like = true, ShopId = ShopDto.Id, UserId = ShopDto.UserId }; _context.UserShops.Add(newUserShop); }
public ReturnType UpdateUserShop(UserShop usershop) { try { using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString())) { /*UserShop result = alading.UserShop.Where(p => p.UserShopID == usershop.UserShopID).FirstOrDefault();*/ UserShop result = alading.UserShop.Where(p => p.Id == usershop.Id).FirstOrDefault(); if (result == null) { return(ReturnType.NotExisted); } #region Using Attach() Function Update,Default USE; alading.Attach(result); alading.ApplyPropertyChanges("UserShop", usershop); #endregion #region Using All Items Replace To Update ,Default UnUse /* * * result.Id = usershop.Id; * * result.UserCode = usershop.UserCode; * * result.ShopId = usershop.ShopId; * * result.Enable = usershop.Enable; * */ #endregion if (alading.SaveChanges() == 1) { return(ReturnType.Success); } else { return(ReturnType.OthersError); } } } catch (SqlException sex) { return(ReturnType.ConnFailed); } catch (Exception ex) { return(ReturnType.OthersError); } }
public JsonResult Delete(UserShop userShop) { int result = userShopService.Delete(userShop.Id); _hubContext.Clients.All.SendAsync("dataChangeNotification", null); if (result != 0) { return(Json(new { messageType = "success", note = AppGlobal.DeleteSuccessMessage })); } else { return(Json(new { messageType = "error", note = AppGlobal.DeleteFailMessage })); } }
public async Task SeedAsync() { Context.Database.EnsureCreated(); UserShop user = await this.userManager.FindByEmailAsync("*****@*****.**"); if (user == null) { user = new UserShop { FirstName = "Ahmad", LastName = "Haseeb", Email = "*****@*****.**", UserName = "******" }; var result = await this.userManager.CreateAsync(user, "P@ssw0rd!"); if (result != IdentityResult.Success) { throw new InvalidOperationException("Could not create new user In Seeder"); } } if (!Context.Products.Any()) { string filepath = Path.Combine(hosting.ContentRootPath, "Data/art.json"); string json = File.ReadAllText(filepath); var products = JsonConvert.DeserializeObject <IEnumerable <Product> >(json); Context.AddRange(products); Order order = new Order() { User = user, OrderDate = DateTime.UtcNow, OrderNumber = "12345", Items = new List <OrderItem>() { new OrderItem() { Product = products.First(), Quantity = 5, UnitPrice = products.First().Price } } }; Context.Add(order); } Context.SaveChanges(); }
public JsonResult Update(UserShop userShop) { userShop.Initialization(ObjectInitType.Update, "", HttpContext); int result = userShopService.Update(userShop.Id, userShop); _hubContext.Clients.All.SendAsync("dataChangeNotification", null); if (result != 0) { return(Json(new { messageType = "success", note = AppGlobal.UpdateSuccessMessage })); } else { return(Json(new { messageType = "error", note = AppGlobal.UpdateFailMessage })); } }
/// <summary> /// 保存客服商店 /// </summary> private void SaveUserShop() { TreeListNode node = tLRole.Nodes[3]; if (node.Nodes.Count > 0) { foreach (TreeListNode x in node.Nodes) { if (x.Checked == true) { UserShop us = new UserShop(); us.ShopId = x.Tag.ToString(); us.UserCode = selectedUser.UserCode; Alading.Business.UserShopService.AddUserShop(us); } } } }
public string SetPreferredShop(string shopId, bool flag) { var idUser = Convert.ToInt32(Session["LoginId"]); var idShop = int.Parse(shopId); UserShop shopResult = (from us in shopsContext.UserShop where us.login_id == idUser && us.shop_id == idShop select us).SingleOrDefault(); if (shopResult == null) { UserShop us = new UserShop(); us.login_id = idUser; us.shop_id = idShop; us.isPreferred = flag; if (flag) { us.likedDate = DateTime.Now; } else { us.dislikedDate = DateTime.Now; } shopsContext.UserShop.Add(us); shopsContext.SaveChanges(); } else { shopResult.isPreferred = flag; if (flag) { shopResult.likedDate = DateTime.Now; } else { shopResult.dislikedDate = DateTime.Now; } shopsContext.SaveChanges(); } return(""); }
public async Task <ActionResult <UserShop> > PostUserShop(UserShop userShop) { _context.UserShop.Add(userShop); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (UserShopExists(userShop.shopId)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetUserShop", new { id = userShop.shopId }, userShop)); }
public ReturnType UpdateUserShop(long usershopId, UserShop usershop) { try { using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString())) { /*var result = alading.UserShop.Where(p => p.UserShopID == usershopID).ToList();*/ var result = alading.UserShop.Where(p => p.Id == usershopId).ToList(); if (result.Count == 0) { return(ReturnType.NotExisted); } UserShop ob = result.First(); ob.Id = usershop.Id; ob.UserCode = usershop.UserCode; ob.ShopId = usershop.ShopId; if (alading.SaveChanges() == 1) { return(ReturnType.Success); } else { return(ReturnType.OthersError); } } } catch (SqlException sex) { return(ReturnType.ConnFailed); } catch (System.Exception ex) { return(ReturnType.OthersError); } }
public async Task <RustCreateShopResult> CreateShopAsync(CreateShopViewModel model) { var user = await _userManager.FindByEmailAsync(_httpContextAccessor.HttpContext.User.Identity.Name); var userShops = await UserShopsByUserEmailAsync(user.Email); var userAllowedShops = int.Parse(_configuration["ShopsAllowed"]); if (userShops.Count() < userAllowedShops) { Guid secret; do { secret = Guid.NewGuid(); } while (_easyShopContext.Shops.FirstOrDefault(x => x.Secret == secret) != null); var gameType = _easyShopContext.GameTypes.First(x => x.Type == model.GameType); Guid newShopId; do { newShopId = Guid.NewGuid(); } while (_easyShopContext.UserShops.FirstOrDefault(x => x.ShopId == newShopId) != null); var newShop = new Shop { Id = newShopId, ShopName = model.ShopName, GameType = gameType, ShopTitle = model.ShopTitle, StartBalance = model.StartBalance, Secret = secret }; var userShop = new UserShop { ShopId = newShopId, Shop = newShop, AppUserId = user.Id, AppUser = user, }; var addNewTenant = await _tenancyStoreService.TryAddAsync( newShopId.ToString(), newShopId.ToString(), model.ShopName, null); if (!addNewTenant) { return(RustCreateShopResult.SomethingWentWrong); } _easyShopContext.Shops.Add(newShop); _easyShopContext.UserShops.Add(userShop); await _easyShopContext.SaveChangesAsync(); if (model.AddDefaultItems) { try { await SetDefaultProductsAsync(user, newShop); await _easyShopContext.SaveChangesAsync(); _logger.LogInformation("UserName: {0} | UserId: {1} | Request: {2} | Message: {3}", user.UserName, user.Id, _httpContextAccessor.HttpContext.Request.GetRawTarget(), $"Rust shop has been successfully created! ShopId: {newShopId}"); return(RustCreateShopResult.Success); } catch (Exception e) { _easyShopContext.Shops.Remove(newShop); _easyShopContext.UserShops.Remove(userShop); await RemoveAllCategoriesAndItemsInShopAsync(newShop); await _easyShopContext.SaveChangesAsync(); _logger.LogError("UserName: {0} | UserId: {1} | Request: {2} | Message: {3}", user.UserName, user.Id, _httpContextAccessor.HttpContext.Request.GetRawTarget(), $"Error on adding default products and categories. Error message: {e.Message}; Inner exception: {e.InnerException?.Message}; Stacktrace: {e.StackTrace};"); return(RustCreateShopResult.SomethingWentWrong); } } _logger.LogInformation("UserName: {0} | UserId: {1} | Request: {2} | Message: {3}", user.UserName, user.Id, _httpContextAccessor.HttpContext.Request.GetRawTarget(), $"Rust shop has been successfully created! ShopId: {newShop.Id}"); return(RustCreateShopResult.Success); } return(RustCreateShopResult.MaxShopLimitIsReached); }
public string InsertUser([FromBody] UserShop data) { return(_userService.InsertUser(data)); }
static void Main(string[] args) { var factory = new ConnectionFactory() { HostName = "localhost" }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { channel.QueueDeclare(queue: "User", durable: false, exclusive: false, autoDelete: false, arguments: null); var consumer = new EventingBasicConsumer(channel); consumer.Received += (model, ea) => { var body = ea.Body.Span; var data = Encoding.UTF8.GetString(body); //UserShop user = JsonConvert.DeserializeObject<UserShop>(data); UserShop user = JsonSerializer.Deserialize <UserShop>(data); Console.WriteLine(" [x] Received {0}", user.name + " : " + user.surname); using (DenoContext context = new DenoContext()) { if (!context.Users.Any(us => us.Name == user.name && us.Surname == user.surname)) { Users userModel = new Users(); userModel.Name = user.name; userModel.Surname = user.surname; userModel.No = user.no; userModel.IsActive = false; context.Users.Add(userModel); context.SaveChanges(); ProductConsumer product = new ProductConsumer(); product.Name = user.productName; product.Price = user.productPrice; product.UserId = userModel.Id; product.IsActive = false; List <TransactionHistory> listTransaction = new List <TransactionHistory>(); listTransaction.Add(new TransactionHistory() { TableName = "Users", ID = userModel.Id, State = TransactionState.Pending, Step = TransactionStep.User, Type = TransactionType.SqlDB }); product.TransactionList = listTransaction; Console.WriteLine(PushRabbitMQ(product)); } else { int userID = context.Users.FirstOrDefault(us => us.Name == user.name && us.Surname == user.surname).Id; ProductConsumer product = new ProductConsumer(); product.Name = user.productName; product.Price = user.productPrice; product.UserId = userID; product.IsActive = false; List <TransactionHistory> listTransaction = new List <TransactionHistory>(); product.TransactionList = listTransaction; Console.WriteLine(PushRabbitMQ(product)); } } //------------------------- }; channel.BasicConsume(queue: "User", autoAck: true, consumer: consumer); Console.WriteLine(" Press [enter] to exit."); Console.ReadLine(); } }
public ReturnType UpdateUser(User user, List <Role> roles, List <Shop> shops, List <StockHouse> houses) { System.Data.Common.DbTransaction tran = null; using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString())) { try { alading.Connection.Open(); tran = alading.Connection.BeginTransaction(); User u1 = alading.User.FirstOrDefault(c => c.UserCode == user.UserCode); if (u1 != null) { //更新用户 alading.Attach(u1); alading.ApplyPropertyChanges("User", user); //更新用户角色 var result1 = alading.UserRole.Where(c => c.UserCode == u1.UserCode); foreach (UserRole s1 in result1) { alading.DeleteObject(s1); } alading.SaveChanges(); foreach (var i1 in roles) { UserRole e1 = new UserRole { UserRoleCode = Guid.NewGuid().ToString(), UserCode = u1.UserCode, RoleCode = i1.RoleCode, RoleType = i1.RoleType, }; alading.AddToUserRole(e1); } alading.SaveChanges(); //更新用户和店铺的关联 var return2 = alading.UserShop.Where(c => c.UserCode == u1.UserCode); foreach (UserShop s2 in return2) { alading.DeleteObject(s2); } alading.SaveChanges(); foreach (var i2 in shops) { UserShop e2 = new UserShop { UserCode = u1.UserCode, ShopId = i2.sid, }; alading.AddToUserShop(e2); } alading.SaveChanges(); //更新用户和仓库的关联 var return3 = alading.UserStockHouse.Where(c => c.UserCode == u1.UserCode); foreach (UserStockHouse s3 in return3) { alading.DeleteObject(s3); } alading.SaveChanges(); foreach (var i3 in houses) { UserStockHouse e3 = new UserStockHouse { UserCode = u1.UserCode, StockHouseCode = i3.StockHouseCode, }; alading.AddToUserStockHouse(e3); } alading.SaveChanges(); tran.Commit(); return(ReturnType.Success); } else { return(ReturnType.NotExisted); } } catch (System.Exception ex) { if (tran != null) { tran.Rollback(); } return(ReturnType.SaveFailed); } finally { if (alading != null && alading.Connection.State != System.Data.ConnectionState.Closed) { alading.Connection.Close(); } } } }
/* * public static ReturnType UpdateUserShop(string usershopCode, UserShop usershop) * { * return DataProviderClass.Instance().UpdateUserShop(usershopCode, usershop); * } */ public static ReturnType UpdateUserShop(long usershopID, UserShop usershop) { return(DataProviderClass.Instance().UpdateUserShop(usershopID, usershop)); }
public static ReturnType AddUserShop(UserShop usershop) { return(DataProviderClass.Instance().AddUserShop(usershop)); }
private async Task <Guid> CreateDefaultShopForAdmin() { var user = await _userManager.FindByEmailAsync(DefaultIdentity.AdminUserName); var model = new CreateShopViewModel { ShopName = "TestDataShop", ShopTitle = "TestDataShop", StartBalance = 50000, GameType = "Rust", AddDefaultItems = true }; Guid secret; do { secret = Guid.NewGuid(); } while (_easyShopContext.Shops.FirstOrDefault(x => x.Secret == secret) != null); var gameType = _easyShopContext.GameTypes.First(x => x.Type == model.GameType); Guid newShopId; do { newShopId = Guid.NewGuid(); } while (_easyShopContext.UserShops.FirstOrDefault(x => x.ShopId == newShopId) != null); var newShop = new Shop { Id = newShopId, ShopName = model.ShopName, GameType = gameType, ShopTitle = model.ShopTitle, StartBalance = model.StartBalance, Secret = secret }; _newShop = newShop; var userShop = new UserShop { ShopId = newShopId, Shop = newShop, AppUserId = user.Id, AppUser = user }; var addNewTenant = await _tenancyStoreService.TryAddAsync( newShopId.ToString(), newShopId.ToString(), model.ShopName, null); if (!addNewTenant) { throw new ApplicationException($"Cannot add tenant in to DB, please check connection string for context - {nameof(RustShopMultiTenantStoreContext)}"); } _easyShopContext.Shops.Add(newShop); _easyShopContext.UserShops.Add(userShop); await _easyShopContext.SaveChangesAsync(); (List <RustCategory>, List <RustProduct>)? defaultData = GetDefaultCategoriesWithProducts(user, newShop); _easyShopContext.RustCategories.AddRange(defaultData?.Item1); _easyShopContext.RustUserItems.AddRange(defaultData?.Item2); await _easyShopContext.SaveChangesAsync(); return(newShopId); }