public ActionResult Save(CurrencyTypeViewModel vm) { if (ModelState.ContainsKey("FechaRegistro")) { ModelState["FechaRegistro"].Errors.Clear(); } var currency = Mapper.Map(vm, new CurrencyType()); if (ModelState.IsValid) { string mensaje = ""; if (currency.Id > 0) { db.CurrencyTypes.Attach(currency); db.Entry(currency).State = EntityState.Modified; db.SaveChanges(); mensaje = "Datos Actualizados."; } else { db.CurrencyTypes.Add(currency); db.SaveChanges(); mensaje = "Moneda Creada"; } var tempAccount = db.CurrencyTypes.Find(currency.Id); vm = Mapper.Map(tempAccount, new CurrencyTypeViewModel()); return Json(new { Result = "OK", Data = vm, Message = mensaje }); } return Json(new { Result = "ERROR", Message = "Hay Datos erroneos" }); }
public ActionResult Delete(CurrencyTypeViewModel vm) { try { var currency = Mapper.Map(vm, new CurrencyType()); db.CurrencyTypes.Attach(currency); db.CurrencyTypes.Remove(currency); db.SaveChanges(); return Json(new { Result = "OK", Message = "Elemento Eliminado." }); } catch (Exception ex) { return Json(new { Result = "Error", Message = ex.StackTrace }); } }