public API.NightSettings Transalte(NightSetting tableItem) { return new API.NightSettings { UID = tableItem.UID, NightEndTime = TimeSpan.FromMinutes(tableItem.NightEndTime), NightStartTime = TimeSpan.FromMinutes(tableItem.NightStartTime), OrganisationUID = tableItem.OrganisationUID.GetValueOrDefault() }; }
public OperationResult<bool> Save(API.NightSettings item) { return DbServiceHelper.InTryCatch(() => { bool isNew = false; var tableItem = Context.NightSettings.FirstOrDefault(x => x.UID == item.UID); if (tableItem == null) { tableItem = new NightSetting { UID = item.UID }; isNew = true; } tableItem.NightStartTime = (int)item.NightStartTime.TotalMinutes; tableItem.NightEndTime = (int)item.NightEndTime.TotalMinutes; tableItem.OrganisationUID = item.OrganisationUID.EmptyToNull(); if (isNew) Context.NightSettings.Add(tableItem); Context.SaveChanges(); return true; }); }