public BaseResponse GetIncomingMarkersInvitations(string userId) { var invitations = _markerRepository.GetIncomingMarkersInvitations(userId); var result = LocalMapper.Map <List <IncomingMarkerInviation> >(invitations); return(new SuccessResponse <List <IncomingMarkerInviation> >(result)); }
public BaseResponse GetUsersMarkers(string userId) { var dbMarkers = _markerRepository.GetUsersMarkers(userId); var result = LocalMapper.Map <List <Marker> >(dbMarkers); return(new SuccessResponse <List <Marker> >(result)); }
public IActionResult UpdateComment([FromBody] Comment comment) { var mappedComment = LocalMapper.Map <Business.Models.Comment.Comment>(comment); var response = _commentService.UpdateComment(mappedComment, Requestor.User.Id); return(response.GetActionResult <Business.Models.Comment.Comment, Comment>(this)); }
public BaseResponse GetPotentionalContacts(string userId, string userName) { var potentionalFriends = _contactsRepository.GetPotentionalContacts(userId, userName); var result = LocalMapper.Map <List <Contact> >(potentionalFriends); return(new SuccessResponse <List <Contact> >(result)); }
public async Task <IActionResult> UpdateUserData([FromBody] ApplicationUser applicationUser) { var mappedUser = LocalMapper.Map <Business.Models.User.ApplicationUser>(applicationUser); var response = await _userService.UpdateUser(Requestor.UserName, mappedUser); return(response.GetActionResult <Business.Models.User.ApplicationUser, ApplicationUser>(this)); }
public BaseResponse <bool> AcceptBlock(BlockBase blockBase) { if (blockBase == null) { return(new ErrorResponse <bool>("The block can not be null!", false)); } var lastBlock = _blockchainService.GetLastBlock(); if (blockBase is Block block && block.ParentUniqueId != lastBlock.UniqueId) { return(new ErrorResponse <bool>("The blockchain head has changed!", false)); } var validationResult = ValidateTransactionsDuplicates(blockBase); if (!validationResult.IsSuccess) { return(validationResult); } var mappedBlock = LocalMapper.Map <DAM.Block.BlockBase>(blockBase); _blockchainService.AddBlock(mappedBlock); DistributeBlock(mappedBlock); return(new SuccessResponse <bool>("The block has been accepted and appended!", true)); }
public ActionResult <BaseResponse> AddTransactions([FromBody] List <Transaction> transactions) { var mappedTransactions = LocalMapper.Map <List <BusinessLogic.Model.Transaction.Transaction> >(transactions); var result = _transactionService.AddTransactions(mappedTransactions); return(result.GetActionResult <List <BusinessLogic.Model.Transaction.Transaction>, List <Transaction> >(this)); }
public ActionResult <BaseResponse> AddTransaction([FromBody] Transaction transaction) { var mappedTransaction = LocalMapper.Map <BusinessLogic.Model.Transaction.Transaction>(transaction); var result = _transactionService.AddTransaction(mappedTransaction); return(result.GetActionResult <BusinessLogic.Model.Transaction.Transaction, Transaction>(this)); }
public ActionResult <BaseResponse> CreateScenario([FromBody] Scenario scenario) { var mappedScenario = LocalMapper.Map <BusinessLogic.Model.Scenarios.Scenario>(scenario); var response = _scenarioService.CreateScenario(mappedScenario); return(response.GetActionResult <BusinessLogic.Model.Scenarios.Scenario, Scenario>(this)); }
public ActionResult <BaseResponse> Start(Guid scenarioId, [FromBody] SimulationSettings settings) { var mappedSetting = LocalMapper.Map <BusinessLogic.Model.Scenarios.SimulationSettings>(settings); return(_simulationService.StartSimulation(scenarioId, mappedSetting) .GetActionResult <BusinessLogic.Model.Scenarios.Simulation, Simulation>(this)); }
public async Task <BaseResponse> UpdateUser(string userName, ApplicationUser applicationUser) { var user = await _userManager.FindByNameAsync(userName); if (user == null) { return(new ErrorResponse(new CustomApplicationException($"Could not find user with user name {userName}"))); } user.FirstName = applicationUser.FirstName; user.LastName = applicationUser.LastName; user.PhoneNumber = applicationUser.PhoneNumber; var result = await _userManager.UpdateAsync(user); if (result.Succeeded) { var mappedUser = LocalMapper.Map <ApplicationUser>(user); return(new SuccessResponse <ApplicationUser>(mappedUser)); } var errors = result.Errors.Select(e => new CustomApplicationException(e.Description)).ToArray(); return(new ErrorResponse(new CustomAggregatedException("Errors occurred during user update.", errors))); }
public ActionResult <BaseResponse> AddNode(Guid scenarioId, [FromBody] ServerNode serverNode) { var mappedNode = LocalMapper.Map <BusinessLogic.Model.Consensus.ServerNode>(serverNode); return(_simulationService.AddNode(scenarioId, mappedNode) .GetActionResult <BusinessLogic.Model.Scenarios.Simulation, Simulation>(this)); }
public IActionResult UpdateMarker([FromBody] Marker marker) { var mappedMarker = LocalMapper.Map <Business.Models.Marker.Marker>(marker); var response = _markerService.UpdateMarker(mappedMarker, Requestor.User.Id); return(response.GetActionResult <Business.Models.Marker.Marker, Marker>(this)); }
public BaseResponse AddMarker(Marker marker, string userId) { // Create images marker.Images = marker.Images.Select(i => _imageService.SaveImageAsync(i, Guid.NewGuid().ToString()).Result).ToList(); // Add marker to database var dbMarker = LocalMapper.Map <Data.Models.Marker>(marker); dbMarker.ApplicationUserId = userId; dbMarker = _markerRepository.AddMarker(dbMarker); // Add marker invitations to database var markerInvitations = new List <Data.Models.MarkerInvitation>(); if (marker.MarkerInvitations != null && marker.MarkerInvitations.Any()) { markerInvitations = CreateMarkerInvitations(dbMarker, marker.MarkerInvitations); markerInvitations = _markerRepository.AddMarkerInvitations(markerInvitations); } // Return mapped result var result = LocalMapper.Map <Marker>(dbMarker); result.MarkerInvitations = LocalMapper.Map <List <MarkerInvitation> >(markerInvitations); return(new SuccessResponse <Marker>(result)); }
public ActionResult <BaseResponse> ConnectNode([FromBody] ServerNode serverNode) { var mappedServerNode = LocalMapper.Map <BusinessLogic.Model.Consensus.ServerNode>(serverNode); var result = _consensusService.ConnectNode(mappedServerNode); return(result.GetActionResult <BusinessLogic.Model.Consensus.ServerNode, ServerNode>(this)); }
public async Task <IActionResult> Register([FromBody] ApplicationUser applicationUser) { var callbackUri = new Uri($"{Request.Scheme}://{Request.Host}{Url.Action(nameof(ConfirmEmailAddress))}", UriKind.Absolute); var user = LocalMapper.Map <Business.Models.User.ApplicationUser>(applicationUser); var response = await _userService.RegisterNewUser(user, callbackUri); return(response.GetActionResult <Business.Models.User.ApplicationUser, ApplicationUser>(this)); }
public ActionResult <BaseResponse> ChangeConfiguration(Guid scenarioId, [FromBody] BlockchainConfiguration configuration) { var mappedConfiguration = LocalMapper.Map <BusinessLogic.Model.Scenarios.BlockchainConfiguration>(configuration); return(_simulationService.ChangeConfiguration(scenarioId, mappedConfiguration) .GetActionResult <BusinessLogic.Model.Scenarios.Simulation, Simulation>(this)); }
public BaseResponse AddComment(Comment comment, string userId) { var dbComment = LocalMapper.Map <Data.Models.Comment>(comment); dbComment.ApplicationUserId = userId; dbComment = _commentRepository.AddComment(dbComment); return(new SuccessResponse <Comment>(LocalMapper.Map <Comment>(dbComment))); }
public BaseResponse DeleteContact(Guid contactId, string userId) { var contact = _contactsRepository.GetContact(contactId); var resultContact = contact.RequestedById == userId ? contact.RequestedTo : contact.RequestedBy; var result = LocalMapper.Map <Contact>(resultContact); _contactsRepository.DeleteContact(contact); return(new SuccessResponse <Contact>(result)); }
public BaseResponse GetIncomingInvitations(string userId) { var contactList = _contactsRepository.GetAllContacts(userId) .Where(c => c.RequestedToId == userId) .Where(c => c.Status == Data.Models.InvitationStatuses.PendingAcceptance).ToList(); var result = LocalMapper.Map <List <Inviation> >(contactList); result.ForEach(c => c.User.InvitationId = contactList.First(cl => cl.RequestedBy.UserName == c.User.UserName || cl.RequestedTo.UserName == c.User.UserName).Id); return(new SuccessResponse <List <Inviation> >(result)); }
private BaseResponse <bool> AcceptBlock(DAM.Block.BlockBase incomingBlock, string senderNodeId) { if (incomingBlock == null) { return(new ErrorResponse <bool>("The incoming block cannot be null!", false)); } if (_blockchainService.BlockExists(incomingBlock.UniqueId)) { _statisticService.RegisterRejectedBlock(); return(new ErrorResponse <bool>("The block already exists!", false)); } var mappedBlock = LocalMapper.Map <BlockBase>(incomingBlock); if (incomingBlock is DAM.Block.Block block && !incomingBlock.IsGenesis) { var parentBlockValidationResult = ValidateParentBlock(block, senderNodeId); if (!parentBlockValidationResult.IsSuccess) { _statisticService.RegisterRejectedBlock(); return(parentBlockValidationResult); } var parentBlock = _blockchainService.GetBlock(block.ParentUniqueId); if (parentBlock == null || parentBlock.Depth + 1 != mappedBlock.Depth) { _statisticService.RegisterRejectedBlock(); return(new ErrorResponse <bool>("The depth of incoming block is incorrect!", false)); } var mappedParentBlock = LocalMapper.Map <BlockBase>(parentBlock); ((Block)mappedBlock).Parent = mappedParentBlock; } var duplicatesValidationResult = ValidateTransactionsDuplicates(mappedBlock); if (!duplicatesValidationResult.IsSuccess) { return(duplicatesValidationResult); } var validationResult = _blockchainValidator.Validate(mappedBlock); if (!validationResult.IsSuccess) { _statisticService.RegisterRejectedBlock(); return(new ErrorResponse <bool>("The validation for the block failed!", false, validationResult.Errors)); } _blockchainService.AddBlock(incomingBlock); return(new SuccessResponse <bool>("The block has been accepted and appended!", true)); }
public async Task <BaseResponse> GetUser(string userName) { var user = await _userManager.FindByNameAsync(userName); if (user == null) { return(new ErrorResponse(new CustomApplicationException("User with given name not found."))); } var mappedUser = LocalMapper.Map <ApplicationUser>(user); return(new SuccessResponse <ApplicationUser>(mappedUser)); }
public BaseResponse RemoveComment(Guid commentId, string userId) { var comment = _commentRepository.GetCommentForUser(commentId, userId); if (comment == null) { return(new ErrorResponse(new CustomApplicationException($"Cannot find comment with id: {commentId}"))); } var result = _commentRepository.RemoveComment(comment); return(new SuccessResponse <Comment>(LocalMapper.Map <Comment>(result))); }
public BaseResponse GetMyContacts(string userId) { var contactList = _contactsRepository.GetAcceptedContacts(userId); var contacts = contactList.Where(c => c.RequestedById != userId).Select(c => c.RequestedBy) .Concat(contactList.Where(c => c.RequestedToId != userId).Select(c => c.RequestedTo)) .GroupBy(c => c.UserName).Select(g => g.First()).ToList(); var result = LocalMapper.Map <List <Contact> >(contacts); result.ForEach(c => c.InvitationId = contactList.First(cl => cl.RequestedBy.UserName == c.UserName || cl.RequestedTo.UserName == c.UserName).Id); return(new SuccessResponse <List <Contact> >(result)); }
public BaseResponse GetMarker(Guid markerId) { var dbMarker = _markerRepository.GetMarker(markerId); if (dbMarker == null) { return(new ErrorResponse(new CustomApplicationException($"Marker with id: {markerId} not found"))); } var result = LocalMapper.Map <Marker>(dbMarker); return(new SuccessResponse <Marker>(result)); }
public BaseResponse DeleteMarkerInvitation(string userId, Guid invitationId) { var invitation = _markerRepository.DeleteMarkerInvitation(userId, invitationId); if (invitation == null) { return(new ErrorResponse(new ApplicationException($"Cannot find invitation with id {invitationId} for user with id {userId}"))); } var result = LocalMapper.Map <IncomingMarkerInviation>(invitation); return(new SuccessResponse <IncomingMarkerInviation>(result)); }
public BaseResponse UpdateMarker(Marker marker, string userId) { var dbMarker = _markerRepository.GetMarker(marker.Id); if (dbMarker == null || dbMarker.ApplicationUserId != userId) { return(new ErrorResponse(new CustomApplicationException($"Marker with id: {marker.Id} not found"))); } UpdateDatabaseMarker(marker, dbMarker); var result = _markerRepository.UpdateMarker(dbMarker); return(new SuccessResponse <Marker>(LocalMapper.Map <Marker>(result))); }
public async Task <BaseResponse> SendInvitationAsync(string userId, string invitedUserName) { if (invitedUserName == null) { return(new ErrorResponse(new ArgumentNullException($"{nameof(invitedUserName)} cannot be null!"))); } var invitedUserResponse = await _userService.GetUser(invitedUserName); var invitedUser = (invitedUserResponse as SuccessResponse <ApplicationUser>)?.Result; if (invitedUser == null) { return(invitedUserResponse); } if (invitedUser.Id == userId) { return(new ErrorResponse(new ApplicationException("Cannot send invitation to itself!"))); } var myContactsResponse = GetPotentionalContacts(userId, invitedUserName); var myContacts = (myContactsResponse as SuccessResponse <List <Contact> >)?.Result; if (myContacts == null) { return(myContactsResponse); } if (myContacts.All(c => c.UserName != invitedUserName)) { return(new ErrorResponse(new ApplicationException("Contact already exists!"))); } var newContact = new Data.Models.Contact { CreateDate = DateTimeOffset.UtcNow, RequestedById = userId, RequestedToId = invitedUser.Id, Status = Data.Models.InvitationStatuses.PendingAcceptance }; _contactsRepository.AddContact(newContact); var result = LocalMapper.Map <Contact>(newContact); return(new SuccessResponse <Contact>(result)); }
public BaseResponse AcceptInvitation(Guid contactId, string userId) { var contact = _contactsRepository.GetContact(contactId); if (contact == null || contact.RequestedToId != userId) { return(new ErrorResponse(new ArgumentException($"User with id: {userId} does not own invitation with id ${contactId}"))); } contact.Status = Data.Models.InvitationStatuses.Accepted; _contactsRepository.UpdateContact(contact); var result = LocalMapper.Map <Contact>(contact.RequestedBy); return(new SuccessResponse <Contact>(result)); }
public BaseResponse UpdateMarkerInvitationStatus(string userId, Guid invitationId, InvitationStatuses invitationStatus) { var invitation = _markerRepository.GetIncomingMarkersInvitation(userId, invitationId); if (invitation == null) { return(new ErrorResponse(new ApplicationException($"Cannot find invitation with id {invitationId} for user with id {userId}"))); } invitation.InvitationStatus = (Data.Models.InvitationStatuses)((int)invitationStatus); _markerRepository.UpdateIncomingMarkersInvitation(invitation); var result = LocalMapper.Map <IncomingMarkerInviation>(invitation); return(new SuccessResponse <IncomingMarkerInviation>(result)); }