public OperationResult<bool> Save(RubezhAPI.GK.GKDaySchedule item) { return DbServiceHelper.InTryCatch(() => { bool isNew = false; var tableItem = Context.GKDaySchedules.Include(x => x.GKDayScheduleParts).FirstOrDefault(x => x.UID == item.UID); if (tableItem == null) { isNew = true; tableItem = new GKDaySchedule { UID = item.UID }; } else Context.GKDayScheduleParts.RemoveRange(tableItem.GKDayScheduleParts); tableItem.No = item.No; tableItem.Name = item.Name; tableItem.Description = item.Description; tableItem.GKDayScheduleParts = item.DayScheduleParts.Select(x => new GKDaySchedulePart { UID = Guid.NewGuid(), StartMilliseconds = x.StartMilliseconds, EndMilliseconds = x.EndMilliseconds }).ToList(); if (isNew) Context.GKDaySchedules.Add(tableItem); Context.SaveChanges(); return true; }); }
public RubezhAPI.GK.GKDaySchedule Translate(GKDaySchedule tableItem) { var result = new RubezhAPI.GK.GKDaySchedule(); result.UID = tableItem.UID; result.No = tableItem.No; result.Name = tableItem.Name; result.DayScheduleParts = tableItem.GKDayScheduleParts.Select(x => new RubezhAPI.GK.GKDaySchedulePart { StartMilliseconds = x.StartMilliseconds, EndMilliseconds = x.EndMilliseconds, }).OrderBy(x => x.StartMilliseconds).ToList(); return result; }
public void Seed() { if (!IsPostgres) { string journalClusteredIndex = GetIndexName("UID", "Journals"); if (journalClusteredIndex != null) SetPkNonclustered(journalClusteredIndex, "Journals"); } if (Organisations.Count() == 0) { var organisation = new Organisation { UID = Guid.NewGuid(), Name = "Организация", Users = new List<OrganisationUser> { new OrganisationUser { UID = Guid.NewGuid(), UserUID = new Guid("10e591fb-e017-442d-b176-f05756d984bb") } } }; Organisations.Add(organisation); } if (GKDaySchedules.Count() == 0) { var neverDaySchedule = new GKDaySchedule { UID = Guid.NewGuid(), Name = "<Никогда>", No = 1 }; GKDaySchedules.Add(neverDaySchedule); var alwaysDaySchedule = new GKDaySchedule { UID = Guid.NewGuid(), Name = "<Всегда>", No = 2 }; alwaysDaySchedule.GKDayScheduleParts.Add(new GKDaySchedulePart() { StartMilliseconds = 0, EndMilliseconds = (int)new TimeSpan(1, 0, 0, 0, 0).TotalMilliseconds }); GKDaySchedules.Add(alwaysDaySchedule); } }