/// <summary>
 /// Deprecated Method for adding a new object to the DWindFarms EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDWindFarms(DWindFarm dWindFarm)
 {
     base.AddObject("DWindFarms", dWindFarm);
 }
 /// <summary>
 /// Create a new DWindFarm object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="isPublic">Initial value of the IsPublic property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="country">Initial value of the Country property.</param>
 /// <param name="urlOfficial">Initial value of the UrlOfficial property.</param>
 /// <param name="urlPublicWiki">Initial value of the UrlPublicWiki property.</param>
 /// <param name="description">Initial value of the Description property.</param>
 /// <param name="geoLat">Initial value of the GeoLat property.</param>
 /// <param name="geoLng">Initial value of the GeoLng property.</param>
 /// <param name="totalCapacity">Initial value of the TotalCapacity property.</param>
 public static DWindFarm CreateDWindFarm(global::System.Guid id, global::System.Boolean isPublic, global::System.String name, global::System.String country, global::System.String urlOfficial, global::System.String urlPublicWiki, global::System.String description, global::System.Decimal geoLat, global::System.Decimal geoLng, global::System.Decimal totalCapacity)
 {
     DWindFarm dWindFarm = new DWindFarm();
     dWindFarm.Id = id;
     dWindFarm.IsPublic = isPublic;
     dWindFarm.Name = name;
     dWindFarm.Country = country;
     dWindFarm.UrlOfficial = urlOfficial;
     dWindFarm.UrlPublicWiki = urlPublicWiki;
     dWindFarm.Description = description;
     dWindFarm.GeoLat = geoLat;
     dWindFarm.GeoLng = geoLng;
     dWindFarm.TotalCapacity = totalCapacity;
     return dWindFarm;
 }
        private Guid CopyWindFarm(DWindFarm copiedDb)
        {
            DWindFarm db;
            db = new DWindFarm();
            db.Id = Guid.NewGuid();
            db.Created = DateTime.UtcNow;
            db.Author = HttpContext.User.Identity.Name;

            _ctx.DWindFarms.AddObject(db);

            db.Updated = DateTime.UtcNow;
            var copiedDbName = copiedDb.Name;
            var copyNumber = 1;
            var dbName = string.Empty;
            while (true)
            {
                dbName = string.Format("{0} ({1})", copiedDbName, copyNumber);
                if (!_ctx.DWindFarms.Any(wf => (string.Compare(wf.Name, dbName, false) == 0)))
                {
                    break;
                }
                copyNumber++;
            }
            db.Name = dbName;
            db.Country = copiedDb.Country;
            db.Description = copiedDb.Description;
            db.GeoLat = copiedDb.GeoLat;
            db.GeoLng = copiedDb.GeoLng;
            db.TotalCapacity = copiedDb.TotalCapacity;
            db.UrlOfficial = copiedDb.UrlOfficial;
            db.UrlPublicWiki = copiedDb.UrlPublicWiki;
            db.IsPublic = copiedDb.IsPublic;
            //db.Rating
            //db.TurbineTypeId
            //_ctx.SaveChanges();

            _ctx.DWindFarmTurbines.Where(wft => wft.WindFarmId == copiedDb.Id).ForEach(
                wft =>
                {
                    _ctx.DWindFarmTurbines.AddObject(
                        new DWindFarmTurbine
                        {
                            Id = Guid.NewGuid(),
                            WindFarmId = db.Id,
                            Number = wft.Number,
                            X = wft.X,
                            Y = wft.Y,
                            Z = wft.Z
                        }
                    );
                }
            );
            _ctx.SaveChanges();

            return db.Id;
        }
        private void SaveDB(VWindFarm model)
        {
            DWindFarm db;
            if (model.Id == Guid.Empty)
            {
                db = new DWindFarm();
                db.Id = Guid.NewGuid();
                db.Created = DateTime.UtcNow;
                db.Author = HttpContext.User.Identity.Name;

                model.Id = db.Id;

                _ctx.DWindFarms.AddObject(db);
            }
            else
            {
                db = _ctx.DWindFarms.First(n => n.Id == model.Id);
            }

            db.Updated = DateTime.UtcNow;
            db.Name = model.Name ?? "";
            db.Country = model.Country ?? "";
            db.Description = model.Description ?? "";
            db.GeoLat = model.GeoLat;
            db.GeoLng = model.GeoLng;
            db.TotalCapacity = model.TotalCapacity;
            db.UrlOfficial = model.UrlOfficial ?? "";
            db.UrlPublicWiki = model.UrlPublicWiki ?? "";
            db.IsPublic = false;
            _ctx.SaveChanges();
        }
Example #5
0
 public static void MapFromDb(VWindFarm model, DWindFarm db, IPrincipal user)
 {
     var mapper = ObjectMapperManager.DefaultInstance.GetMapper<DWindFarm, VWindFarm>();
     mapper.Map(db, model);
     model.Turbines.AddRange(new VTurbine[db.DWindFarmTurbines.Count]);
     model.CanEdit = db.Author == user.Identity.Name;
 }
Example #6
0
 public static VWindFarm MapFromDb(DWindFarm db, IPrincipal user)
 {
     var model = new VWindFarm();
     MapFromDb(model, db, user);
     return model;
 }