Ejemplo n.º 1
0
        public IActionResult Update(int id, [FromBody] FacilityUpdateModel model)
        {
            var facility = _mapper.Map <Facility>(model);

            facility.Id = id;

            try
            {
                // update facility
                _facilityService.Update(facility);
                return(Ok("Successfully updated"));
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }
Ejemplo n.º 2
0
        public IHttpActionResult UpdateFacility(FacilityUpdateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                Cad.UpdateFacility(User.Identity.GetUserId(), model.Id, model.Level, model.Number);
            }
            catch (ConnectedApartmentsException e)
            {
                return(BadRequest(e.Message));
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
            return(GetResponse());
        }
Ejemplo n.º 3
0
        public UpdateFacilityTests()
        {
            facade = new Mock <IFacade>();

            var username          = "******";
            var identity          = new GenericIdentity(username, "");
            var nameIdentityClaim = new Claim(ClaimTypes.NameIdentifier, username);

            identity.AddClaim(nameIdentityClaim);

            var principal = new Mock <IPrincipal>();

            principal.Setup(p => p.Identity).Returns(identity);
            principal.Setup(p => p.IsInRole("Tenant")).Returns(true);

            model = new FacilityUpdateModel()
            {
                Level = "3", Number = "1", Id = 2
            };

            controllerContext = new HttpControllerContext {
                RequestContext = { Principal = principal.Object }
            };
        }