Exemplo n.º 1
0
        public ActionResult CreateTestPlant()
        {
            if (!_plantRepository.IsDemoPlantExsting())
              {
            var plant = new SolarPlant()
            {
              Name = "Demo Anlage",
              Password = Utils.GenerateRandomString(6),
              PeakWattage = 50000,
              PostalCode = "123456",
              IsDemoPlant = true
            };

            var id = _plantRepository.CreatePlant(plant);

            _plantRepository.Cleanup();

            ViewData["Message"] = "Die Testanlage wurde erfolgreich angelegt.";
            return View("GenericAdminSuccess");
              }
              else
              {
            ViewData["Message"] = "Es ist bereits eine Testanlage vorhanden.";
            return View("GenericAdminFail");
              }
        }
Exemplo n.º 2
0
        /* SOLAR PLANT */
        /// <summary>
        /// Creates a new PV System by a given password
        /// </summary>
        /// <returns>The ID of the new pv system</returns>
        //public int CreatePlant(SolarPlant plant)
        //{
        //  return this.CreatePlant(plant, false);
        //}
        public int CreatePlant(SolarPlant plant)
        {
            //Add a new PV System to the plants table
              string insertPVText = @"INSERT INTO plants(Name, Password, IsDemoPlant, PostalCode, PeakWattage)
                                    VALUES (@Name, @Password, @isDemoPlant, @PostalCode, @PeakWattage);
                                    SELECT LAST_INSERT_ID() AS ID";

              var result = ProfiledWriteConnection.Query( insertPVText, plant ).First();

              return (int)result.ID;
        }
Exemplo n.º 3
0
        public ActionResult Add(SolarPlant model)
        {
            if (ModelState.IsValid)
              {
            model.Password = Utils.GenerateRandomString( 8 );
            var plantId = _plantRepository.CreatePlant( model );
            _plantRepository.StoreUserPlantRelation( CurrentUserId, plantId, E_PlantRole.Owner );

            return RedirectToAction( "View", new { id = plantId, name = model.Name } );
              }
              else
              {
            return View( model );
              }
        }
Exemplo n.º 4
0
        public void AddPlantTest()
        {
            var userId = 1337;

              //setup membership service
              var membershipMock = new Mock<IMembershipService>();
              membershipMock.SetupGet(x => x.CurrentUserId).Returns(userId);
              _plantController.MembershipService = membershipMock.Object;

            var plantModel = new SolarPlant()
            {
                Name = "test_plant",
                Password = "******"
            };

            _plantController.Add(plantModel);
            _plantRepositoryMock.Verify(x => x.CreatePlant(plantModel), Times.Once());
            _plantRepositoryMock.Verify(x => x.StoreUserPlantRelation(userId, It.IsAny<int>(), PVLog.Enums.E_PlantRole.Owner), Times.Once());
        }
Exemplo n.º 5
0
        public void UpdatePlantTest()
        {
            // create test plant
              var plant = DatabaseHelpers.CreatePlantWithOneInverter();

              //set new plant name
              SolarPlant plantToUpdate = new SolarPlant()
              {
            Name = "UpdatedPlant",
            PlantId = plant.PlantId,
            AutoCreateInverter = false,
            PeakWattage = 1843,
            PostalCode = "1543"
              };

              //verify old plant first
              Assert.IsTrue(_plantRepository.GetPlantById(plant.PlantId).AutoCreateInverter);

              //update plant
              _plantRepository.UpdatePlant(plantToUpdate);

              //verify plant name was updated
              var actual = _plantRepository.GetPlantById(plant.PlantId);
              Assert.AreEqual(plantToUpdate.Name, actual.Name);
              Assert.IsFalse(actual.AutoCreateInverter);
              Assert.AreEqual("1543", actual.PostalCode);
              Assert.AreEqual(1843, actual.PeakWattage);
        }
Exemplo n.º 6
0
 //public static ScriptUrl (this UrlHelper url,string path)
 //{
 //    return url.Content(path);
 //}
 public static string PlantUrl(this UrlHelper url, string text, string action, SolarPlant plant)
 {
     string name = HtmlExtensions.ResolveSubjectForUrl(plant.Name);
     return url.Action(action, new { id = plant.PlantId, name });
 }
Exemplo n.º 7
0
 public void UpdatePlant(SolarPlant plantToUpdate)
 {
     ProfiledWriteConnection.Execute( @"UPDATE plants
                                   SET Name = @name,
                                       AutoCreateInverter = @autoCreateInverter,
                                       PeakWattage = @peakWattage,
                                       PostalCode = @postalCode
                                 WHERE PlantId = @plantId", plantToUpdate );
 }
Exemplo n.º 8
0
 private PlantHeader GetHeaderModel(SolarPlant plant)
 {
     return new PlantHeader()
       {
     IsEditingAllowed = IsAuthorizedForPlant( plant.PlantId ),
     Plant = plant
       };
 }
Exemplo n.º 9
0
        public ActionResult Edit(SolarPlant model)
        {
            var plantToUpdate = _plantRepository.GetPlantById( model.PlantId );

              if (!IsAuthorizedForPlant( model.PlantId ))
            ThrowNotAuthorizedForPlantException();

              if (ModelState.IsValid)
              {
            // store all updated fields
            plantToUpdate.Name = model.Name;
            plantToUpdate.AutoCreateInverter = model.AutoCreateInverter;
            plantToUpdate.PeakWattage = model.PeakWattage;
            plantToUpdate.PostalCode = model.PostalCode;

            _plantRepository.UpdatePlant( plantToUpdate );

            ViewData["Message"] = "Ihre Änderungen wurden übernommen.";
              }
              return View( "EditPlant", plantToUpdate );
        }
Exemplo n.º 10
0
 public static MvcHtmlString PlantLink(this HtmlHelper html, string text, string action, SolarPlant plant)
 {
     string name = html.ResolveSubjectForUrl(plant.Name);
       return html.ActionLink(text, action, new { id = plant.PlantId, name });
 }