public async Task <IActionResult> RequestForm([Bind("ActivityId", "ActivityName", "Description", "ActivityDate", "Price", "ClientId")] Activity activity, IFormFile file) { if (file == null) { return(Content("File is not selected")); } Path.GetTempFileName(); if (ModelState.IsValid) { activity.ClientId = (long)HttpContext.Session.GetInt32("token"); _context.Activity.Add(activity); } await _context.SaveChangesAsync(); CloudBlobContainer container = BlobsController.GetClouldBlobContainer(); CloudBlockBlob cloudBlockBlob = container.GetBlockBlobReference(activity.ActivityId + "_" + file.FileName); var stream = file.OpenReadStream(); await cloudBlockBlob.UploadFromStreamAsync(stream); stream.Dispose(); activity.RequestFormPath = "https://whatsapstorage.blob.core.windows.net/whatsap/" + activity.ActivityId + "_" + file.FileName; _context.Update(activity); await _context.SaveChangesAsync(); return(RedirectToAction("ActivityRequest", "Client", new { id = activity.ClientId })); }
public async Task <IActionResult> Edit(long id, [Bind("ActivityId,ActivityName,Description,CategoryId,ClientId, ActivityDate,Price,Capacity,typeId")] Activity newActivity) { ViewData["CategoryId"] = new SelectList(_context.Category, "CategoryId", "CategoryName", newActivity.CategoryId); var activity = await _context.Activity .Include(c => c.Address) .Include(c => c.Category) .Include(c => c.Client) .FirstOrDefaultAsync(m => m.ActivityId.Equals(id)); activity.ActivityName = newActivity.ActivityName; activity.Description = newActivity.Description; activity.CategoryId = newActivity.CategoryId; activity.Category = newActivity.Category; activity.ActivityDate = newActivity.ActivityDate; activity.Price = newActivity.Price; activity.Capacity = newActivity.Capacity; if (id != newActivity.ActivityId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Activity.Update(activity); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } } return(RedirectToAction("ActivityList", "Client", new { id = activity.ClientId })); }
public async Task <IActionResult> Checkout([Bind("CustomerId,Amount,NameOnCard,CardNumber,Expiration,CVV")] PaymentViewModel paymentViewModel) { if (!ModelState.IsValid) { return(View()); } List <CartViewModel> cart = SessionHelper.GetObjectFromJson <List <CartViewModel> >(HttpContext.Session, "cart"); PaymentMethod method = new PaymentMethod(); method.CardNumber = paymentViewModel.CardNumber; method.NameOnCard = paymentViewModel.NameOnCard; method.Expiration = paymentViewModel.Expiration; method.Cvv = paymentViewModel.CVV; method.CustomerId = paymentViewModel.CustomerId; Payment payment = new Payment(); payment.CustomerId = paymentViewModel.CustomerId; payment.MethodCode = method.MethodCode; payment.PaymentDate = DateTime.Now; payment.PaymentAmount = paymentViewModel.Amount; payment.DiscountAmount = 5; _context.PaymentMethod.Add(method); _context.Payment.Add(payment); await _context.SaveChangesAsync(); return(View("Completed")); }
public async Task <IActionResult> Create([Bind("CommentId, Body, Rate, CustomerId, ActivityId")] Comment comment) { if (ModelState.IsValid) { if (HttpContext.Session.GetInt32("token") != null) { long userId = (long)HttpContext.Session.GetInt32("token"); comment.CustomerId = userId; comment.Customer = _context.Customer.Where(x => x.CustomerId.Equals(userId)).FirstOrDefault(); comment.Activity = _context.Activity.Where(x => x.ActivityId.Equals(comment.ActivityId)).FirstOrDefault(); } _context.Add(comment); await _context.SaveChangesAsync(); return(RedirectToAction("Details", "Activity", new { id = comment.ActivityId })); } return(View(comment)); }
public async Task <IActionResult> Register([Bind("Username, Password, ConfirmPassword")] AdminRegisterViewModel adminViewModel) { if (ModelState.IsValid) { if (!AdminExists(adminViewModel.Username)) { Administrator admin = new Administrator { Username = adminViewModel.Username, Password = AccountsController.EncryptionPassword(adminViewModel.Password), }; _context.Administrator.Add(admin); await _context.SaveChangesAsync(); ViewData["Message"] = "Registration succeed"; return(RedirectToAction("Index", "Admin")); } } //TODO: Need to create UI for exception w/ message choose different email address throw new Exception("user email has already exist"); }
public async Task <IActionResult> Register([Bind("FirstName,LastName,EmailAddress,Password,ConfirmPassword,UserType")] RegisterViewModel registerViewModel) { if (ModelState.IsValid) { if (!UserExists(registerViewModel.EmailAddress)) { switch (registerViewModel.UserType) { case "Customer": Customer customer = new Customer { Email = registerViewModel.EmailAddress, Password = EncryptionPassword(registerViewModel.Password), FirstName = registerViewModel.FirstName, LastName = registerViewModel.LastName }; _context.Customer.Add(customer); break; case "Client": Client client = new Client { Email = registerViewModel.EmailAddress, Password = EncryptionPassword(registerViewModel.Password), FirstName = registerViewModel.FirstName, LastName = registerViewModel.LastName }; _context.Client.Add(client); break; default: throw new ArgumentNullException(); } await _context.SaveChangesAsync(); ViewData["Message"] = "Registration succeed"; return(View("Login")); } } //TODO: Need to create UI for exception w/ message choose different email address throw new Exception("user email has already exist"); }