public async Task <IHttpActionResult> PutPageRating(int id, PageRating pageRating) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != pageRating.Id) { return(BadRequest()); } db.Entry(pageRating).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PageRatingExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> PutRating(long id, Rating rating) { if (id != rating.Id) { return(BadRequest()); } _context.Entry(rating).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RatingExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("TradeID,TradeType")] Trade trade) { if (ModelState.IsValid) { _context.Add(trade); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(trade)); }
public async Task <IActionResult> Create([Bind("CustomerID,FirstName,LastName,PhoneNumber,Email,City")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(customer)); }
public async Task <IActionResult> Create(/*[Bind("ContractorID,CustomerID,Rating,message")]*/ Review review) { // UPDATE Customers // SET ContactName = 'Alfred Schmidt', City = 'Frankfurt' // WHERE CustomerID = 1; //_context.Database.ExecuteSqlCommand review = new Review { ContractorID = review.ContractorID, CustomerID = review.CustomerID, Rating = review.Rating, message = review.message }; if (ModelState.IsValid) { _context.Add(review); await _context.SaveChangesAsync(); //Now we need to update our contractor table //find the contractor Contractor contractor = _context.Contractors.Where(c => c.ContractorID == review.ContractorID).SingleOrDefaultAsync().Result; //variable to hold values var contractorid = contractor.ContractorID; var businessName = contractor.BusinessName; var city = contractor.City; var email = contractor.Email; var firstName = contractor.FirstName; var lastName = contractor.LastName; var phoneNumber = contractor.PhoneNumber; var tradeID = contractor.TradeID; var reviewCount = contractor.ReviewCount + 1; var starTotal = contractor.ReviewStarTotal + review.Rating; var AverageRating = (double)starTotal / reviewCount; //query the database string sqlUpdate = $" UPDATE Contractor" + $" SET AverageRating = {AverageRating}, BusinessName = '{businessName}', City = '{city}', Email = '{email}', FirstName = '{firstName}'," + $" LastName = '{lastName}', PhoneNumber = '{phoneNumber}', ReviewCount = {reviewCount}, TradeID = {tradeID} , ReviewStarTotal = {starTotal}" + $" WHERE ContractorID = {contractorid}"; //update the database _context.Database.ExecuteSqlCommand(sqlUpdate); return(RedirectToAction("Index")); } ViewData["ContractorID"] = new SelectList(_context.Contractors, "ContractorID", "BusinessName", review.ContractorID); return(View(review)); }
public async Task <ActionResult> Create([Bind(Include = "Id,Date,Data")] RatingTableViewModel ratingTableViewModel) { if (ModelState.IsValid) { db.RatingTableViewModels.Add(ratingTableViewModel); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(ratingTableViewModel)); }
public async Task <IActionResult> Register(RegisterViewModel model, IList <IFormFile> files, //BPoirier: added file upload string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName,//BPoirier Custom properties LastName = model.LastName, City = model.City, PhoneNumber = model.PhoneNumber }; //create customer var customer = new Customer { Email = model.Email, FirstName = model.FirstName,//BPoirier Custom properties LastName = model.LastName, City = model.City, PhoneNumber = model.PhoneNumber }; var result = await _userManager.CreateAsync(user, model.Password); //this creates the user if (result.Succeeded) { _context.Add(customer); //Add customer inside customer Table if result Succeeded it should be good to go!!! await _context.SaveChangesAsync(); //save the database with new customer //============================ upload profile image =======================// foreach (var file in files) { //rename the file: 6847sdf456561sdf78.jpg var filename = user.Email + System.IO.Path.GetExtension(file.FileName); //this is the new fileName attached with user.id //tag on the path where we want to upload the image //filename = _hostingEnv.WebRootPath + $"\\images\\users\\{filename}"; //One way to do it filename = _hostingEnv.WebRootPath + $@"\images\users\{filename}"; //this would create \images\users\[email protected] using (System.IO.FileStream fs = System.IO.File.Create(filename)) { file.CopyTo(fs); fs.Flush(); // clear the memory like java } } //============================ End file upload ============================// // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=532713 // Send an email with this link //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); //var callbackUrl = Url.Action(nameof(ConfirmEmail), "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); //await _emailSender.SendEmailAsync(model.Email, "Confirm your account", // $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>"); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation(3, "User created a new account with password."); return(RedirectToLocal(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> Create(Contractor model, IList <IFormFile> files) //BPoirier: added file upload { var filename = ""; if (ModelState.IsValid) { //============================ upload profile image =======================// foreach (var file in files) { //rename the file: 6847sdf456561sdf78.jpg filename = model.FirstName + "_" + model.LastName + System.IO.Path.GetExtension(file.FileName); //this is the new fileName attached with user.id //tag on the path where we want to upload the image //filename = _hostingEnv.WebRootPath + $"\\images\\users\\{filename}"; //One way to do it filename = _hostingEnv.WebRootPath + $@"\images\users\{filename}";//this would create \images\users\[email protected] using (System.IO.FileStream fs = System.IO.File.Create(filename)) { file.CopyTo(fs); fs.Flush(); // clear the memory like java } } //============================ End file upload ============================// //create a new contractor var contractor = new Contractor { AverageRating = model.AverageRating, BusinessName = model.BusinessName, City = model.City, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, PhoneNumber = model.PhoneNumber, TradeID = model.TradeID, ReviewStarTotal = model.ReviewStarTotal, ReviewCount = model.ReviewCount, image = model.image //image = filename }; _context.Add(contractor); await _context.SaveChangesAsync(); //save the database with new customer //Now we need to update our contrator to put the image path in result //variable to hold values var contractorid = contractor.ContractorID; var businessName = contractor.BusinessName; var city = contractor.City; var email = contractor.Email; var firstName = contractor.FirstName; var lastName = contractor.LastName; var phoneNumber = contractor.PhoneNumber; var tradeID = contractor.TradeID; var reviewCount = contractor.ReviewCount; var starTotal = contractor.ReviewStarTotal; var AverageRating = contractor.AverageRating; var logo = ""; if (files == null) { logo = "imageNotFound" + ".jpg"; } else { //var logo = contractor.Email + ".jpg"; logo = contractor.FirstName + "_" + contractor.LastName + ".jpg"; } //query the database string sqlUpdate = $" UPDATE Contractor" + $" SET AverageRating = {AverageRating}, BusinessName = '{businessName}', City = '{city}', Email = '{email}', FirstName = '{firstName}'," + $" LastName = '{lastName}', PhoneNumber = '{phoneNumber}', ReviewCount = {reviewCount}, TradeID = {tradeID} , ReviewStarTotal = {starTotal}, image = '{logo}' " + $" WHERE ContractorID = {contractorid}"; //update the database _context.Database.ExecuteSqlCommand(sqlUpdate); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=532713 // Send an email with this link //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); //var callbackUrl = Url.Action(nameof(ConfirmEmail), "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); //await _emailSender.SendEmailAsync(model.Email, "Confirm your account", // $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>"); //await _signInManager.SignInAsync(user, isPersistent: false); //_logger.LogInformation(3, "User created a new account with password."); return(RedirectToAction("Index")); } ViewData["TradeID"] = new SelectList(_context.Trades, "TradeID", "TradeID"); return(View(model)); }