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));
        }
Exemplo n.º 2
0
        public BaseResponse GetIncomingMarkersInvitations(string userId)
        {
            var invitations = _markerRepository.GetIncomingMarkersInvitations(userId);
            var result      = LocalMapper.Map <List <IncomingMarkerInviation> >(invitations);

            return(new SuccessResponse <List <IncomingMarkerInviation> >(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 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));
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 9
0
        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)));
        }
Exemplo n.º 10
0
        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 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));
        }
Exemplo n.º 12
0
        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));
        }
Exemplo n.º 13
0
        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)));
        }
Exemplo n.º 14
0
        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));
        }
Exemplo n.º 15
0
        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));
        }
Exemplo n.º 17
0
        public BaseResponse <BlockBase> GetBlockchainTreeLinked()
        {
            var blockchain = _blockchainRepository.GetBlockchainTree();

            if (blockchain?.Blocks == null)
            {
                return(new ErrorResponse <BlockBase>("The blockchain tree does not contain blocks!", null));
            }

            var result = LocalMapper.ManualMap(blockchain);

            return(new SuccessResponse <BlockBase>("The blockchain from local storage.", result));
        }
Exemplo n.º 18
0
        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));
        }
Exemplo n.º 19
0
        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)));
        }
Exemplo n.º 20
0
        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));
        }
Exemplo n.º 21
0
        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));
        }
Exemplo n.º 22
0
        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));
        }
Exemplo n.º 23
0
        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)));
        }
Exemplo n.º 24
0
        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));
        }
Exemplo n.º 25
0
        public BaseResponse UpdateComment(Comment comment, string userId)
        {
            var dbComment = _commentRepository.GetCommentForUser(comment.Id, userId);

            if (dbComment == null)
            {
                return(new ErrorResponse(new CustomApplicationException($"Cannot find comment with id: {comment.Id}")));
            }

            dbComment.Text             = comment.Text;
            dbComment.ModificationDate = DateTimeOffset.UtcNow;

            var result = _commentRepository.UpdateComment(dbComment);

            return(new SuccessResponse <Comment>(LocalMapper.Map <Comment>(result)));
        }
Exemplo n.º 26
0
        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));
        }
Exemplo n.º 27
0
        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));
        }
Exemplo n.º 28
0
        public async Task <BaseResponse> RegisterNewUser(ApplicationUser applicationUser, Uri tokenCallback)
        {
            var mappedApplicationUser = LocalMapper.Map <Entities.ApplicationUser>(applicationUser);
            var createdUser           = await _userManager.CreateAsync(mappedApplicationUser, applicationUser.Password);

            if (createdUser == null)
            {
                return(new ErrorResponse(new ApplicationException("Created user is null!")));
            }
            if (createdUser.Succeeded)
            {
                var token = await _userManager.GenerateEmailConfirmationTokenAsync(mappedApplicationUser);
                await SendEmailConfirmation(applicationUser.Email, $"{applicationUser.FirstName} {applicationUser.LastName}", tokenCallback, applicationUser.UserName, token);

                return(new SuccessResponse <ApplicationUser>(applicationUser));
            }

            var exceptions = createdUser.Errors.Select(e => new CustomApplicationException(e.Description));

            return(new ErrorResponse(new CustomAggregatedException("Exceptions occurred during creating new user.", exceptions.ToArray())));
        }
Exemplo n.º 29
0
        public BaseResponse DeleteMarker(Guid markerId, string userId)
        {
            var markerToDelete = _markerRepository.GetMarker(markerId);

            if (markerToDelete == null || markerToDelete.ApplicationUserId != userId)
            {
                return(new ErrorResponse(new CustomApplicationException($"Marker with id: {markerId} not found")));
            }

            var result = LocalMapper.Map <Marker>(markerToDelete);

            result.Images.ForEach(i => _imageService.DeleteImage(i));

            _markerRepository.DeleteMarker(markerToDelete);
            if (markerToDelete.MarkerInvitations.Any())
            {
                _markerRepository.DeleteMarkerInvitations(markerToDelete.MarkerInvitations);
            }

            return(new SuccessResponse <Marker>(result));
        }
Exemplo n.º 30
0
        private async void RemoveNote_FromCollection(object sender)
        {
            if (sender != null)
            {
                var id = sender as string;

                //Add Notes to Server
                Animate      = true;
                Instructions = "Deleting Note";

                //Diagnostics
                string Message    = string.Empty;
                string StackTrace = string.Empty;
                bool   _HasError  = false;

                //Remove note
                await Task.Run(() =>
                {
                    try
                    {
                        this.Notes.RemoveAt(this.Notes.IndexOf(this.Notes.SingleOrDefault(w => w.ID == id)));
                        _notesManager.Delete_NoteById(id);

                        DataVaultWebServiceClient dataService = new DataVaultWebServiceClient(ConfigurationManager.InSecurePublicBinding(), new System.ServiceModel.EndpointAddress(Constants.Data_InSecureUrl));

                        var response = dataService._DeleteNote_ByID(id, Constants.InMemory_ContactID);
                        if (response.Errors.Count != 0)
                        {
                            response.Errors.ForEach(w =>
                            {
                                //Add to log table for diagnostics

                                if (this.logging != null)
                                {
                                    var log = LocalMapper.Map_LogWithMessage(w, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
                                    this.logging.AddLog(log);
                                }
                            });

                            _HasError = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        _HasError = true;

                        if (ex.InnerException != null)
                        {
                            Message    = ex.InnerException.Message;
                            StackTrace = ex.InnerException.StackTrace;
                        }
                        else
                        {
                            Message    = ex.Message;
                            StackTrace = ex.StackTrace;
                        }
                        var mEx = new Exceptions(logging, Message, StackTrace);
                        if (mEx != null)
                        {
                            mEx.HandleException(mEx, logging);
                        }
                    }
                }).ContinueWith((e) =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Animate = false;
                        //if (_HasError)
                        //    dialogue.ShowAlert("mmm...Something went wrong", Message);
                    });
                });
            }
        }