Beispiel #1
0
 public static void MapFromDb(VTurbine model, DTurbine db, IPrincipal user)
 {
     model.Id                 = db.Id;
     model.Author             = db.Author ?? "";
     model.Name               = db.Name ?? "";
     model.Description        = db.Description ?? "";
     model.Manufacturer       = db.Manufacturer ?? "";
     model.RatedPower         = db.RatedPower ?? 0;
     model.RotorDiameter      = db.RotorDiameter ?? 0;
     model.RotorOrientation   = db.RotorOrientation ?? "";
     model.RotorConfiguration = db.RotorConfiguration ?? "";
     model.Control            = db.Control ?? "";
     model.HubHeight          = db.HubHeight ?? 0;
     model.HubDiameter        = db.HubDiameter ?? 0;
     model.WindSpeedCutIn     = db.WindSpeedCutIn ?? 0;
     model.WindSpeedRated     = db.WindSpeedRated ?? 0;
     model.WindSpeedCutOut    = db.WindSpeedCutOut ?? 0;
     model.RotorSpeedCutIn    = db.RotorSpeedCutIn ?? 0;
     model.RotorSpeedRated    = db.RotorSpeedRated ?? 0;
     model.TipSpeedRated      = db.TipSpeedRated ?? 0;
     model.RotorMass          = db.RotorMass ?? 0;
     model.NacelleMass        = db.NacelleMass ?? 0;
     model.TowerMass          = db.TowerMass ?? 0;
     model.IsPublic           = db.IsPublic;
     model.CanEdit            = db.Author == user.Identity.Name;
 }
Beispiel #2
0
        public static VTurbine MapFromDb(DTurbine db, IPrincipal user)
        {
            var model = new VTurbine();

            MapFromDb(model, db, user);
            return(model);
        }
        public ActionResult EditSave(VTurbine model)
        {
            if (ModelState.IsValid)
            {
                SaveDB(model);
                if (model.ReturnTo == "list") return RedirectToAction("List", "Turbine", new { area = "WindFarms" });
                return RedirectToAction("Details", "Turbine", new { area = "WindFarms", id = model.Id });
            }

            return View("Edit", model);
        }
        public ActionResult Edit(Guid? id)
        {
            var model = new VTurbine();
            if (id == null)
            {
            }
            else
            {
                var db = _ctx.DTurbines.First(n => n.Id == id);
                model = VTurbine.MapFromDb(db, User);
            }

            return View("Edit", model);
        }
        private void SaveDB(VTurbine model)
        {
            DTurbine db;
            var now = DateTime.UtcNow;
            if (model.Id == Guid.Empty)
            {
                db = new DTurbine();
                db.Id = Guid.NewGuid();
                db.Created = now;
                db.Author = HttpContext.User.Identity.Name;

                model.Id = db.Id;

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

            db.Updated = now;
            db.Name = model.Name ?? "";
            db.Description = model.Description ?? "";
            db.Manufacturer = model.Manufacturer ?? "";
            db.RatedPower = model.RatedPower;
            db.RotorDiameter = model.RotorDiameter;
            db.RotorOrientation = model.RotorOrientation ?? "";
            db.RotorConfiguration = model.RotorConfiguration ?? "";
            db.Control = model.Control ?? "";
            db.HubHeight = model.HubHeight;
            db.HubDiameter = model.HubDiameter;
            db.WindSpeedCutIn = model.WindSpeedCutIn;
            db.WindSpeedRated = model.WindSpeedRated;
            db.WindSpeedCutOut = model.WindSpeedCutOut;
            db.RotorSpeedCutIn = model.RotorSpeedCutIn;
            db.RotorSpeedRated = model.RotorSpeedRated;
            db.TipSpeedRated = model.TipSpeedRated;
            db.RotorMass = model.RotorMass;
            db.NacelleMass = model.NacelleMass;
            db.TowerMass = model.TowerMass;

            _ctx.SaveChanges();
        }
 public static void MapFromDb(VTurbine model, DTurbine db, IPrincipal user)
 {
     model.Id = db.Id;
     model.Author = db.Author ?? "";
     model.Name = db.Name ?? "";
     model.Description = db.Description ?? "";
     model.Manufacturer = db.Manufacturer ?? "";
     model.RatedPower = db.RatedPower ?? 0;
     model.RotorDiameter = db.RotorDiameter ?? 0;
     model.RotorOrientation = db.RotorOrientation ?? "";
     model.RotorConfiguration = db.RotorConfiguration ?? "";
     model.Control = db.Control ?? "";
     model.HubHeight = db.HubHeight ?? 0;
     model.HubDiameter = db.HubDiameter ?? 0;
     model.WindSpeedCutIn = db.WindSpeedCutIn ?? 0;
     model.WindSpeedRated = db.WindSpeedRated ?? 0;
     model.WindSpeedCutOut = db.WindSpeedCutOut ?? 0;
     model.RotorSpeedCutIn = db.RotorSpeedCutIn ?? 0;
     model.RotorSpeedRated = db.RotorSpeedRated ?? 0;
     model.TipSpeedRated = db.TipSpeedRated ?? 0;
     model.RotorMass = db.RotorMass ?? 0;
     model.NacelleMass = db.NacelleMass ?? 0;
     model.TowerMass = db.TowerMass ?? 0;
     model.IsPublic = db.IsPublic;
     model.CanEdit = db.Author == user.Identity.Name;
 }
 public static VTurbine MapFromDb(DTurbine db, IPrincipal user)
 {
     var model = new VTurbine();
     MapFromDb(model, db, user);
     return model;
 }