Beispiel #1
0
        public CreateStructureRetval CreateStructure(Structure structure, Location location)
        {
            try
            {
                DBStructure DBStruct = new DBStructure();
                structure.Sync(DBStruct);

                db.DBStructures.InsertOnSubmit(DBStruct);

                DBLocation DBLoc = new DBLocation();
                location.Sync(DBLoc);
                DBLoc.DBStructure = DBStruct;

                db.DBLocations.InsertOnSubmit(DBLoc);

                db.SubmitChanges();

                //Return new ID's to the caller
                CreateStructureRetval retval = new CreateStructureRetval(new Structure(DBStruct, false), new Location(DBLoc));
                return retval;
            }
            finally
            {
                if (db != null)
                    db.Connection.Close();
            }

            return null;
        }
Beispiel #2
0
        public Location CreateLocation(Location new_location, long[] links)
        {
            try
            {
                DBLocation db_obj = new DBLocation();
                string username = ServiceModelUtil.GetUserForCall();
                using (var transaction = new TransactionScope())
                {
                    //Create the object to get the ID
                    new_location.Sync(db_obj);
                    new_location.Username = username;
                    db.DBLocations.InsertOnSubmit(db_obj);

                    db.Log = Console.Out;
                    db.SubmitChanges();
                    Console.Out.Flush();

                    //Build a new location link for every link in the array
                    List<DBLocationLink> listLinks = new List<DBLocationLink>(links.Length);
                    foreach (long linked_locationID in links)
                    {
                        DBLocationLink created_link = _CreateLocationLink(db_obj.ID, linked_locationID, username);
                        listLinks.Add(created_link);
                    }

                    db.DBLocationLinks.InsertAllOnSubmit(listLinks);
                    db.SubmitChanges();
                    transaction.Complete();
                }

                Location output_loc = new Location(db_obj);
                output_loc.Links = links;
                return output_loc;
            }
            finally
            {
                if (db != null)
                    db.Connection.Close();
            }
        }