public IActionResult Create(web_db._Weighing.TblCar model, IFormFile file) { if (!ModelState.IsValid) { ViewBag.error = "ثبت انجام نشد - فیلد ها را درست پر کنید"; return(View(model)); } try { var x = db.TblCars.Find(model.Id); if (x == null) { x = new web_db._Weighing.TblCar { Id = model.Id, PriceTowBascol = 0 }; db.TblCars.Add(x); } x.Title = model.Title; x.IsDel = model.IsDel; x.PriceTowBascol = model.PriceTowBascol; var dbdoc = new web_dbDocument.db_Context(); if (file != null) { var r = dbdoc.TblDocuments.FirstOrDefault(a => a.FkP == x.Id); if (r == null) { r = new web_dbDocument.TblDocument { Date = DateTime.Now, FkP = x.Id, fkuser = User._getuserid(), Id = Guid.NewGuid(), Kind = "Image" }; dbdoc.TblDocuments.Add(r); } r.Image = file.ToByteArray().imgTosmall(); } db.SaveChanges(); dbdoc.SaveChanges(); ViewBag.txt = "ثبت انجام شد"; Models.cl._ListCar = db.TblCars.OrderBy(a => a.Title).ToList(); return(RedirectToAction(nameof(Index))); } catch { ViewBag.error = "ثبت انجام نشد"; } return(View(model)); }
public car(web_db._Weighing.TblCar row) { this.Id = row.Id; this.Title = row.Title; //this.Img = row.Img; this.IsDel = row.IsDel; this.PriceTowBascol = row.PriceTowBascol; }
public IActionResult Create(Guid id) { var model = new web_db._Weighing.TblCar { Id = Guid.NewGuid(), IsDel = false }; var row = db.TblCars.Find(id); if (row != null) { model = row; } return(View(model)); }