public ActionResult Rate(int id, Order order) { var oldOrder = orderRepository.Find(id); oldOrder.Rating = order.Rating * 20; oldOrder.RatingNotes = order.RatingNotes; if (ModelState.IsValid) { orderRepository.Update(id, oldOrder); //Start serviceProvider Rating var sprovider = oldOrder.Service.Sprovider; var ordersRating = orderRepository.List().Where(s => s.Rating > 0).Select(s => s.Rating); sprovider.Rating = 0; foreach (var item in ordersRating) { sprovider.Rating += item; } sprovider.Rating /= ordersRating.Count(); sproviderRepository.Update(sprovider.Id, sprovider); //End serviceProvider Rating return(RedirectToAction(nameof(CustomerOrders), new { customerId = oldOrder.CustomerId })); } return(View(order)); }
public async Task <IActionResult> Edit(int id, Sprovider sprovider) { if (ModelState.IsValid) { string UrlImage = ""; var files = HttpContext.Request.Form.Files; foreach (var Image in files) { if (Image != null && Image.Length > 0) { var file = Image; var uploads = Path.Combine(hostingEnvironment.WebRootPath, "uploads/sprovider"); if (file.Length > 0) { // var fileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(file.FileName); var fileName = Guid.NewGuid().ToString().Replace("-", "") + file.FileName; using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create)) { await file.CopyToAsync(fileStream); UrlImage = fileName; } } } } Sprovider newSprovider = sproviderRepository.Find(id); if (UrlImage != "") { var Directory = Path.Combine(hostingEnvironment.WebRootPath, "uploads/sprovider"); var fullPath = Path.Combine(Directory, newSprovider.Image); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } newSprovider.Image = UrlImage; } newSprovider.CompanyName = sprovider.CompanyName; newSprovider.CategoryId = sprovider.CategoryId; newSprovider.MapLocation = sprovider.MapLocation; sproviderRepository.Update(id, newSprovider); return(RedirectToAction(nameof(Index))); } return(View(sprovider)); }