예제 #1
0
        public async Task UpdateAsync(Guid id, GroupUpdate model)
        {
            Has.NotNull(model);

            if (!id.Equals(model.Id))
            {
                throw new InvalidOperationException($"The IDs don't match: {id} and {model.Id}");
            }

            var entity = await _unitOfWork.Groups.GetByIdAsync(model.Id);

            /// This is not a bug but a feature:
            /// When you change the reference to the group in the Student and Employee objects is not deleted so you have to delete it manually
            await _unitOfWork.SetAllReferences(DeletedGroupReference.GetInstance(entity, model));

            /// Adding new links received from the UI
            await _unitOfWork.SetAllReferences(InsertedGroupReference.GetInstance(entity, model));

            await _unitOfWork.Groups.UpdateAsync(id, _mapper.Map(model, entity));
        }
 public static async Task SetAllReferences(this IUnitOfWork unitOfWork, InsertedGroupReference model)
 {
     await ReferenceHalper.SetAllReferences(unitOfWork, model, (@ref, id) => @ref.Groups.Add(id));
 }