Ejemplo n.º 1
0
        public async Task RenameCardListAsync(CardList cardList, string newName)
        {
            var foundCardList = await FindAndCheckNullabilityHelper <CardList> .InDatabaseAsync(context.CardLists, cardList, "Card list not found!", false);

            if (foundCardList.Name.Equals(newName))
            {
                throw new Exception("Names are equal!");
            }
            else
            {
                context.Entry <CardList>(foundCardList).State = EntityState.Detached;
                foundCardList.Name = newName;
                context.Entry <CardList>(foundCardList).State = EntityState.Modified;
            }
        }
Ejemplo n.º 2
0
        public async Task ChangeDueDateOfACardAsync(Card card, DateTime date)
        {
            try
            {
                var foundCard = await FindAndCheckNullabilityHelper <Card> .InDatabaseAsync(context.Cards, card, "Card not found!", false);

                if (foundCard.DueDate.Equals(date))
                {
                    throw new Exception("Dates are the same!");
                }
                else
                {
                    context.Entry <Card>(foundCard).State = EntityState.Detached;
                    foundCard.DueDate = date;
                    context.Entry <Card>(foundCard).State = EntityState.Modified;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 3
0
        public async Task RenameBoardAsync(Board board, string newName)
        {
            try
            {
                var foundBoard = await FindAndCheckNullabilityHelper <Board> .InDatabaseAsync(context.Boards, board, "Board was not found!", false);

                if (foundBoard.Name.Equals(newName))
                {
                    throw new Exception("Names are equal!");
                }
                else
                {
                    context.Entry <Board>(foundBoard).State = EntityState.Detached;
                    foundBoard.Name = newName;
                    context.Entry <Board>(foundBoard).State = EntityState.Modified;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Updates in <paramref name="context"/> an <paramref name="oldEntity"/> with values from <paramref name="newEntity"/>
        /// </summary>
        /// <param name="context">Context to work in</param>
        /// <param name="oldEntity">Old entity</param>
        /// <param name="newEntity">New entity from where to set values</param>
        /// <returns></returns>
        public static T UpdateEntity(KanbanSystemContext context, T oldEntity, T newEntity)
        {
            context.Entry(oldEntity).State = EntityState.Detached;
            var    type       = oldEntity.GetType();
            var    properties = type.GetProperties();
            object propValue  = null;
            var    propName   = "";

            foreach (var p in properties)
            {
                for (int i = 0; i < properties.Length; i++)
                {
                    propName = properties[i].Name;
                    if (i == 0 && propName.Contains("Id"))
                    {
                        continue;
                    }
                    propValue = type.GetProperty(propName).GetValue(newEntity);
                    properties[i].SetValue(oldEntity, propValue);
                }
            }
            context.Entry(oldEntity).State = EntityState.Modified;
            return(oldEntity);
        }