public async Task <ActionResult> Save(CarDetailModel carDetailModel) { try { if (carDetailModel.ImagesData != null && carDetailModel.ImagesData[0] != null) { carDetailModel.Images = new List <RentoImage>(); foreach (var item in carDetailModel.ImagesData) { var content = new byte[item.ContentLength]; item.InputStream.Read(content, 0, item.ContentLength); item.InputStream.Dispose(); carDetailModel.Images.Add(new RentoImage() { Content = content, FileName = item.FileName }); } Array.Clear(carDetailModel.ImagesData, 0, carDetailModel.ImagesData.Length); carDetailModel.ImagesData = null; } carDetailModel.DeletedImages = string.IsNullOrEmpty(carDetailModel.DeletedImageIds) ? new int[0] : carDetailModel.DeletedImageIds.Split(',').Select(Int32.Parse).ToArray(); var carSaveResponse = await CallApi <BaseEntity, Car>("Car/Save", carDetailModel); return(RentoJson(carSaveResponse)); } catch (Exception e) { Logger.Exception(e); } return(RentoJsonError()); }
// GET: Car/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Car car = carManager.Find(x => x.Id == id.Value); if (car == null) { return(HttpNotFound()); } var model = new CarDetailModel() { Car = car, YakitTipleri = LookupManager.GetLookups(LookupType.YakitTipi), VitesTipleri = LookupManager.GetLookups(LookupType.VitesTipi), MarkaTipleri = LookupManager.GetLookups(LookupType.Marka), KasaTipleri = LookupManager.GetLookups(LookupType.KasaTipi), LocationTipleri = LookupManager.GetLookups(LookupType.Locations), }; return(View(model)); }
public async Task <ActionResult> Create(int id = 0) { CarDetailModel model = null; try { ViewBag.Type = FixData.SYSTEM_TYPE; ViewBag.SubType = FixData._rentoSerializer.Serialize(FixData.SYSTEM_SUB_TYPE).Replace("\"", "'"); ViewBag.TypeJSON = FixData._rentoSerializer.Serialize(FixData.SYSTEM_TYPE).Replace("\"", "'"); ViewBag.StatusOption = GetCarStatus(true); if (id == 0) { ViewBag.ModelSubType = FixData.SYSTEM_SUB_TYPE.Where(c => c.ExternalData == 1); return(View()); } else { var carInfoResponse = await CallApi <int, Car>("Car/Get", id); if (carInfoResponse.ErrorCode != ErrorCode.Success) { return(RedirectToAction("Index")); } ViewBag.ModelSubType = FixData.SYSTEM_SUB_TYPE.Where(c => c.ExternalData == carInfoResponse.Data.Type); model = new CarDetailModel { AdditinalKiloCost = carInfoResponse.Data.AdditinalKiloCost, Color = carInfoResponse.Data.Color, DayCost = carInfoResponse.Data.DayCost, Description = carInfoResponse.Data.Description, Flag = carInfoResponse.Data.Flag, Id = carInfoResponse.Data.Id, ImageIds = carInfoResponse.Data.ImageIds, KiloLimit = carInfoResponse.Data.KiloLimit, KiloNumber = carInfoResponse.Data.KiloNumber, Model = carInfoResponse.Data.Model, MonthCost = carInfoResponse.Data.MonthCost, Status = carInfoResponse.Data.Status, SubType = carInfoResponse.Data.SubType, Type = carInfoResponse.Data.Type, WeekCost = carInfoResponse.Data.WeekCost, }; } } catch (Exception e) { Logger.Exception(e); } return(View(model)); }
// GET: Car/Create public ActionResult Create() { var model = new CarDetailModel() { Car = new Car(), YakitTipleri = LookupManager.GetLookups(LookupType.YakitTipi), VitesTipleri = LookupManager.GetLookups(LookupType.VitesTipi), MarkaTipleri = LookupManager.GetLookups(LookupType.Marka), KasaTipleri = LookupManager.GetLookups(LookupType.KasaTipi), LocationTipleri = LookupManager.GetLookups(LookupType.Locations), }; return(View(model)); }
public ActionResult Edit(CarDetailModel model, HttpPostedFileBase ProfileImage) { if (ModelState.IsValid) { if (ProfileImage != null && (ProfileImage.ContentType == "image/jpeg" || ProfileImage.ContentType == "image/jpg" || ProfileImage.ContentType == "image/png")) { string filename = $"user_{model.Car.Id}.{ProfileImage.ContentType.Split('/')[1]}"; ProfileImage.SaveAs(Server.MapPath($"~/Content/Admin/Content/Photos/Cars/{filename}")); model.Car.ImageUrl = filename; } Car db_car = carManager.Find(x => x.Id == model.Car.Id); db_car.IsActive = model.Car.IsActive; db_car.GunlukUcret = model.Car.GunlukUcret; db_car.KasaTipi = model.Car.KasaTipi; db_car.IndirimOrani = model.Car.IndirimOrani; db_car.SürücüYas = model.Car.SürücüYas; db_car.VitesTipi = model.Car.VitesTipi; db_car.YakitTipi = model.Car.YakitTipi; db_car.Marka = model.Car.Marka; db_car.Locations = model.Car.Locations; db_car.Yıl = model.Car.Yıl; db_car.ArabaAdi = model.Car.ArabaAdi; db_car.Depozito = model.Car.Depozito; db_car.EhliyetYas = model.Car.EhliyetYas; db_car.ImageUrl = model.Car.ImageUrl; carManager.Update(db_car); return(RedirectToAction("Index", "Car")); } return(View(model)); }
public ActionResult Create(CarDetailModel model, HttpPostedFileBase ProfileImage) { if (ModelState.IsValid) { if (ProfileImage != null && (ProfileImage.ContentType == "image/jpeg" || ProfileImage.ContentType == "image/jpg" || ProfileImage.ContentType == "image/png")) { carManager.Insert(model.Car); string filename = $"user_{model.Car.Id}.{ProfileImage.ContentType.Split('/')[1]}"; ProfileImage.SaveAs(Server.MapPath($"~/Content/Admin/Content/Photos/Cars/{filename}")); model.Car.ImageUrl = filename; carManager.Save(); } return(RedirectToAction("Index", "Car")); } else { return(View(model)); } }