Exemplo n.º 1
0
        public ReturnModel Register([FromBody] OrganizationModel model, string accesToken)
        {
            var account =
                _readOnlyRepository.First <Account>(
                    account1 => account1.Token == accesToken);
            ReturnModel remodel = new ReturnModel();

            if (account != null)
            {
                if (account.VerifyToken(account))
                {
                    Organization organization        = _mappingEngine.Map <OrganizationModel, Organization>(model);
                    Organization organizationCreated = _writeOnlyRepository.Create(organization);
                    if (organizationCreated != null)
                    {
                        account.AddOrganization(organizationCreated);
                        Activity activity = new Activity();
                        activity.Text = account.FirstName + " Creo una organizacion";
                        account.AddActivities(activity);
                        var accountUpdate = _writeOnlyRepository.Update(account);

                        return(remodel.ConfigureModel("SuccessFull", "Se Creo satisfactoriamente la organizacion " + organizationCreated.Title, remodel));;
                    }
                }
                return(remodel.ConfigureModel("Error", "Su session ya expiro", remodel));
            }
            return(remodel.ConfigureModel("Error", "No se pudo acceder a su cuenta", remodel));
        }
Exemplo n.º 2
0
        public ReturnModel GetOrganizations(long lineId, string accessToken)
        {
            var         account = _readOnlyRepository.First <Account>(account1 => account1.Token == accessToken);
            ReturnModel remodel = new ReturnModel();

            if (account != null)
            {
                if (account.VerifyToken(account))
                {
                    var line = _readOnlyRepository.GetById <Lines>(lineId);
                    if (line != null)
                    {
                        ReturnCardsModel cardsModel = _mappingEngine.Map <Lines, ReturnCardsModel>(line);
                        var cards = new ReturnCardsModel();
                        cards.Cards = new List <Cards>();
                        foreach (var or in cardsModel.Cards)
                        {
                            if (!or.IsArchived)
                            {
                                var o = new Cards();
                                o.Text = or.Text;
                                o.Id   = or.Id;
                                cards.Cards.Add(o);
                            }
                        }
                        return(cards.ConfigureModel("Successfull", "", cards));
                    }
                }
                return(remodel.ConfigureModel("Error", "Su session ya expiro", remodel));
            }
            return(remodel.ConfigureModel("Error", "No se pudo acceder a su cuenta", remodel));
        }
Exemplo n.º 3
0
        public ReturnModel GetOrganizations(long organizationId, string accessToken)
        {
            var         account = _readOnlyRepository.First <Account>(account1 => account1.Token == accessToken);
            ReturnModel remodel = new ReturnModel();

            if (account != null)
            {
                if (account.VerifyToken(account))
                {
                    var organization = _readOnlyRepository.GetById <Organization>(organizationId);
                    if (organization != null)
                    {
                        ReturnBoardsModel boardsModel = _mappingEngine.Map <Organization, ReturnBoardsModel>(organization);
                        var boards = new ReturnBoardsModel();
                        boards.Boards = new List <Board>();
                        foreach (var or in boardsModel.Boards)
                        {
                            if (!or.IsArchived)
                            {
                                var o = new Board();
                                //o.Administrator = or.Administrator;
                                o.Title = or.Title;
                                o.Id    = or.Id;
                                boards.Boards.Add(o);
                            }
                        }
                        return(boards.ConfigureModel("Successfull", "", boards));
                    }
                }
                return(remodel.ConfigureModel("Error", "Su session ya expiro", remodel));
            }
            return(remodel.ConfigureModel("Error", "No se pudo acceder a su cuenta", remodel));
        }
Exemplo n.º 4
0
        public ReturnModel CreateBoard([FromBody] AccountBoardsModel model, long idOrganization, string accesToken)
        {
            var         account = _readOnlyRepository.First <Account>(account1 => account1.Token == accesToken);
            ReturnModel remodel = new ReturnModel();

            if (account != null)
            {
                if (account.VerifyToken(account))
                {
                    Organization organization = _readOnlyRepository.GetById <Organization>(idOrganization);
                    Board        board        = _mappingEngine.Map <AccountBoardsModel, Board>(model);
                    board.Administrator = account;
                    Board boardCreated = _writeOnlyRepository.Create(board);
                    if (boardCreated != null)
                    {
                        organization.AddBoard(boardCreated);
                        Activity activity = new Activity();
                        activity.Text = account.FirstName + " Creo un board";
                        account.AddActivities(activity);
                        var organizacionUpdate = _writeOnlyRepository.Update(organization);
                        var accountUpdate      = _writeOnlyRepository.Update(account);
                        return(remodel.ConfigureModel("Succesfull", "Se creo el board correctamente", remodel));
                    }
                    return(remodel.ConfigureModel("Error", "No se pudo crear el board", remodel));
                }
                return(remodel.ConfigureModel("Error", "Su session ya expiro", remodel));
            }
            return(remodel.ConfigureModel("Error", "No se pudo acceder a su cuenta", remodel));
        }
Exemplo n.º 5
0
        public ReturnModel GetOrganizations(string accessToken)
        {
            var         account = _readOnlyRepository.First <Account>(account1 => account1.Token == accessToken);
            ReturnModel remodel = new ReturnModel();

            if (account != null)
            {
                if (account.VerifyToken(account))
                {
                    ReturnOrganizationsModel organizationsmodel = _mappingEngine.Map <Account, ReturnOrganizationsModel>(account);
                    ReturnOrganizationsModel organ = new ReturnOrganizationsModel();
                    organ.Organizations = new List <Organization>();
                    foreach (var or in organizationsmodel.Organizations)
                    {
                        if (!or.IsArchived)
                        {
                            Organization o = new Organization();
                            o.Title = or.Title;
                            o.Id    = or.Id;
                            organ.Organizations.Add(o);
                        }
                    }
                    return(organ.ConfigureModel("Successfull", "", organ));
                }
                return(remodel.ConfigureModel("Error", "Su session ya expiro", remodel));
            }
            return(remodel.ConfigureModel("Error", "No se pudo acceder a su cuenta", remodel));
        }
Exemplo n.º 6
0
        public ReturnModel CreateLine([FromBody] LineModel model, long idBoard, string accesToken)
        {
            var account = _readOnlyRepository.First <Account>(account1 => account1.Token == accesToken);

            ReturnModel remodel = new ReturnModel();

            if (account != null)
            {
                if (account.VerifyToken(account))
                {
                    Board board       = _readOnlyRepository.GetById <Board>(idBoard);
                    Lines line        = _mappingEngine.Map <LineModel, Lines>(model);
                    Lines lineCreated = _writeOnlyRepository.Create(line);
                    if (lineCreated != null)
                    {
                        board.AddLine(lineCreated);
                        var      boardUpdate = _writeOnlyRepository.Update(board);
                        Activity activity    = new Activity();
                        activity.Text = account.FirstName + " Creo una Line en " + board.Title;
                        account.AddActivities(activity);
                        var accountUpdate = _writeOnlyRepository.Update(account);
                        return(remodel.ConfigureModel("Successfull", "Se creo exitosamente la line " + lineCreated.Title, remodel));
                    }
                    return(remodel.ConfigureModel("Error", "No se pudo crear la line", remodel));
                }
                return(remodel.ConfigureModel("Error", "Su session ya expiro", remodel));
            }
            return(remodel.ConfigureModel("Error", "No se pudo acceder a su cuenta", remodel));
        }
Exemplo n.º 7
0
        public ReturnModel CreateCard([FromBody] CardModel model, long idLine, string accesToken)
        {
            var account =
                _readOnlyRepository.First <Account>(
                    account1 => account1.Token == accesToken);

            ReturnModel remodel = new ReturnModel();

            if (account != null)
            {
                if (account.VerifyToken(account))
                {
                    Lines line        = _readOnlyRepository.GetById <Lines>(idLine);
                    Cards card        = _mappingEngine.Map <CardModel, Cards>(model);
                    Cards cardCreated = _writeOnlyRepository.Create(card);
                    if (cardCreated != null)
                    {
                        line.AddCard(cardCreated);
                        var      lineUpdate = _writeOnlyRepository.Update(line);
                        Activity activity   = new Activity();
                        activity.Text = account.FirstName + " Creo una card en " + line.Title;
                        account.AddActivities(activity);
                        var accountUpdate = _writeOnlyRepository.Update(account);
                        return(remodel.ConfigureModel("Successfull", "Se creo correctamente la card " + cardCreated.Text, remodel));
                    }
                    return(remodel.ConfigureModel("Error", "No se pudo crear la card", remodel));
                }
                return(remodel.ConfigureModel("Error", "Su session ya expiro", remodel));
            }
            return(remodel.ConfigureModel("Error", "No se pudo acceder a la cuenta", remodel));
        }
Exemplo n.º 8
0
        public ReturnModel MoveCardToLane([FromBody] MoveCardModel model, string accessToken)
        {
            var         account = _readOnlyRepository.First <Account>(account1 => account1.Token == accessToken);
            ReturnModel remodel = new ReturnModel();

            if (account != null)
            {
                if (account.VerifyToken(account))
                {
                    var   card  = _readOnlyRepository.GetById <Cards>(model.Id);
                    Cards card1 = new Cards();
                    card1.Text        = card.Text;
                    card1.Description = card.Description;
                    var line = _readOnlyRepository.GetById <Lines>(model.IdLineTo);

                    line.AddCard(card1);
                    var      archivedCard = _writeOnlyRepository.Archive(card);
                    var      updateLine   = _writeOnlyRepository.Update(line);
                    Activity activity     = new Activity();
                    activity.Text = account.FirstName + " Movio la card " + card.Text + " a la line: " + line.Title;
                    account.AddActivities(activity);
                    var accountUpdate = _writeOnlyRepository.Update(account);
                    return(remodel.ConfigureModel("Successfull", "Se movio correctamente la card", remodel));
                }
                return(remodel.ConfigureModel("Error", "Su session ya expiro", remodel));
            }
            return(remodel.ConfigureModel("Error", "No se pudo acceder a su cuenta", remodel));
        }
        public ReturnModel ResetPassword([FromBody] ResetPasswordModel model)
        {
            ReturnModel remodel = new ReturnModel();
            var         account = _readOnlyRepository.First <Account>(account1 => account1.Email == model.Email);

            if (account != null)
            {
                account.Password = Guid.NewGuid().ToString();
                account.Password = Encrypt(account.Password);
                var        tokenCreated = _writeOnlyRepository.Update(account);
                RestClient client       = new RestClient();
                client.BaseUrl       = "https://api.mailgun.net/v2";
                client.Authenticator =
                    new HttpBasicAuthenticator("api",
                                               "key-3v0eblygcsga9qlj7tnn34w0vk14q-k3");
                RestRequest request = new RestRequest();
                request.AddParameter("domain",
                                     "app6870.mailgun.org", ParameterType.UrlSegment);
                request.Resource = "{domain}/messages";
                request.AddParameter("from", "MiniTrello <*****@*****.**>");
                request.AddParameter("to", account.Email);
                request.AddParameter("to", account.Email);
                request.AddParameter("subject", "ResetPassword");
                request.AddParameter("text", "Utilice este codigo como contraseña para poder ingresar y CAMBIELA " + account.Password + "!");
                request.Method = Method.POST;
                client.Execute(request);
                return(remodel.ConfigureModel("Success", "Se le envio un mensaje a su correo", remodel));
            }
            return(remodel.ConfigureModel("Error", "No se pudo realizar la accion", remodel));
        }
Exemplo n.º 10
0
        public ReturnModel ChangeTitleBoard([FromBody] ChangeBoardsTitleModel model, string titleOrganization, string accesToken)
        {
            var         account = _readOnlyRepository.First <Account>(account1 => account1.Token == accesToken);
            ReturnModel remodel = new ReturnModel();

            if (account != null)
            {
                if (account.VerifyToken(account))
                {
                    var board = _readOnlyRepository.GetById <Board>(model.Id);
                    board.Title = model.NewTitle;
                    if (board.Administrator.Token.Equals(account.Token))
                    {
                        var      boardUpdate = _writeOnlyRepository.Update(board);
                        var      boardModel  = _mappingEngine.Map <Board, AccountBoardsModel>(boardUpdate);
                        Activity activity    = new Activity();
                        activity.Text = account.FirstName + " renombro el board a  " + board.Title;
                        account.AddActivities(activity);
                        var accountUpdate = _writeOnlyRepository.Update(account);
                        return(remodel.ConfigureModel("Successfull", "Se cambio el nombre del board correctamente", remodel));
                    }
                    return(remodel.ConfigureModel("Error", "No es el administrador no puede cambiar el nombre", remodel));
                }
                return(remodel.ConfigureModel("Error", "Su session ya expiro", remodel));
            }
            return(remodel.ConfigureModel("Error", "No se pudo acceder a su cuenta", remodel));
        }
Exemplo n.º 11
0
        public ReturnModel Login([FromBody] AccountLoginModel model)
        {
            var account =
                _readOnlyRepository.First <Account>(
                    account1 => account1.Email == model.Email && account1.Password == Encrypt(model.Password));

            ReturnModel remodel = new ReturnModel();

            if (account != null)
            {
                //account.TokenTime = BitConverter.GetBytes(DateTime.UtcNow.ToBinary());
                account.TokenTime = DateTime.Now;
                account.Token     = Guid.NewGuid().ToString();
                //account.Token = Convert.ToBase64String(account.TokenTime.Concat(account.TokenKey).ToArray()).Replace("/", "A").Replace("+", "B"); //.Replace(@"/", "").Replace(@"+","")

                var tokenCreated = _writeOnlyRepository.Update(account);
                if (tokenCreated != null)
                {
                    return new AuthenticationModel()
                           {
                               Token = account.Token
                           }
                }
                ;
            }
            return(remodel.ConfigureModel("Error", "NO se pudo acceder a su cuenta", remodel));
        }
Exemplo n.º 12
0
        public ReturnModel Activities(string accessToken)
        {
            var         account = _readOnlyRepository.First <Account>(account1 => account1.Token == accessToken);
            ReturnModel remodel = new ReturnModel();

            if (account != null)
            {
                if (account.VerifyToken(account))
                {
                    ReturnActivitiesModel activitiesmodel = _mappingEngine.Map <Account, ReturnActivitiesModel>(account);
                    return(activitiesmodel.ConfigureModel("Successfull", "", activitiesmodel));
                }
                return(remodel.ConfigureModel("Error", "Su session ya expiro", remodel));
            }
            return(remodel.ConfigureModel("Error", "No se pudo acceder a su cuenta", remodel));
        }
Exemplo n.º 13
0
        public ReturnModel Register([FromBody] AccountRegisterModel model)
        {
            ReturnModel remodel = new ReturnModel();

            if (model.Password != model.ConfirmPassword)
            {
                return(remodel.ConfigureModel("Error", "Las Claves no son iguales", remodel));
            }

            if (model.Password.Length <= 6 || Regex.IsMatch(model.Password, @"^[a-zA-Z]+$"))
            {
                return(remodel.ConfigureModel("Error", "la clave debe ser mayor a 6 caracteres y debe contener almenos un numero", remodel));
            }

            var accountExist = _readOnlyRepository.First <Account>(account1 => account1.Email == model.Email);

            if (accountExist == null)
            {
                Account account = _mappingEngine.Map <AccountRegisterModel, Account>(model);
                account.TokenTime = DateTime.Now;
                account.Password  = Encrypt(account.Password);
                Account accountCreated = _writeOnlyRepository.Create(account);
                if (accountCreated != null)
                {
                    ReturnRegisterModel registermodel = _mappingEngine.Map <Account, ReturnRegisterModel>(account);

                    RestClient client = new RestClient();
                    client.BaseUrl       = "https://api.mailgun.net/v2";
                    client.Authenticator = new HttpBasicAuthenticator("api", "key-3v0eblygcsga9qlj7tnn34w0vk14q-k3");
                    RestRequest request = new RestRequest();
                    request.AddParameter("domain", "app6870.mailgun.org", ParameterType.UrlSegment);
                    request.Resource = "{domain}/messages";
                    request.AddParameter("from", "MiniTrello <*****@*****.**>");
                    request.AddParameter("to", model.Email);
                    request.AddParameter("to", model.Email);
                    request.AddParameter("subject", "Registrado");
                    request.AddParameter("text", "Bienvenido a MiniTrello " + model.FirstName + "!");
                    request.Method = Method.POST;
                    client.Execute(request);
                    return(remodel.ConfigureModel("Successfull", "Se Registro Correctamente", registermodel));
                }
                return(remodel.ConfigureModel("Error", "Error al Guardar el Usuario", remodel));
            }
            return(remodel.ConfigureModel("Error", "Usuario ya existe", remodel));
        }
Exemplo n.º 14
0
        public ReturnModel UpdateData([FromBody] UpdateDataModel model, string accessToken)
        {
            var         account = _readOnlyRepository.First <Account>(account1 => account1.Token == accessToken);
            ReturnModel remodel = new ReturnModel();

            if (account != null)
            {
                if (account.VerifyToken(account))
                {
                    account.FirstName = model.FirstName;
                    account.LastName  = model.LastName;
                    var Updateaccount = _writeOnlyRepository.Update(account);
                    ReturnUpdateDataModel updatemodel = _mappingEngine.Map <Account, ReturnUpdateDataModel>(account);
                    return(updatemodel.ConfigureModel("Successfull", "Se actualizo correctamente su informacion", remodel));
                }
                return(remodel.ConfigureModel("Error", "Su session ya expiro", remodel));
            }
            return(remodel.ConfigureModel("Error", "No se pudo acceder a su cuenta", remodel));
        }
Exemplo n.º 15
0
        public ReturnModel Archive([FromBody] OrganizationArchiveModel model, string accesToken)
        {
            var         account = _readOnlyRepository.First <Account>(account1 => account1.Token == accesToken);
            ReturnModel remodel = new ReturnModel();

            if (account != null)
            {
                if (account.VerifyToken(account))
                {
                    var organization        = _readOnlyRepository.GetById <Organization>(model.Id);
                    var archiveOrganization = _writeOnlyRepository.Archive(organization);
                    ReturnOrganizationModel organizationmodel = new ReturnOrganizationModel();
                    organizationmodel = _mappingEngine.Map <Organization, ReturnOrganizationModel>(archiveOrganization);
                    return(organizationmodel.ConfigureModel("Successfull", "Se elimino satisfactoriamente " + organization.Title, organizationmodel));
                }
                return(remodel.ConfigureModel("Error", "Su session ya expiro", remodel));
            }
            return(remodel.ConfigureModel("Error", "No se pudo acceder a su cuenta", remodel));
        }
Exemplo n.º 16
0
        public ReturnModel GetOrganizations(long boardId, string accessToken)
        {
            ReturnModel remodel = new ReturnModel();

            try
            {
                var account = _readOnlyRepository.First <Account>(account1 => account1.Token == accessToken);

                if (account != null)
                {
                    if (account.VerifyToken(account))
                    {
                        var board = _readOnlyRepository.GetById <Board>(boardId);
                        if (board != null)
                        {
                            ReturnLinesModel boardsModel = _mappingEngine.Map <Board, ReturnLinesModel>(board);
                            var lines = new ReturnLinesModel();
                            lines.Lines = new List <Lines>();
                            foreach (var or in boardsModel.Lines)
                            {
                                if (!or.IsArchived)
                                {
                                    var o = new Lines();
                                    o.Title = or.Title;
                                    o.Id    = or.Id;
                                    lines.Lines.Add(o);
                                }
                            }
                            return(lines.ConfigureModel("Successfull", "", lines));
                        }
                    }
                    return(remodel.ConfigureModel("Error", "Su session ya expiro", remodel));
                }
                return(remodel.ConfigureModel("Error", "No se pudo acceder a su cuenta", remodel));
            }
            catch (Exception e)
            {
                return(remodel.ConfigureModel("Error", e.Message, remodel));
            }
        }
Exemplo n.º 17
0
        public ReturnModel AddMember([FromBody] AddMemberBoardModel model, string accesToken)
        {
            var         account = _readOnlyRepository.First <Account>(account1 => account1.Token == accesToken);
            ReturnModel remodel = new ReturnModel();

            if (account.VerifyToken(account))
            {
                var memberToAdd = _readOnlyRepository.GetById <Account>(model.MemberId);
                var board       = _readOnlyRepository.GetById <Board>(model.BoardId);
                board.AddMember(memberToAdd);
                var      updateBoard = _writeOnlyRepository.Update(board);
                var      boardModel  = _mappingEngine.Map <Board, AccountBoardsModel>(updateBoard);
                Activity activity    = new Activity();
                activity.Text = account.FirstName + " Agrego a " + memberToAdd.FirstName + " al board: " + board.Title;
                account.AddActivities(activity);
                return(boardModel);
            }
            return(remodel.ConfigureModel("Error", "Su session ya expiro", remodel));
        }
Exemplo n.º 18
0
        public ReturnModel DeleteBoard([FromBody] CardArchiveModel model, string accesToken)
        {
            var         account = _readOnlyRepository.First <Account>(account1 => account1.Token == accesToken);
            ReturnModel remodel = new ReturnModel();

            if (account != null)
            {
                if (account.VerifyToken(account))
                {
                    var      card         = _readOnlyRepository.GetById <Cards>(model.Id);
                    var      archivedCard = _writeOnlyRepository.Archive(card);
                    Activity activity     = new Activity();
                    activity.Text = account.FirstName + " elimino la card " + card.Text;
                    account.AddActivities(activity);
                    var       accountUpdate = _writeOnlyRepository.Update(account);
                    CardModel cardmodel     = _mappingEngine.Map <Cards, CardModel>(archivedCard);
                    return(cardmodel.ConfigureModel("Successfull", "Se borro exitosamente la card " + card.Text, cardmodel));
                }
            }
            return(remodel.ConfigureModel("Error", "Su session ya expiro", remodel));
        }
Exemplo n.º 19
0
        public ReturnModel DeleteBoard([FromBody] BoardArchiveModel model, string accesToken)
        {
            var         account = _readOnlyRepository.First <Account>(account1 => account1.Token == accesToken);
            ReturnModel remodel = new ReturnModel();

            if (account != null)
            {
                if (account.VerifyToken(account))
                {
                    var      board         = _readOnlyRepository.GetById <Board>(model.Id);
                    var      archivedBoard = _writeOnlyRepository.Archive(board);
                    Activity activity      = new Activity();
                    activity.Text = account.FirstName + " elimino el board: " + board.Title;
                    account.AddActivities(activity);
                    var accountUpdate             = _writeOnlyRepository.Update(account);
                    AccountBoardsModel boardmodel = _mappingEngine.Map <Board, AccountBoardsModel>(archivedBoard);
                    return(boardmodel.ConfigureModel("Successfull", "Se Borro el board correctamente", boardmodel));
                }
            }
            return(remodel.ConfigureModel("Error", "Su session ya expiro", remodel));
        }