Beispiel #1
0
 public static DeletedOrderReference GetInstance(IParticipantsReferences entity, IParticipantsReferences update)
 {
     return(new DeletedOrderReference
     {
         Id = entity.Id,
         CustomerId = update.CustomerId != entity.CustomerId
             ? entity.CustomerId
             : default,
 public static DeletedGroupReference GetInstance(IParticipantsReferences entity, IParticipantsReferences update)
 {
     return(new DeletedGroupReference
     {
         Id = entity.Id,
         TeacherId = update.TeacherId != entity.TeacherId
             ? entity.TeacherId
             : default,
        /// <summary>
        /// sets a reference to the group for all the specified object
        /// </summary>
        /// <param name="unitOfWork"></param>
        /// <param name="model"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static async Task SetAllReferences(this IUnitOfWork unitOfWork, IParticipantsReferences model, Action <IOrdersReference, Guid> action)
        {
            if (model.CustomerId != default)
            {
                var customer = await unitOfWork.Customers.GetByIdAsync(model.CustomerId);

                action?.Invoke((IOrdersReference)customer, model.Id);

                await unitOfWork.Customers.UpdateAsync(customer.Id, customer);
            }

            await model.ProductsIds?.SelectAsync(async id =>
            {
                var products = await unitOfWork.Products.GetByIdAsync(id);

                action?.Invoke((IOrdersReference)products, model.Id);

                await unitOfWork.Products.UpdateAsync(products.Id, products);
                return(id);
            });
        }
        /// <summary>
        /// Sets a reference to the group for all the specified objects
        /// </summary>
        /// <param name="unitOfWork"></param>
        /// <param name="model"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static async Task SetAllReferences(this IUnitOfWork unitOfWork, IParticipantsReferences model, Action <IGroupsReferense, Guid> action)
        {
            if (model.TeacherId != default)
            {
                var teacher = await unitOfWork.Employees.GetByIdAsync(model.TeacherId);

                /// teacher?.Groups.Add(model.Id);
                action?.Invoke(teacher, model.Id);

                await unitOfWork.Employees.UpdateAsync(teacher.Id, teacher);
            }

            await model.StudentsIds?.SelectAsync(async id =>
            {
                var student = await unitOfWork.Students.GetByIdAsync(id);
                /// student?.Groups.Add(model.Id);
                action?.Invoke(student, model.Id);

                await unitOfWork.Students.UpdateAsync(student.Id, student);
                return(id);
            });
        }