public HttpResponseMessage GetById(HttpRequestMessage request, int activityId)
        {
            var cardActivity = new CardActivity();

            var result = cardActivity.Get(activityId);

            return request.CreateResponse(HttpStatusCode.OK, result);
        }
        public CardActivity Add(CardActivity cardActivity)
        {
            using (var db = new CardsDBContext())
            {
                var result = db.CardActivities.Add(cardActivity);
                db.SaveChanges();

                return result;
            }
        }
Example #3
0
        public CardActivity Add(int cardID, CardActivityType cardActivityType, DateTime dateTime)
        {
            CardActivity cardActivity = new CardActivity()
            {
                CardID       = cardID,
                ActivityType = cardActivityType.ToString(),
                LoggedUser   = IdentityProvider.GetUserName(),
                LoggedDate   = dateTime
            };

            return StorageProvider.Add(cardActivity);
        }
Example #4
0
            public void WhenAdd_ShouldCardIDBeOne()
            {
                CardActivity subject = null;

                var storageProvider = new Mock<IStorageProvider>();
                storageProvider
                    .Setup(d => d.Add(It.IsAny<CardActivity>()))
                    .Callback<CardActivity>(a => subject = a)
                    .Returns(() => subject);

                var identityProvider = new Mock<IIdentityProvider>();
                identityProvider
                    .Setup(d => d.GetUserName())
                    .Returns("MIKADO");

                DateTime NOW = new DateTime(2014, 6, 13);
                CardActivity cardActivity = new CardActivity(storageProvider.Object, identityProvider.Object);

                subject = cardActivity.Add(1, CardActivityType.Add, NOW);

                subject.CardID.Should().Be(1);
            }
Example #5
0
            public void WhenInitialize_ShouldNotBeNull()
            {
                CardActivity subject = new CardActivity();

                subject.Should().NotBeNull();
            }
Example #6
0
            public void WhenInitialize_ShouldLoggedUserBeNull()
            {
                CardActivity subject = new CardActivity();

                subject.LoggedUser.Should().BeNull();
            }
Example #7
0
            public void WhenInitialize_ShouldLoggedDateBeMinDate()
            {
                CardActivity subject = new CardActivity();

                subject.LoggedDate.Should().Be(DateTime.MinValue);
            }
Example #8
0
 public void WhenInitialize_ShouldIDBeZero()
 {
     CardActivity subject = new CardActivity();
     subject.ID.Should().Be(0);
 }
Example #9
0
            public void WhenInitialize_ShouldActivityTypeBeNone()
            {
                CardActivity subject = new CardActivity();

                subject.ActivityType.Should().Be(null);
            }
Example #10
0
            public void WhenGet_ShouldNotBeNull()
            {
                DateTime NOW = new DateTime(2014, 6, 13);

                CardActivity subject = null;

                var storageProvider = new Mock<IStorageProvider>();
                storageProvider
                    .Setup(d => d.GetCardActivity(It.Is<int>(i => i == 1)))
                    .Returns(() => new CardActivity() { ID = 22, CardID = 3, ActivityType = CardActivityType.Modify.ToString(), LoggedDate = NOW, LoggedUser = "******" });

                CardActivity cardActivity = new CardActivity(storageProvider.Object, null);

                subject = cardActivity.Get(1);

                subject.Should().NotBeNull();
            }
Example #11
0
            public void WhenGet_ShouldCountBeTwo()
            {
                DateTime NOW = new DateTime(2014, 6, 13);

                var storageProvider = new Mock<IStorageProvider>();
                storageProvider
                    .Setup(d => d.GetAllCardActivities(It.Is<int>(i => i == 3)))
                    .Returns(() =>
                    {
                        return new List<CardActivity>()
                        {
                            new CardActivity() { ID = 22, CardID = 3, ActivityType = CardActivityType.Modify.ToString(), LoggedDate = NOW, LoggedUser = "******" },
                            new CardActivity() { ID = 22, CardID = 3, ActivityType = CardActivityType.Move.ToString(), LoggedDate = NOW, LoggedUser = "******" }
                        };
                    });

                CardActivity cardActivity = new CardActivity(storageProvider.Object, null);

                var subject = cardActivity.GetAll(3);

                subject.Count.Should().Be(2);
            }
Example #12
0
        private Card onUpdate(Card card, CardActivityType cardActivityType)
        {
            var dateNow = DateProvider.Now();

            card.ModifiedDate = dateNow;
            card.ModifiedUser = IdentityProvider.GetUserName();

            var cardResult = StorageProvider.Update(card);

            if (cardResult != null)
            {
                CardActivity cardActivity = new CardActivity(StorageProvider, IdentityProvider);

                cardResult.CardActivities.Add(cardActivity.Add(card.ID, cardActivityType, dateNow));
            }

            return cardResult;
        }
Example #13
0
        /// <summary>
        /// Removes the card with the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        public void Remove(int id)
        {
            var card = Get(id);

            if (card != null)
            {
                var NOW = DateProvider.Now();

                card.ModifiedDate = NOW;
                card.ModifiedUser = IdentityProvider.GetUserName();

                StorageProvider.RemoveCard(card);

                CardActivity cardActivity = new CardActivity(StorageProvider, IdentityProvider);

                cardActivity.Add(card.ID, CardActivityType.Delete, NOW);
            }
        }
Example #14
0
        /// <summary>
        /// Creates a card using the specified TFS WorkItem
        /// </summary>
        /// <param name="workItem">The work item.</param>
        /// <param name="areaID">The area identifier.</param>
        /// <returns></returns>
        public List<Card> Add(List<WorkItem> workItems, int areaID)
        {
            var dateNow     = DateProvider.Now();
            var currentUser = IdentityProvider.GetUserName();

            List<Card> result = new List<Card>();

            if (workItems != null)
            {
                foreach (var workItem in workItems)
                {
                    var cardToAdd = createCardFromWorkItem(areaID, workItem, dateNow, currentUser);

                    var storedCard = StorageProvider.Add(cardToAdd);

                    if (storedCard != null)
                    {
                        CardActivity activity = new CardActivity(StorageProvider, IdentityProvider);
                        storedCard.CardActivities.Add(activity.Add(storedCard.ID, CardActivityType.Add, dateNow));

                        result.Add(storedCard);
                    }
                }
            }

            return result;
        }
Example #15
0
        /// <summary>
        /// Adds the specified name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="description">The description.</param>
        /// <param name="assignedTo">The assigned to.</param>
        /// <param name="areaID">The area identifier.</param>
        /// <param name="tfsID">The TFS identifier.</param>
        /// <returns></returns>
        public Card Add(string name, string description, string assignedTo, int areaID, int tfsID)
        {
            var dateNow     = DateProvider.Now();
            var currentUser = IdentityProvider.GetUserName();

            var card = new Card()
            {
                CreatedUser = currentUser,
                CreatedDate = dateNow,
                ModifiedUser = currentUser,
                ModifiedDate = dateNow,

                Name        = name,
                Description = description,
                AreaID      = areaID,
                TfsID       = tfsID,
                AssignedTo  = assignedTo
            };

            var result = StorageProvider.Add(card);

            if (result != null)
            {
                CardActivity activity = new CardActivity(StorageProvider, IdentityProvider);
                activity = activity.Add(result.ID, CardActivityType.Add, dateNow);

                result.CardActivities.Add(activity);
            }

            return result;
        }