Beispiel #1
0
        public static UpdateSeries MapUpdateSeries(Entities.UpdateSeries dbo)
        {
            var obj = new UpdateSeries();

            Mapper.Map(dbo, obj);

            obj.Updates  = GetUpdatesBySeriesId(obj.Id);
            obj.Versions = GetVersionsBySeriesId(obj.Id).Select(x => x.Id).ToList();

            return(obj);
        }
Beispiel #2
0
        public static UpdateSeries SaveUpdateSeries(UpdateSeries us)
        {
            var dbo = new Entities.UpdateSeries();

            using (var dc = new UpdateManagerClassesDataContext())
            {
                if (us.Id.Equals(Guid.Empty))
                {
                    us.Id           = Guid.NewGuid();
                    us.DateCreated  = DateTime.Now;
                    us.DateModified = DateTime.Now;

                    dbo = new Entities.UpdateSeries();
                    Mapper.Map(us, dbo);

                    dc.UpdateSeries.InsertOnSubmit(dbo);
                    dc.SubmitChanges();
                }
                else
                {
                    us.DateModified = DateTime.Now;

                    dbo = dc.UpdateSeries.SingleOrDefault(x => x.Id == us.Id);
                    if (dbo != null)
                    {
                        Mapper.Map(us, dbo);
                        dc.SubmitChanges();
                    }
                }

                dc.UpdatesVersions.DeleteAllOnSubmit(dc.UpdatesVersions.Where(x => x.UpdateSeriesId == us.Id));
                foreach (var g in us.Versions)
                {
                    dc.UpdatesVersions.InsertOnSubmit(new UpdatesVersion {
                        Id = Guid.NewGuid(), UpdateSeriesId = us.Id, VersionId = g
                    });
                }
                dc.SubmitChanges();

                return(MapUpdateSeries(dbo));
            }
        }