public async Task <IActionResult> Details(CarDetailsModel input) { input.CarCommentsInputModel.UserId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); await this.commentService.CreateAsync(input.CarCommentsInputModel); return(this.RedirectToAction("Details", new { id = input.CarCommentsInputModel.CarId })); }
public IActionResult Details(int id) { var car = _cars.GetById(id); var model = new CarDetailsModel { CarId = id, Model = car.Model, Manufacturer = car.Manufacturer, Cost = car.Cost, Status = car.Status.Name, CheckoutHistory = _checkouts.GetCheckoutHistory(id), LatestCheckout = _checkouts.GetLatestCheckout(id), ClientName = _checkouts.GetCurrentCheckoutClient(id), ReturnDate = _checkouts.GetCurrentCheckoutReturn(id), NumberOfDays = _checkouts.GetNumberOfDays(id), TotalCost = _checkouts.GetTotalCost(id), }; return(View(model)); }
public async Task <IActionResult> Details(string id) { if (id == null) { return(this.View("404Error")); } var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var car = await this.adService.GetCurrentCarAsync(id); if (car == null) { return(this.View("404Error")); } if (userId == null) { var uniqCarId = car.Make + car.Model + car.UserId + car.CreatedOn.ToString(); if (this.HttpContext.Request.Cookies[uniqCarId] == null || !this.HttpContext.Request.Cookies[uniqCarId].Contains(uniqCarId)) { var myId = Guid.NewGuid().ToString() + uniqCarId; var cookieOptions = new CookieOptions { IsEssential = true, MaxAge = new TimeSpan(365, 0, 0, 0), }; this.HttpContext.Response.Cookies.Append(uniqCarId, myId, cookieOptions); await this.viewService.AddViewAsync(GlobalConstants.NotRegisterUserId, car.Id); } } else { await this.viewService.AddViewAsync(userId, car.Id); } if (car.ImgsPaths == string.Empty) { car.ImgsPaths = GlobalConstants.DefaultImgCar; } var user = await this.userRepository.AllWithDeleted().FirstOrDefaultAsync(x => x.Id == car.UserId); var output = new CarDetailsModel { CarDetailsViewModel = new CarDetailsViewModel { Id = car.Id, Cc = car.Cc, Color = car.Color, Door = car.Door, EuroStandart = car.EuroStandart, Extras = car.Extras == null ? new List <string>() : car.Extras.Split(",", StringSplitOptions.RemoveEmptyEntries).ToList(), Fuel = car.Fuel, Gearbox = car.Gearbox, Horsepowers = car.Horsepowers, ImgsPaths = car.ImgsPaths.Split(",", StringSplitOptions.RemoveEmptyEntries).ToList(), Km = car.Km, Location = car.Location, Make = car.Make, Model = car.Model, Modification = car.Modification, MoreInformation = car.MoreInformation, Price = car.Price, Type = car.Type, Condition = car.Condition, User = user, UserId = car.UserId, YearOfProduction = car.YearOfProduction.ToString("MM.yyyy"), Comments = await this.commentService.GetComments <CarCommentViewModel>(car.Id), Views = this.viewService.GetViewsCount(id), IsApproved = car.IsApproved, IsDeleted = car.IsDeleted, CurrentUserId = userId, ModelToString = this.adService.EnumParser(car.Make.ToString(), car.Model), }, }; return(this.View(output)); }