public bool GiBrukerAdminTilgang(Sjef innBruker, string brukernavn) { Dbkontekst dbs = new Dbkontekst(); DbTransaksjonerProsjekt DbTp = new DbTransaksjonerProsjekt(); if (!DbTp.ErEier(brukernavn,innBruker.ProsjektId)) { return false; } var AdminTilgang = dbs.Prosjektdeltakelser.FirstOrDefault(p => p.ProsjektId == innBruker.ProsjektId && p.BrukerId == innBruker.BrukerId); if (AdminTilgang == null) { return false; } try { AdminTilgang.Admin = true; dbs.SaveChanges(); return true; } catch (Exception feil) { return false; } }
public HttpResponseMessage Put(Sjef innBruker) { string userName = User.Identity.Name; bool ok = _BrukerBLL.FjernAdminTilgang(innBruker, userName); if (ok) { return new HttpResponseMessage() { StatusCode = HttpStatusCode.Created, }; } return new HttpResponseMessage() { StatusCode = HttpStatusCode.NotFound, Content = new StringContent("Feil") }; }
public HttpResponseMessage Post(Sjef innBruker) { string userName = User.Identity.Name; bool ok = _BrukerBLL.GiBrukerAdminTilgang(innBruker, userName); if (ok) { var response = Request.CreateResponse(HttpStatusCode.Created, innBruker); string uri = Url.Link("DefaultApi", null); response.Headers.Location = new Uri(uri); return response; } return new HttpResponseMessage() { StatusCode = HttpStatusCode.NotFound, Content = new StringContent("Feil") }; }
public bool GiBrukerAdminTilgang(Sjef innBruker, string brukernavn) { return _repository.GiBrukerAdminTilgang(innBruker, brukernavn); }
public void Put_Sjef_NOT_Found() { Sjef innBruker = new Sjef() { BrukerId = 1, ProsjektId = 1 }; Sjef innBruker1 = new Sjef() { BrukerId = 0, ProsjektId = 1 }; var commandBus = new Mock<IBrukerLogikk>(); commandBus.Setup(c => c.FjernAdminTilgang(innBruker, It.IsAny<string>())).Returns(true); // Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>(); var httpConfiguration = new HttpConfiguration(); WebApiConfig.Register(httpConfiguration); var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"], new HttpRouteValueDictionary { { "controller", "SjefApi" } }); var controller = new SjefController(commandBus.Object) { Request = new HttpRequestMessage(HttpMethod.Put, "http://localhost/api/SjefApi/") { Properties = { { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration }, { HttpPropertyKeys.HttpRouteDataKey, httpRouteData } } } }; // Act var response = controller.Put(innBruker1); // Assert Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); }
public void Fjern_AdminTilgang_Ok() { Sjef s = new Sjef(); s.BrukerId = 2; s.ProsjektId = 1; bool ok = this.mockProductRepository.FjernAdminTilgang(s, "*****@*****.**"); Assert.IsTrue(ok); }
public void Fjern_AdminTilgang_Feil() { Sjef s = new Sjef(); s.BrukerId = 2; s.ProsjektId = 1; bool ok = this.mockProductRepository.FjernAdminTilgang(s, "*****@*****.**"); Assert.IsFalse(ok); }