public IActionResult PostAlgorithm([FromBody] Algorithm algorithm) { try { context.Algorithms.Add(algorithm); context.SaveChanges(); string url = Url.ActionContext.HttpContext.Request.Path; return(Created(url, algorithm)); } catch (Exception ex) { return(StatusCode(500)); } }
public IActionResult PostFarmRight([FromBody] FarmRight farmRight) { try { context.FarmRights.Add(farmRight); context.SaveChanges(); string url = Url.ActionContext.HttpContext.Request.Path; return(Created(url, farmRight)); } catch (Exception ex) { return(StatusCode(500)); } }
public IActionResult PostUserInformation([FromBody] UserInformation userInformation) { try { context.UserInformations.Add(userInformation); context.SaveChanges(); string url = Url.ActionContext.HttpContext.Request.Path; return(Created(url, userInformation)); } catch (Exception ex) { return(StatusCode(500)); } }
public IActionResult PostManufacturer([FromBody] Manufacturer manufacturer) { try { context.Manufacturers.Add(manufacturer); context.SaveChanges(); string url = Url.ActionContext.HttpContext.Request.Path; return(Created(url, manufacturer)); } catch (Exception ex) { return(StatusCode(500)); } }
public IActionResult PostCoin([FromBody] Coin coin) { try { context.Coins.Add(coin); context.SaveChanges(); string url = Url.ActionContext.HttpContext.Request.Path; return(Created(url, coin)); } catch (Exception ex) { return(StatusCode(500)); } }
public IActionResult PostCoinALgorithm([FromBody]CoinAlgorithm coinAlgorithm) { try { if (context.Algorithms.Find(coinAlgorithm.AlgorithmId) == null || context.Coins.Find(coinAlgorithm.CoinId) == null) return BadRequest(); context.CoinAlgorithms.Add(coinAlgorithm); context.SaveChanges(); string url = Url.ActionContext.HttpContext.Request.Path; return Created(url, coinAlgorithm); } catch (Exception ex) { return StatusCode(500); } }
public IActionResult PostAddress([FromBody] Address address) { try { if (context.Countries.Find(address.CountryId) != null) { context.Addresses.Add(address); context.SaveChanges(); string url = Url.ActionContext.HttpContext.Request.Path; return(Created(url, address)); } return(BadRequest()); } catch (Exception ex) { return(StatusCode(500)); } }
public IActionResult PostShelf([FromBody] Shelf shelf) { try { if (context.Locations.Find(shelf.LocationId) == null) { return(BadRequest()); } context.Shelves.Add(shelf); context.SaveChanges(); string url = Url.ActionContext.HttpContext.Request.Path; return(Created(url, shelf)); } catch (Exception ex) { return(StatusCode(500)); } }
public IActionResult PostMiningFarm([FromBody] MiningFarm miningFarm) { try { if (context.Customers.Find(miningFarm.AdminCustomerId) == null) { return(BadRequest()); } context.MiningFarms.Add(miningFarm); context.SaveChanges(); string url = Url.ActionContext.HttpContext.Request.Path; return(Created(url, miningFarm)); } catch (Exception ex) { return(StatusCode(500)); } }
public IActionResult PostMinerAlgorithm([FromBody] MinerAlgorithm minerAlgorithm) { try { if (context.MinerTypes.Find(minerAlgorithm.MinerTypeId) == null || context.Algorithms.Find(minerAlgorithm.AlgorithmId) == null) { return(BadRequest()); } context.MinerAlgorithms.Add(minerAlgorithm); context.SaveChanges(); string url = Url.ActionContext.HttpContext.Request.Path; return(Created(url, minerAlgorithm)); } catch (Exception ex) { return(StatusCode(500)); } }
public IActionResult PostAdministrator([FromBody] Administrator administrator) { try { if (context.UserInformations.Find(administrator.UserInformation) != null) { context.Administrators.Add(administrator); context.SaveChanges(); string url = Url.ActionContext.HttpContext.Request.Path; return(Created(url, administrator)); } return(BadRequest()); } catch (Exception ex) { return(StatusCode(500)); } }
public IActionResult PostHostingPeriod([FromBody] HostingPeriod hostingPeriod) { try { if (context.Miners.Find(hostingPeriod.Id) == null) { return(BadRequest()); } context.HostingPeriods.Add(hostingPeriod); context.SaveChanges(); string url = Url.ActionContext.HttpContext.Request.Path; return(Created(url, hostingPeriod)); } catch (Exception ex) { return(StatusCode(500)); } }
public IActionResult PostBalance([FromBody] Balance balance) { try { if (context.Coins.Find(balance.CoinId) == null || context.MiningFarms.Find(balance.MiningFarmId) == null) { return(BadRequest()); } context.Balances.Add(balance); context.SaveChanges(); string url = Url.ActionContext.HttpContext.Request.Path; return(Created(url, balance)); } catch (Exception ex) { return(StatusCode(500)); } }
public IActionResult PostLocation([FromBody] Location location) { try { if (context.Addresses.Find(location.AddressId) == null) { return(BadRequest()); } context.Locations.Add(location); context.SaveChanges(); string url = Url.ActionContext.HttpContext.Request.Path; return(Created(url, location)); } catch (Exception ex) { return(StatusCode(500)); } }
public IActionResult PostMinerType([FromBody] MinerType minerType) { try { if (context.Manufacturers.Find(minerType.ManufacturerId) == null) { return(BadRequest()); } context.MinerTypes.Add(minerType); context.SaveChanges(); string url = Url.ActionContext.HttpContext.Request.Path; return(Created(url, minerType)); } catch (Exception ex) { return(StatusCode(500)); } }
public IActionResult PostLocationAdministrator([FromBody] LocationAdministrator locationAdministrator) { try { if (context.Locations.Find(locationAdministrator.LocationId) == null || context.Administrators.Find(locationAdministrator.AdministratorId) == null) { return(BadRequest()); } context.LocationAdministrators.Add(locationAdministrator); context.SaveChanges(); string url = Url.ActionContext.HttpContext.Request.Path; return(Created(url, locationAdministrator)); } catch (Exception ex) { return(StatusCode(500)); } }
public IActionResult PostFarmMember([FromBody] FarmMember farmMember) { try { if (context.FarmRights.Find(farmMember.FarmRightId) == null || context.Users.Find(farmMember.CustomerId) == null || context.MiningFarms.Find(farmMember.MiningFarmId) == null) { return(BadRequest()); } context.FarmMembers.Add(farmMember); context.SaveChanges(); string url = Url.ActionContext.HttpContext.Request.Path; return(Created(url, farmMember)); } catch (Exception ex) { return(StatusCode(500)); } }
public IActionResult PostCustomer([FromBody] Customer customer) { try { if (context.UserInformations.Find(customer.UserInformationId) == null || context.Addresses.Find(customer.AddressId) == null) { return(BadRequest()); } context.Customers.Add(customer); context.SaveChanges(); string url = Url.ActionContext.HttpContext.Request.Path; return(Created(url, customer)); } catch (Exception ex) { return(StatusCode(500)); } }
public IActionResult PostUserRolesAssociation([FromBody] UserRolesVM UserRolesVM) { if (ModelState.IsValid) { List <int> ClaimRolesIds = new List <int>(); foreach (var role in UserRolesVM.Roles) { //check roles exist? Roles rolesVM = context.Roles.FirstOrDefault(p => p.Role.ToLower().Equals(role.Role.ToLower())); if (rolesVM == null) { var addRole = context.Roles.Add(new Roles() { Role = role.Role }); context.SaveChanges(); role.Id = addRole.Entity.Id; } else { role.Id = rolesVM.Id; } foreach (var claim in role.Claims) { //check claims exist? Claims claimsVM = context.Claims.FirstOrDefault(p => p.Claim.ToLower().Equals(claim.Claim.ToLower())); if (claimsVM == null) { var addClaim = context.Claims.Add(new Claims() { Claim = claim.Claim }); context.SaveChanges(); claim.Id = addClaim.Entity.Id; } else { claim.Id = claimsVM.Id; } //check ClaimRoles exist? If not Add them... ClaimRoles claimRolesVM = context.ClaimRoles.FirstOrDefault(p => p.RolesId == role.Id && p.ClaimsId == claim.Id); if (claimRolesVM == null) { var claimRoles = context.ClaimRoles.Add(new ClaimRoles() { ClaimsId = claim.Id, RolesId = role.Id }); context.SaveChanges(); ClaimRolesIds.Add(claimRoles.Entity.Id); } else { ClaimRolesIds.Add(claimRolesVM.Id); } } //check UserClaimRoles exist.... foreach (var claimRolesId in ClaimRolesIds) { var UserClaimRoles = context.UserClaimRoles.FirstOrDefault(p => p.ClaimRolesId == claimRolesId && p.UserInformationId == new Guid(UserRolesVM.UserInformationId)); if (UserClaimRoles == null) { var userClaimRoles = context.UserClaimRoles.Add(new UserClaimRoles() { ClaimRolesId = claimRolesId, UserInformationId = new Guid(UserRolesVM.UserInformationId) }); context.SaveChanges(); } } } return(Ok()); } else { return(StatusCode(500)); } }