public SaveResult InsertOrUpdate(ref FamilyLogDTO familyLog) { try { using (OpenNosContext context = DataAccessHelper.CreateContext()) { long FamilyLog = familyLog.FamilyLogId; FamilyLog entity = context.FamilyLog.FirstOrDefault(c => c.FamilyLogId.Equals(FamilyLog)); if (entity == null) { familyLog = insert(familyLog, context); return(SaveResult.Inserted); } familyLog = update(entity, familyLog, context); return(SaveResult.Updated); } } catch (Exception e) { Logger.Error(string.Format(Language.Instance.GetMessageFromKey("UPDATE_FAMILYLOG_ERROR"), familyLog.FamilyLogId, e.Message), e); return(SaveResult.Error); } }
public static bool ToFamilyLogDTO(FamilyLog input, FamilyLogDTO output) { if (input == null) { return(false); } output.FamilyId = input.FamilyId; output.FamilyLogData = input.FamilyLogData; output.FamilyLogId = input.FamilyLogId; output.FamilyLogType = input.FamilyLogType; output.Timestamp = input.Timestamp; return(true); }
private static FamilyLogDTO insert(FamilyLogDTO famlog, OpenNosContext context) { FamilyLog entity = new FamilyLog(); Mapper.Mappers.FamilyLogMapper.ToFamilyLog(famlog, entity); context.FamilyLog.Add(entity); context.SaveChanges(); if (Mapper.Mappers.FamilyLogMapper.ToFamilyLogDTO(entity, famlog)) { return(famlog); } return(null); }
private static FamilyLogDTO update(FamilyLog entity, FamilyLogDTO famlog, OpenNosContext context) { if (entity != null) { Mapper.Mappers.FamilyLogMapper.ToFamilyLog(famlog, entity); context.SaveChanges(); } if (Mapper.Mappers.FamilyLogMapper.ToFamilyLogDTO(entity, famlog)) { return(famlog); } return(null); }
public DeleteResult Delete(long familyLogId) { try { using (OpenNosContext context = DataAccessHelper.CreateContext()) { FamilyLog famlog = context.FamilyLog.FirstOrDefault(c => c.FamilyLogId.Equals(familyLogId)); if (famlog != null) { context.FamilyLog.Remove(famlog); context.SaveChanges(); } return(DeleteResult.Deleted); } } catch (Exception e) { Logger.Error(string.Format(Language.Instance.GetMessageFromKey("DELETE_ERROR"), familyLogId, e.Message), e); return(DeleteResult.Error); } }