public ResponseWrapper <Granter> NewGranter([FromBody] Granter granter) { _dbContext.Granter.Add(granter); _dbContext.SaveChanges(); return(new ResponseWrapper <Granter>(granter)); }
public ResponseWrapper <bool> In([FromRoute] int deviceId, [FromRoute] string granterId) { Device device; try { device = CheckDevice(deviceId, granterId); } catch (RestReturnException e) { return(new ResponseWrapper <bool>(false, e.Value)); } var inObj = new InOut { Type = InOutType.In, Device = device, OnDate = DateTime.Now }; _dbContext.InOut.Add(inObj); _dbContext.SaveChanges(); return(new ResponseWrapper <bool>(true, Constants.RestReturn.OK)); }
public ResponseWrapper <Device> Link([FromRoute] string tempGuid) { LinkHolder link; if (!_memCache.TryGetValue <LinkHolder>(tempGuid, out link)) { return(new ResponseWrapper <Device>(Constants.RestReturn.ERR_LINK)); } var response = ClientUtils.GetROClient(Constants.A2BB_API_RESOURCE_NAME, Constants.A2BB_API_RO_CLIENT_ID, link.Username, link.Password); if (response.IsError) { return(new ResponseWrapper <Device>(Constants.RestReturn.ERR_INVALID_PASS)); } var sub = _dbContext.Subject.FirstOrDefault(s => s.Id == link.Subject); if (sub == null) { sub = new Subject { Id = link.Subject }; _dbContext.Subject.Add(sub); } sub.Device.Add(link.Device); _dbContext.SaveChanges(); link.IsEstabilished = true; return(new ResponseWrapper <Device>(link.Device, Constants.RestReturn.OK)); }
public ResponseWrapper <string> StartLink([FromBody] NewLinkRequestDTO req) { ClaimsHolder claimsHolder; try { claimsHolder = ClaimsUtils.ValidateUserClaimForIdSrvCall(User); } catch (RestReturnException ex) { return(new ResponseWrapper <string>(ex.Value)); } var sub = _dbContext.Subject.FirstOrDefault(s => s.Id == claimsHolder.Sub); if (sub == null) { sub = new Subject { Id = claimsHolder.Sub }; _dbContext.Subject.Add(sub); _dbContext.SaveChanges(); } var linkHolder = new LinkHolder { Device = req.Device, Username = claimsHolder.Name, Password = req.Password, Subject = claimsHolder.Sub, IsEstabilished = false }; var guid = Guid.NewGuid(); _memCache.Set(guid.ToString(), linkHolder, new MemoryCacheEntryOptions { SlidingExpiration = TimeSpan.FromSeconds(90) }); return(new ResponseWrapper <string>(guid.ToString(), Constants.RestReturn.OK)); }