public MobilesVM GetById(int id) { MobilesVM data = GetMobilesById(id); // FirstOrDefault couse if not found id back null return(data); }
public IActionResult Edit(MobilesVM mob) { try { // check data validation if (ModelState.IsValid) { mobile.Edit(mob); return(RedirectToAction("Index", "Mobiles")); } else { return(View(mob)); } } catch (Exception /*ex*/) { //// using System.Diagnostics; //// this error mean i can't use EventLog on macOS just windows //EventLog log = new EventLog(); //log.Source = "Mobiles Page"; //log.WriteEntry(ex.Message, EventLogEntryType.Error); return(View(mob)); // return with data } }
public void Edit(MobilesVM mob) { var data = mapper.Map <Mobiles>(mob); db.Entry(data).State = Microsoft.EntityFrameworkCore.EntityState.Modified; db.SaveChanges(); }
public void Add(MobilesVM mob) { var data = mapper.Map <Mobiles>(mob); //var path = "/wwwroot/Files/Photos/"; data.ImageName = UploadeFileHelper.SaveFile(mob.ImageUrl, "Mobiles/"); db.Mobiles.Add(data); db.SaveChanges(); }