public async Task <IActionResult> Create(CreateShopViewModel model) { if (ModelState.IsValid) { var user = await userManager.GetUserAsync(HttpContext.User); Seller seller = new Seller { Name = model.ShopName, ShopType = model.ShopType.ToString(), About = string.Empty, Address = string.Empty, Tel = string.Empty, CreatedDate = DateTime.UtcNow, }; db.Add(seller); var effect = await db.SaveChangesAsync(); seller = db.Sellers.SingleOrDefault(s => s == seller); user.SellerID = seller.Id; await userManager.UpdateAsync(user); return(RedirectToAction(nameof(Index))); } else { ModelState.AddModelError(string.Empty, "Invalid filed information"); return(View()); } }
public ActionResult Create(CreateShopViewModel requestedViewModel) { if (ModelState.IsValid) { try { var form = requestedViewModel.ProductForm; ProductService.Create(form.AlbumName, form.ArtistName, form.GenreId, form.Price, requestedViewModel.Cover); Messages.Add("Albummet er oprettet", "Albummet er blevet oprettet", MessageType.Success); } catch { Messages.AddStandardCreateError(); } } requestedViewModel.ProductForm.PossibleGenres = ProductService.GetGenres().Select(x => new SelectListItem { Text = x.Name, Value = x.GenreId.ToString() }); return(View(requestedViewModel)); }
// GET: Shop/Create public ActionResult Create() { CreateShopViewModel model = new CreateShopViewModel(); //model.AdminUser = User.Identity return(View("Create", model)); }
public ActionResult AddNewShop(CreateShopViewModel model) { if (ModelState.IsValid) { var time = model.ShopClosingTime.TimeOfDay;//return TimeSpan return(RedirectToAction("Index", "Home")); } return(View()); }
public ActionResult AddNewShop(CreateShopViewModel model) { if (ModelState.IsValid) { Service.ShopService.Create(Mapper.Map <ShopServiceModel>(model)); return(RedirectToAction("Index", "Home")); } return(View()); }
public IActionResult CreateShop(CreateShopViewModel model) { string EncodedResponse = Request.Form["g-recaptcha-response"]; var isCaptchaValid = CaptchaResponse.Validate(EncodedResponse); if (!ModelState.IsValid) { return(View(model)); } var user = this._context.Users.FirstOrDefault(u => u.Id == model.UserId); var userRole = this._context.UserRoles.FirstOrDefault(u => u.UserId == user.Id); if (isCaptchaValid) { if (userRole.Role != Role.ShopAdmin) { this._context.UserRoles.Add(new UserRole() { Id = Guid.NewGuid(), UserId = user.Id.Value, Role = Infrastructures.Domain.Enums.Role.ShopAdmin }); if (user != null) { Shop shop = new Shop() { BusinessContact = model.BusinessContact, BusinessEmailAddress = model.BusinessEmailAddress, BusinessLocation = model.BusinessLocation, BusinessName = model.BusinessName, BusinessType = model.BusinessType, OpenAt = model.OpenAt, CloseAt = model.CloseAt, Id = Guid.NewGuid(), UserId = model.UserId, Status = Infrastructures.Domain.Enums.Status.Active, BusinessDescription = model.BusinessDescription, OwnerShop = model.OwnerShop, IsPublished = true, }; this._context.Shops.Add(shop); this._context.SaveChanges(); } } } return(RedirectToAction("Welcome")); }
public async Task <IActionResult> CreateShop(CreateShopViewModel model) { if (!ModelState.IsValid) { var errors = ModelState.Values.SelectMany(x => x.Errors.Select(xx => xx.ErrorMessage)).ToList(); errors.ForEach(x => ModelState.AddModelError("", x)); return(View(model)); } RustCreateShopResult result = default; switch (model.GameType) { case "Rust": result = await _rustShopService.CreateShopAsync(model); break; } if (result == RustCreateShopResult.Success) { return(RedirectToAction("ShopsList", "ShopManager")); } else if (result == RustCreateShopResult.MaxShopLimitIsReached) { return(View("AllowedShopsLimitIsReached")); } else if (result == RustCreateShopResult.SomethingWentWrong) { return(RedirectToAction("SomethingWentWrong", "ControlPanel", new { reason = "on shop creating" })); } else { return(RedirectToAction("SomethingWentWrong", "ControlPanel", new { reason = "on shop creating" })); } }
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 async Task <IActionResult> Create(CreateShopViewModel VM) { if (ModelState.IsValid) { var ShopTransaction = _context.Database.BeginTransaction(); try { Shop InsertData = new Shop() { ShopCode_Id = VM.ShopCode_Id, Shop_Mougheyat = VM.Shop_Mougheyat, Shop_Metrazh = VM.Shop_Metrazh, Shop_TypeDarb = VM.Shop_TypeDarb, Shop_StatusEjareh = VM.Shop_StatusEjareh, Shop_Balakon = VM.Shop_Balakon, Shop_BalakonMetrazh = VM.Shop_BalakonMetrazh, Shop_BeARZ = VM.Shop_BeARZ, Shop_InsidePooshesh = VM.Shop_InsidePooshesh, Shop_AB = VM.Shop_AB, Shop_Gaz = VM.Shop_Gaz, Shop_Bargh = VM.Shop_Bargh, Shop_Tell = VM.Shop_Tell, Shop_HagheCharge = VM.Shop_HagheCharge, Shop_PriceCharge = VM.Shop_PriceCharge, Shop_PriceRahn = VM.Shop_PriceRahn, Shop_PriceEjareh = VM.Shop_PriceEjareh, Shop_Address = VM.Shop_Address, Shop_PayaneKar = VM.Shop_PayaneKar, Shop_TypeSenf = VM.Shop_TypeSenf, Shop_Family = VM.Shop_Family, Shop_Mobile = VM.Shop_Mobile, Shop_Comment = VM.Shop_Comment, Shop_Anbary = VM.Shop_Anbary, Shop_Asansor = VM.Shop_Asansor, Shop_Shoofazh = VM.Shop_Shoofazh, Shop_Status_Rah_OR_Ejareh = VM.Shop_Status_Rah_OR_Ejareh, Shop_DatePublish = DateTime.Now }; await _context.Shops.AddAsync(InsertData); await _context.SaveChangesAsync(); ShopTransaction.Commit(); return(RedirectToAction("Read")); } catch (Exception) { return(RedirectToAction("Read", new { AddNewDataMessageShop = "Faild New Shop Data" })); } } else { // دریافت کلیه لیست های مربوط به مغازه ViewBag.Shop_LST_Locations = new SelectList(_context.Shop_LST_Locations, "Shop_LST_LocationName", "Shop_LST_LocationName"); ViewBag.Shop_LST_Darbs = new SelectList(_context.Shop_LST_Darbs, "Shop_LST_DarbName", "Shop_LST_DarbName"); ViewBag.Shop_LST_Ejarehs = new SelectList(_context.Shop_LST_Ejarehs, "Shop_LST_EjarehName", "Shop_LST_EjarehName"); ViewBag.Shop_LST_Balakons = new SelectList(_context.Shop_LST_Balakons, "Shop_LST_BalakonName", "Shop_LST_BalakonName"); ViewBag.Shop_LST_InsideDesigns = new SelectList(_context.Shop_LST_InsideDesigns, "Shop_LST_InsideDesignName", "Shop_LST_InsideDesignName"); ViewBag.Shop_LST_ABs = new SelectList(_context.Shop_LST_ABs, "Shop_LST_ABName", "Shop_LST_ABName"); ViewBag.Shop_LST_Gazs = new SelectList(_context.Shop_LST_Gazs, "Shop_LST_GazName", "Shop_LST_GazName"); ViewBag.Shop_LST_Barghs = new SelectList(_context.Shop_LST_Barghs, "Shop_LST_BarghName", "Shop_LST_BarghName"); ViewBag.Shop_LST_Tells = new SelectList(_context.Shop_LST_Tells, "Shop_LST_TellName", "Shop_LST_TellName"); ViewBag.Shop_LST_HagheCharges = new SelectList(_context.Shop_LST_HagheCharges, "Shop_LST_HagheChargeName", "Shop_LST_HagheChargeName"); ViewBag.Shop_LST_PayaneKars = new SelectList(_context.Shop_LST_PayaneKars, "Shop_LST_PayaneKarName", "Shop_LST_PayaneKarName"); ViewBag.Shop_LST_Senfs = new SelectList(_context.Shop_LST_Senfs, "Shop_LST_SenfName", "Shop_LST_SenfName"); ViewBag.Shop_LST_Anbaries = new SelectList(_context.Shop_LST_Anbaries, "Shop_LST_AnbaryName", "Shop_LST_AnbaryName"); ViewBag.Shop_LST_Asansors = new SelectList(_context.Shop_LST_Asansors, "Shop_LST_AsansorName", "Shop_LST_AsansorName"); ViewBag.Shop_LST_Shoofazhs = new SelectList(_context.Shop_LST_Shoofazhs, "Shop_LST_ShoofazhName", "Shop_LST_ShoofazhName"); ViewBag.Shop_LST_Rahn_OR_Ejarehs = new SelectList(_context.Shop_LST_Rahn_OR_Ejarehs, "Shop_LST_Rahn_OR_EjarehName", "Shop_LST_Rahn_OR_EjarehName"); return(View(VM)); } }
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); }