Exemplo n.º 1
0
        public async Task UpdateAsync(string transportWorkTicketId, string companyId, IEnumerable <string> collection)
        {
            var newRoutes = new List <RouteViewModel>();

            if (collection.Any())
            {
                foreach (var routeId in collection)
                {
                    var routeTransportWorkTicket = await this.routesService.GetByIdAsync <RouteViewModel>(routeId);

                    newRoutes.Add(routeTransportWorkTicket);
                }

                var allRoutes = await this.GetAllAsync <RouteTransportViewModel>(transportWorkTicketId);

                if (allRoutes.Any())
                {
                    foreach (var rtr in allRoutes)
                    {
                        var routeTransportWorkTicket = new RouteTransportWorkTicket
                        {
                            TransportWorkTicketId = rtr.TransportWorkTicketId,
                            RouteId = rtr.RouteId,
                        };

                        this.routeTransportWorkTicketsRepository.HardDelete(routeTransportWorkTicket);

                        await this.routeTransportWorkTicketsRepository.SaveChangesAsync();
                    }
                }

                foreach (var route in newRoutes)
                {
                    var routeTransportWorkTicket = new RouteTransportWorkTicket
                    {
                        RouteId = route.Id,
                        TransportWorkTicketId = transportWorkTicketId,
                    };

                    await this.routeTransportWorkTicketsRepository.AddAsync(routeTransportWorkTicket);
                }

                await this.routeTransportWorkTicketsRepository.SaveChangesAsync();
            }
        }
Exemplo n.º 2
0
        public async Task SetIsDeletedAsync(string transportWorkTicketId, string fullName)
        {
            var routeTransportWorkTicketsFromDb = await this.GetAllAsync <RouteTransportViewModel>(transportWorkTicketId);

            if (routeTransportWorkTicketsFromDb.Any())
            {
                foreach (var rtr in routeTransportWorkTicketsFromDb)
                {
                    var routeTransportWorkTicket = new RouteTransportWorkTicket
                    {
                        TransportWorkTicketId = rtr.TransportWorkTicketId,
                        RouteId = rtr.RouteId,
                    };

                    routeTransportWorkTicket.ModifiedBy = fullName;
                    this.routeTransportWorkTicketsRepository.Delete(routeTransportWorkTicket);

                    await this.routeTransportWorkTicketsRepository.SaveChangesAsync();
                }
            }
        }