Example #1
0
        public SuccessfulMessageResponse CreateCard([FromBody] CardsCreationModel model, string token, long laneId)
        {
            var session       = IsTokenExpired(token);
            var laneToAddCard = _readOnlyRepository.GetById <Lane>(laneId);
            var board         = _readOnlyRepository.First <Board>(board1 => board1.Lanes.Contains(laneToAddCard));
            var account       = _readOnlyRepository.First <Account>(account1 => account1.Id == session.User.Id);

            if (laneToAddCard != null && account != null)
            {
                var cardToAdd = _mappingEngine.Map <CardsCreationModel, Card>(model);
                cardToAdd.IsArchived = false;
                cardToAdd.Position   = laneToAddCard.Cards.Count() + 1;
                cardToAdd.AddMember(account);
                account.AddCard(cardToAdd);
                laneToAddCard.AddCards(cardToAdd);
                Card cardCreated = _writeOnlyRepository.Create(cardToAdd);
                if (cardCreated != null)
                {
                    string activityDone = "Add " + cardCreated.Text + " to " + board.Title;
                    board.AddActivity(ActivityHelper.CreateActivity(session.User, activityDone));
                    return(new SuccessfulMessageResponse("Lane was successfully created"));
                }
            }
            throw new BadRequestException("YThis Lane does not exist");
        }
        public static CardModel CreateCard(CardsCreationModel cardCreate, string token)
        {
            var client  = new RestClient(BaseUrl);
            var request = InitRequest("/cards/create/" + token, Method.POST, cardCreate);
            IRestResponse <CardModel> response = client.Execute <CardModel>(request);

            return(response.Data);
        }