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; } }
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; } }
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; } }
/// <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); }