private void frmSimleCurrentDefinition_Load(object sender, EventArgs e) { if (_FormOpenType == FormOpenType.New) { __simleCurrent = new SimleCurrentDefinitionDTO(); } if (_FormOpenType == FormOpenType.Edit) { __simleCurrent = _repository.Run <SimleCurrentService, SimleCurrentDefinitionDTO>(x => x.Get_SimleCurrentDefinition(RecId)); } bs_SimpleCurrent.DataSource = __simleCurrent; }
public ActionResponse <SimleCurrentDefinitionDTO> Save_SimleCurrentDefinition(SimleCurrentDefinitionDTO model) { ActionResponse <SimleCurrentDefinitionDTO> response = new ActionResponse <SimleCurrentDefinitionDTO>() { Response = model, ResponseType = ResponseType.Ok }; using (MspDbContext _db = new MspDbContext()) { try { if (response.Response.RecId == 0) { _db.SimleCurrentDefinition.Add(base.Map <SimleCurrentDefinitionDTO, SimleCurrentDefinition>(model)); _db.SaveChanges(); } else { var entity = _db.SimleCurrentDefinition.FirstOrDefault(x => x.RecId == response.Response.RecId); if (entity != null) { base.SetLog <SimleCurrentDefinition, SimleCurrentDefinitionDTO>(entity, model, _db, response.Response.RecId); _db.Entry(entity).CurrentValues.SetValues(model); _db.Entry(entity).State = System.Data.Entity.EntityState.Modified; } } _db.SaveChanges(); } catch (Exception e) { response.Message = e.ToString(); response.ResponseType = ResponseType.Error; } } return(response); }