public ActionResult Share(ShareCar model) { try { var element = new RatingCar(); if (model.BodyId != -1) { element.Body = db.Body.FirstOrDefault(x => x.Id == model.BodyId); } if (model.BrandId != -1) { element.Brand = db.Brand.FirstOrDefault(x => x.Id == model.BrandId); } if (model.GenerationId != -1) { element.Generation = db.Generation.FirstOrDefault(x => x.Id == model.GenerationId); } if (model.ModelId != -1) { element.Model = db.Model.FirstOrDefault(x => x.Id == model.ModelId); } if (model.MotorId != -1) { element.Motor = db.Motor.FirstOrDefault(x => x.Id == model.MotorId); } var send = new RCViewVM(); if (element.Brand != null) { send.Brand = element.Brand.Id; } if (element.Body != null) { send.Body = element.Body.Id; } if (element.Generation != null) { send.Generation = element.Generation.Id; } if (element.Model != null) { send.Model = element.Model.Id; } if (element.Motor != null) { send.Motor = element.Motor.Id; } return(RedirectToAction("Car", send)); } catch (Exception e) { e.Data.Values.GetEnumerator(); } return(RedirectToAction("Index")); }
public async Task <ActionResult> Car(RCViewVM RatingCarViewVM) { if (RatingCarViewVM != null) { decimal Conveniences = 0, Failure = 0, Maintenance = 0; int number = 0; var comment = new List <Comment>(); var Brand = db.Brand.FirstOrDefault(x => x.Id == RatingCarViewVM.Brand); var Body = db.Body.FirstOrDefault(x => x.Id == RatingCarViewVM.Body); var Generation = db.Generation.FirstOrDefault(x => x.Id == RatingCarViewVM.Generation); var Model = db.Model.FirstOrDefault(x => x.Id == RatingCarViewVM.Model); var Motor = db.Motor.FirstOrDefault(x => x.Id == RatingCarViewVM.Motor); var ratingCarList = db.RatingCar.Where(x => x.Brand.Id == Brand.Id); if (Model != null) { ratingCarList = ratingCarList.Where(x => x.Model.Id == Model.Id); } if (Generation != null) { ratingCarList = ratingCarList.Where(x => x.Generation.Id == Generation.Id); } if (Body != null) { ratingCarList = ratingCarList.Where(x => x.Body.Id == Body.Id); } if (Motor != null) { ratingCarList = ratingCarList.Where(x => x.Motor.Id == Motor.Id); } foreach (var carRating in ratingCarList.ToList()) { if (carRating.Conveniences.Value != 0 && carRating.Failure.Value != 0 && carRating.Maintenance.Value != 0) { number++; Conveniences += carRating.Conveniences.Value; Failure += carRating.Failure.Value; Maintenance += carRating.Maintenance.Value; } var user = await UserManager.FindByIdAsync(carRating.UserId); var Avatar = db.Avatar.FirstOrDefault(x => x.UserId == carRating.UserId); var Massage = new Massage() { Description = carRating.Description, Conveniences = carRating.Conveniences.Description, Failure = carRating.Failure.Description, Maintenance = carRating.Maintenance.Description }; if (Avatar != null) { var Image = Convert.ToBase64String(Avatar.Fream, 0, Avatar.Fream.Length); comment.Add(new Comment { Email = user.Email, Massage = Massage, Image = "data:image/jpeg;base64," + Image }); } else { comment.Add(new Comment { Email = user.Email, Massage = Massage }); } } var model = new RatingCarEntityViewModels() { Brand = Brand, Body = Body, Generation = Generation, Model = Model, Motor = Motor, Conveniences = Conveniences, Failure = Failure, Maintenance = Maintenance, Comment = comment }; return(View(model)); } return(View()); }
public async Task <ActionResult> Add(AddRatingCarVM model) { try { var element = new RatingCar(); var user = await UserManager.FindByEmailAsync(User.Identity.Name); element.UserId = user.Id; if (model.BodyId != -1) { element.Body = db.Body.FirstOrDefault(x => x.Id == model.BodyId); } if (model.BrandId != -1) { element.Brand = db.Brand.FirstOrDefault(x => x.Id == model.BrandId); } if (model.GenerationId != -1) { element.Generation = db.Generation.FirstOrDefault(x => x.Id == model.GenerationId); } if (model.ModelId != -1) { element.Model = db.Model.FirstOrDefault(x => x.Id == model.ModelId); } if (model.MotorId != -1) { element.Motor = db.Motor.FirstOrDefault(x => x.Id == model.MotorId); } element.Description = model.Description; element.Conveniences = model.Conveniences; element.Failure = model.Failure; element.Maintenance = model.Maintenance; db.RatingCar.Add(element); await db.SaveChangesAsync(); var send = new RCViewVM(); if (element.Brand != null) { send.Brand = element.Brand.Id; } if (element.Body != null) { send.Body = element.Body.Id; } if (element.Generation != null) { send.Generation = element.Generation.Id; } if (element.Model != null) { send.Model = element.Model.Id; } if (element.Motor != null) { send.Motor = element.Motor.Id; } return(RedirectToAction("Car", send)); } catch (Exception e) { e.Data.Values.GetEnumerator(); } return(RedirectToAction("Index")); }