/// <summary> /// Добавить тарновера с днями в цикловой график /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <TurnoverWithDays> AddTurnoverWithDays(TurnoverWithDays input) { //Начинаем блядь КВН using (var transaction = new TransactionScope(asyncFlowOption: TransactionScopeAsyncFlowOption.Enabled)) { var sqlRTurnovers = new TurnoversRepoisitory(_logger); var sqlRDays = new DayOfRoutesRepoisitory(_logger); var turnover = await sqlRTurnovers.Add(_mapper.Map <TurnoverWithDays, Turnover>(input)); var result = _mapper.Map <Turnover, TurnoverWithDays>(turnover); result.Days = new List <DayOfWeek>(); foreach (var inputDay in input.Days) { var day = await sqlRDays.Add(new DayOfRoute { TurnoverId = result.Id, Day = inputDay }); result.Days.Add(day.Day); } transaction.Complete(); return(result); } }
public async Task <TurnoverWithDays> UpdateTurnoverWithDays(TurnoverWithDays input) { //Начинаем блядь КВН using (var transaction = new TransactionScope(asyncFlowOption: TransactionScopeAsyncFlowOption.Enabled)) { var sqlRTurnovers = new TurnoversRepoisitory(_logger); var sqlRDays = new DayOfRoutesRepoisitory(_logger); var turnover = await sqlRTurnovers.Update(_mapper.Map <TurnoverWithDays, Turnover>(input)); var result = _mapper.Map <Turnover, TurnoverWithDays>(turnover); var currentDays = await sqlRDays.DaysByTurnoverId(input.Id); result.Days = new List <DayOfWeek>(); foreach (var inputDay in input.Days) { if (currentDays.Any(x => x.Day.Equals(inputDay))) { result.Days.Add(inputDay); continue; } var day = await sqlRDays.Add(new DayOfRoute { TurnoverId = input.Id, Day = inputDay }); result.Days.Add(day.Day); } foreach (var currentDay in currentDays) { if (!input.Days.Any(x => x.Equals(currentDay.Day))) { await sqlRDays.Delete(currentDay.Id); } } transaction.Complete(); return(result); } }