public bool RegisterCustomer(CustomerRequestDto customerRequestDto) { if (UserExists(customerRequestDto.userRequestDto.Username)) { return(false); } byte[] passwordHash, passwordSalt; CreatePasswordHash(customerRequestDto.userRequestDto.Password, out passwordHash, out passwordSalt); var user = new User { UserId = Guid.NewGuid(), Username = customerRequestDto.userRequestDto.Username, PasswordHash = passwordHash, PasswordSalt = passwordSalt }; _ecommerceContext.Add(user); if (_ecommerceContext.SaveChanges() == 1) { if (_customerServiceManager.AddCustomer(user.UserId, customerRequestDto)) { if (_cartServiceManager.CreateCart(user.UserId)) { return(true); } } } return(false); }
public async Task <IActionResult> UploadPicture() { JsonResult result; List <object> pictureJson = new List <object>(); var pictures = Request.Form.Files; for (int i = 0; i < pictures.Count; i++) { var picture = pictures[i]; var fileName = Guid.NewGuid() + Path.GetExtension(picture.FileName); var wwwRootFolder = Path.Combine(_environment.WebRootPath, "uploads"); string filePath = Path.Combine(wwwRootFolder, fileName); using var fileStream = new FileStream(filePath, FileMode.Create); await picture.CopyToAsync(fileStream); Picture newPicture = new Picture() { URL = fileName }; _context.Add(newPicture); await _context.SaveChangesAsync(); pictureJson.Add(new { id = newPicture.ID, pictureURL = newPicture.URL }); } result = new JsonResult(new { Data = pictureJson }); return(result); }
public void CreateSubCategorie(SubCategorie subCategorie) { if (subCategorie == null) { throw new ArgumentNullException(nameof(subCategorie)); } _context.Add(subCategorie); }
public async Task <IActionResult> Create([Bind("ProductName,ProductDescription,Price,ProductPicture,SpecificationFile")] Product product) { if (ModelState.IsValid) { product.ProductId = Guid.NewGuid().ToString(); _context.Add(product); await _context.SaveChangesAsync(); StockEntry stock = new StockEntry(); stock.RemainingStock = 0; stock.ProductId = product.ProductId; stock.StockId = Guid.NewGuid().ToString(); _context.Add(stock); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Create([Bind("PostName,PostUrl,PhotoUrl,Hit,UserID,UserName,PostDate,MyProperty,Description,ID,IsActive,IsDeleted,ModifiedOn")] Blog blog) { if (ModelState.IsValid) { _context.Add(blog); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(blog)); }
public async Task <IActionResult> Create([Bind("RoleId,Role1")] Role role) { if (ModelState.IsValid) { _context.Add(role); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(role)); }
public async Task <IActionResult> Create([Bind("Id,Titulo,Autor,Editora,Preco")] Livros livros) { if (ModelState.IsValid) { _context.Add(livros); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(livros)); }
public async Task <IActionResult> Create([Bind("Id,Name,Address,CardNumber,RoleId")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["RoleId"] = new SelectList(_context.Role, "RoleId", "Role1", user.RoleId); return(View(user)); }
public async Task <IActionResult> Create([Bind("CategoryID,ProductName,Description,Seller,Number,Publishing,Author,PhotoURL,Pages,Price,Discount,Cost,isFeatured,ThumbnailPictureID,SKU,Tags,Barcode,Supplier,Hit,ID,IsActive,IsDeleted,ModifiedOn")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryID"] = new SelectList(_context.Categories, "ID", "ID", product.CategoryID); return(View(product)); }
public async Task <IActionResult> Create([Bind("CategoryName")] Category category) { if (ModelState.IsValid) { category.CategoryId = Guid.NewGuid().ToString(); _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("ParentCategoryID,Name,Description,PictureID,isFeatured,ID,IsActive,IsDeleted,ModifiedOn")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ParentCategoryID"] = new SelectList(_context.Categories, "ID", "ID", category.ParentCategoryID); ViewData["PictureID"] = new SelectList(_context.Pictures, "ID", "ID", category.PictureID); return(View(category)); }
public bool AddDepartment(Department departments) { _db.Add(departments); try { _db.SaveChanges(); return(true); } catch { return(false); } }
public async Task <IActionResult> Create([Bind("ProductId,RemainingStock")] StockEntry stockEntry) { if (ModelState.IsValid) { stockEntry.StockId = Guid.NewGuid().ToString(); _context.Add(stockEntry); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ProductId"] = new SelectList(_context.Product, "ProductId", "ProductName", stockEntry.ProductId); return(View(stockEntry)); }
public async Task <IActionResult> Create([Bind("OrderIdFk,ProductIdFk,IdProductOrder")] ProductOrder productOrder) { if (ModelState.IsValid) { _context.Add(productOrder); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["OrderIdFk"] = new SelectList(_context.Order, "OrderId", "OrderId", productOrder.OrderIdFk); ViewData["ProductIdFk"] = new SelectList(_context.Product, "ProductId", "ProductId", productOrder.ProductIdFk); return(View(productOrder)); }
public IActionResult CreateProduct(Product p) { if (ModelState.IsValid) { _context.Add(p); _context.SaveChanges(); return(RedirectToAction("Products")); } else { return(View("Products")); } }
public async Task <IActionResult> Create([Bind("ProductId,CategoryId")] ProductCategory productCategory) { if (ModelState.IsValid) { productCategory.IdProductCategory = Guid.NewGuid().ToString(); _context.Add(productCategory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Category, "CategoryId", "CategoryName", productCategory.CategoryId); ViewData["ProductId"] = new SelectList(_context.Product, "ProductId", "ProductName", productCategory.ProductId); return(View(productCategory)); }
public IActionResult CreateCustomer(Customer c) { if (ModelState.IsValid) { _context.Add(c); _context.SaveChanges(); return(RedirectToAction("Customers")); } else { TempData["noCustomerName"] = "Provide customer name"; return(RedirectToAction("Customers")); } }
public IActionResult Register(RegisterViewModel user) { if (ModelState.IsValid) { var userList = _context.users.Where(p => p.email == user.register_email).FirstOrDefault(); if (userList != null) { if (user.register_email == userList.email) { ModelState.AddModelError("register_email", "email exists"); return(View("index")); } } PasswordHasher <RegisterViewModel> Hasher = new PasswordHasher <RegisterViewModel>(); user.register_password = Hasher.HashPassword(user, user.register_password); users User = new users() { first_name = user.first_name, last_name = user.last_name, email = user.register_email, password = user.register_password, level = "user", created_at = DateTime.Now, updated_at = DateTime.Now }; _context.Add(User); _context.SaveChanges(); HttpContext.Session.SetInt32("Id", (int)User.id); if (User.level == "admin") { return(RedirectToAction("Dashboard")); } else { return(RedirectToAction("UserDashboard")); } } else { return(View("index")); } }
public async Task <IActionResult> Create([Bind("HasBeenPlaced,ClientId,Quantity")] Order order) { if (ModelState.IsValid) { order.OrderId = Guid.NewGuid().ToString(); order.HasBeenPlaced = 0; order.HasBeenConfirmed = "0"; _context.Add(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ClientId"] = new SelectList(_context.User, "Id", "Id", order.ClientId); return(View(order)); }
public async Task <IActionResult> Create([Bind("PostName,PostUrl,PhotoUrl,Hit,UserID,UserName,PostDate,MyProperty,ID,IsActive,IsDeleted,ModifiedOn,Description")] Blog blog, IFormFile PhotoUrl) { if (ModelState.IsValid) { string path = "/Uploads/" + Guid.NewGuid() + PhotoUrl.FileName; using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create)) { await PhotoUrl.CopyToAsync(fileStream); } blog.UserID = _userManager.GetUserId(HttpContext.User); blog.UserName = _userManager.GetUserName(HttpContext.User); blog.PhotoUrl = path; _context.Add(blog); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(blog)); }
public async Task <IActionResult> Create([Bind("ID,Name,Price,Image")] Food food) { if (ModelState.IsValid) { byte[] fileBytes; SQLFunction functions = HttpContext.RequestServices.GetService(typeof(SQLFunction)) as SQLFunction; using (MemoryStream ms = new MemoryStream()) { food.Image.CopyTo(ms); fileBytes = ms.ToArray(); } functions.InsertFood(food.Name, food.Price, fileBytes); _context.Add(food); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Home")); } return(View(food)); }
public IActionResult CreateOrder(int customerid, int productid, int quantity) { Product prod = _context.products.SingleOrDefault(p => p.productid == productid); if (prod.quantity < quantity) { TempData["suckit"] = "Nice try dickhead"; return(RedirectToAction("Orders")); } else { prod.quantity -= quantity; Order order = new Order(); order.customerid = customerid; order.productid = productid; order.quantity = quantity; _context.Add(order); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); } }
public async Task <IActionResult> Create([Bind("CategoryID, ProductName, Description, Seller, Number, Publishing, Author, Pages, Price, Discount, Cost, isFeatured, ThumbnailPictureID, SKU, Tags, Barcode, Supplier, ID, IsActive, IsDeleted, ModifiedOn")] Product product) { string userId = _userManager.GetUserId(HttpContext.User); if (userId != product.Seller) { return(RedirectToAction(nameof(Create))); } if (ModelState.IsValid) { product.Supplier = _userManager.GetUserName(HttpContext.User); product.Seller = userId; _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryID"] = new SelectList(_context.Categories, "ID", "Name", product.CategoryID); return(View(product)); }