/// <summary> /// Deprecated Method for adding a new object to the UnitTypes EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToUnitTypes(UnitType unitType) { base.AddObject("UnitTypes", unitType); }
public JsonResult CreateUnitType(UnitTypeModel model) { if (!ModelState.IsValid) { return Json(new { Result = "ERROR", Message = "Form is not valid! " + "Please correct it and try again." }); } if (!User.IsInRole("Officer")) { return Json(new { Result = "ERROR", Message = "You do not have the authority to create a new unit type." }); } try { JourListDMContainer dm = new JourListDMContainer(); UnitType newUnitType = new UnitType(); newUnitType.Description = model.Description; dm.AddToUnitTypes(newUnitType); dm.SaveChanges(); model.Id = newUnitType.Id; return Json(new { Result = "OK", Record = model }); } catch (Exception e) { return Json(new { Result = "ERROR", Message = e.Message }); } }
/// <summary> /// Create a new UnitType object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="description">Initial value of the Description property.</param> public static UnitType CreateUnitType(global::System.Int32 id, global::System.String description) { UnitType unitType = new UnitType(); unitType.Id = id; unitType.Description = description; return unitType; }