public JsonData Update(AgentBranch entity, string userId) { try { using (var db = new DataContext()) { if (entity == null) throw new ArgumentNullException("The record is" + " record is null"); var agentBranch = db.AgentBranches.FirstOrDefault(x => x.Id == entity.Id); if (agentBranch != null) { agentBranch.AgentId = entity.AgentId; agentBranch.BranchId = entity.BranchId; agentBranch.Updated = DateTime.Now; agentBranch.UpdatedById = userId; } db.SaveChanges(); return DataHelpers.ReturnJsonData(entity, true, "Updated successfully", 1); } } catch (Exception e) { return DataHelpers.ExceptionProcessor(e); } }
public JsonData Insert(AgentBranch entity, string userId) { try { using (var db = new DataContext()) { if (entity == null) throw new ArgumentNullException("The new" + " record is null"); var newData = new AgentBranch { BranchId = entity.BranchId, AgentId = entity.AgentId, Updated = DateTime.Now, Created = DateTime.Now, IsActive = true, IsDeleted = false, CreatedById = userId, UpdatedById = userId }; db.AgentBranches.Add(newData); db.SaveChanges(); return DataHelpers.ReturnJsonData(newData, true, "Saved successfully", 1); } } catch (Exception e) { return DataHelpers.ExceptionProcessor(e); } }