public async Task <ActionResult <FriendRequest> > AddFriendRequest(MAANPP20ContextFlight _context, FriendRequest friendRequest)
        {
            if (friendRequest.myId == friendRequest.hisId)
            {
                return(null);
            }

            // ne moze da se posalje 2 puta isti zahtev
            if (FriendRequestExists(_context, friendRequest.myId, friendRequest.hisId))
            {
                return(null);
            }

            var user = await _context.Users
                       .Include(address => address.address)
                       .Include(friends => friends.friends)
                       .Include(friendRequests => friendRequests.friendRequests)
                       .FirstOrDefaultAsync(i => i.Id == friendRequest.myId);

            if (user == null)
            {
                return(null);
            }

            user.friendRequests.Add(friendRequest);
            // ja sam poslao zahtev
            _context.FriendRequests.Add(friendRequest);

            await _context.SaveChangesAsync();

            var he = await _context.Users
                     .Include(address => address.address)
                     .Include(friends => friends.friends)
                     .Include(friendRequests => friendRequests.friendRequests)
                     .FirstOrDefaultAsync(i => i.Id == friendRequest.hisId);

            var hisFriendRequest = new FriendRequest();

            hisFriendRequest.myId      = friendRequest.hisId;
            hisFriendRequest.hisId     = friendRequest.myId;
            hisFriendRequest.isRequest = true;

            he.friendRequests.Add(hisFriendRequest);

            // on je primio zahtev
            _context.FriendRequests.Add(hisFriendRequest);

            await _context.SaveChangesAsync();

            return(friendRequest);
        }
Beispiel #2
0
        public async Task <ActionResult <FlightDestination> > DeleteFlightDestination(MAANPP20ContextFlight _context, int id)
        {
            var flightDestinaion = await _context.FlightDestinations
                                   .Include(address1 => address1.startAddress)
                                   .Include(address2 => address2.endAddress)
                                   .FirstOrDefaultAsync(i => i.id == id);

            if (flightDestinaion == null)
            {
                return(null);
            }

            flightDestinaion.deleted = true;
            flightDestinaion.startAddress.deleted = true;
            flightDestinaion.endAddress.deleted   = true;

            _context.Entry(flightDestinaion.startAddress).State = EntityState.Modified;
            _context.Entry(flightDestinaion.endAddress).State   = EntityState.Modified;
            _context.Entry(flightDestinaion).State = EntityState.Modified;

            //_context.FlightDestinations.Remove(flightDestinaion);
            await _context.SaveChangesAsync();

            return(flightDestinaion);
        }
        public async Task <ActionResult <Flight> > AddFlight(MAANPP20ContextFlight _context, Flight flight)
        {
            var flightCompany = await _context.FlightCompanies
                                .Include(address => address.address)
                                .Include(destinations => destinations.destinations)
                                .Include(flights => flights.flights)
                                .Include(ocene => ocene.ocene)
                                .FirstOrDefaultAsync(i => i.id == flight.idCompany);

            if (flightCompany == null)
            {
                return(null);
            }

            // posto vec postoje sa primarnim kljucevima
            flight.addressFromId = flight.from.id;
            flight.addressToId   = flight.to.id;
            flight.aeroplaneId   = flight.aeroplane.id;

            //dodaj mu destinaciju i sacuvaj izmene u kompaniji
            flightCompany.flights.Add(flight);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                throw;
            }

            return(flight);
        }
        public async Task <ActionResult <FriendRequest> > DeleteFriendRequest(MAANPP20ContextFlight _context, string id)
        {
            if (id == null)
            {
                return(null);
            }
            string myId  = id.Split('|')[0];
            string hisId = id.Split('|')[1];
            // vraca nam zahtev
            var friendRequest = await _context.FriendRequests
                                .FirstOrDefaultAsync(i => i.hisId == hisId && i.myId == myId);

            if (friendRequest == null)
            {
                return(null);
            }

            // vraca nam cekanje
            var waitingFriendRequest = await _context.FriendRequests
                                       .FirstOrDefaultAsync(i => i.hisId == myId && i.myId == hisId);

            if (waitingFriendRequest == null)
            {
                return(null);
            }


            _context.FriendRequests.Remove(friendRequest);
            _context.FriendRequests.Remove(waitingFriendRequest);
            await _context.SaveChangesAsync();

            return(friendRequest);
        }
        public async Task <Flight> UpdateFlight(MAANPP20ContextFlight _context, Flight flight)
        {
            foreach (var seat in flight.allSeatsForThisFlight)
            {
                _context.Entry(seat).State = EntityState.Modified;
            }
            _context.Entry(flight).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FlightExists(_context, flight.id))
                {
                    return(null);
                }
                else
                {
                    throw;
                }
            }

            return(flight);
        }
Beispiel #6
0
        public async Task <FlightCompany> UpdateFlightCompany(MAANPP20ContextFlight _context, FlightCompany flightCompany)
        {
            if (flightCompany.admin != null)
            {
                flightCompany.admin.serviceId             = flightCompany.id;
                _context.Entry(flightCompany.admin).State = EntityState.Modified;
            }

            _context.Entry(flightCompany.address).State = EntityState.Modified;
            _context.Entry(flightCompany).State         = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FlightCompanyExists(_context, flightCompany.id))
                {
                    return(null);
                }
                else
                {
                    throw;
                }
            }

            return(flightCompany);
        }
Beispiel #7
0
        public async Task <ActionResult <FlightCompany> > AddFlightCompany(MAANPP20ContextFlight _context, FlightCompany flightCompany)
        {
            _context.FlightCompanies.Add(flightCompany);

            await _context.SaveChangesAsync();

            return(flightCompany);
        }
        public async Task <ActionResult <Aeroplane> > AddPlane(MAANPP20ContextFlight _context, Aeroplane aeroplane)
        {
            _context.Aeroplanes.Add(aeroplane);

            await _context.SaveChangesAsync();

            return(aeroplane);
        }
        public async Task <Friend> DeleteFriend(MAANPP20ContextFlight _context, string id)
        {
            if (id == null)
            {
                return(null);
            }

            string myId  = id.Split('|')[0];
            string hisId = id.Split('|')[1];

            var friend = await _context.Friends.Where(x => x.deleted == false)
                         .Include(messages => messages.messages)
                         .FirstOrDefaultAsync(i => i.myId == myId && i.hisId == hisId);

            if (friend == null)
            {
                return(null);
            }
            if (friend.deleted == true)
            {
                return(null);
            }

            foreach (var message in friend.messages)
            {
                message.deleted = true;
                _context.Entry(message).State = EntityState.Modified;
            }

            friend.deleted = true;
            _context.Entry(friend).State = EntityState.Modified;

            var friend1 = await _context.Friends.Where(x => x.deleted == false)
                          .Include(messages => messages.messages)
                          .FirstOrDefaultAsync(i => i.myId == hisId && i.hisId == myId);

            if (friend1 == null)
            {
                return(null);
            }
            if (friend1.deleted == true)
            {
                return(null);
            }

            foreach (var message in friend1.messages)
            {
                message.deleted = true;
                _context.Entry(message).State = EntityState.Modified;
            }

            friend1.deleted = true;
            _context.Entry(friend1).State = EntityState.Modified;

            await _context.SaveChangesAsync();

            return(friend);
        }
Beispiel #10
0
        public async Task <FlightReservation> UpdateFlightReservation(MAANPP20ContextFlight _context, FlightReservation flightReservation)
        {
            Flight flight = await _context.Flights.Where(x => x.deleted == false)
                            .Include(ocene => ocene.ocene)
                            .FirstOrDefaultAsync(id => id.id == flightReservation.flightId);

            if (flight == null)
            {
                return(null);
            }
            if (flightReservation.ocenaLeta > 0)
            {
                DoubleForICollection doubleForICollection = new DoubleForICollection();
                doubleForICollection.DoubleValue = flightReservation.ocenaLeta;
                flight.ocene.Add(doubleForICollection);
                _context.Entry(flight).State = EntityState.Modified;
            }

            if (flightReservation.ocenaKompanije > 0)
            {
                FlightCompany flightCompany = await _context.FlightCompanies.Where(x => x.deleted == false)
                                              .Include(ocene => ocene.ocene)
                                              .FirstOrDefaultAsync(id => id.id == flight.idCompany);

                if (flightCompany == null)
                {
                    return(null);
                }
                DoubleForICollection doubleForICollection = new DoubleForICollection();
                doubleForICollection.DoubleValue = flightReservation.ocenaKompanije;
                flightCompany.ocene.Add(doubleForICollection);
                _context.Entry(flightCompany).State = EntityState.Modified;
            }

            _context.Entry(flightReservation).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FlightReservationExists(_context, flightReservation.id))
                {
                    return(null);
                }
                else
                {
                    throw;
                }
            }

            return(flightReservation);
        }
Beispiel #11
0
        public async Task <ActionResult <FlightCompany> > DeleteFlightCompany(MAANPP20ContextFlight _context, int id)
        {
            var flightCompany = await _context.FlightCompanies
                                .Include(address => address.address)
                                .Include(destinations => destinations.destinations)
                                .ThenInclude(startAddr => startAddr.startAddress)
                                .Include(destinations => destinations.destinations)
                                .ThenInclude(endAddr => endAddr.endAddress)
                                .Include(flights => flights.flights)
                                .ThenInclude(allSeats => allSeats.allSeatsForThisFlight)
                                .Include(admin => admin.admin)
                                .Include(ocene => ocene.ocene)
                                .FirstOrDefaultAsync(i => i.id == id);

            if (flightCompany == null)
            {
                return(null);
            }
            else if (flightCompany.deleted == true)
            {
                return(null);
            }

            flightCompany.admin.serviceId             = 0;
            _context.Entry(flightCompany.admin).State = EntityState.Modified;

            flightCompany.deleted         = true;
            flightCompany.address.deleted = true;
            foreach (var destination in flightCompany.destinations)
            {
                destination.deleted = true;
                destination.startAddress.deleted = true;
                destination.endAddress.deleted   = true;
            }
            foreach (var flight in flightCompany.flights)
            {
                flight.deleted = true;
                foreach (var seat in flight.allSeatsForThisFlight)
                {
                    seat.deleted = true;
                }
            }
            _context.Entry(flightCompany).State = EntityState.Modified;

            //_context.FlightCompanies.Remove(flightCompany);
            await _context.SaveChangesAsync();

            return(flightCompany);
        }
        public async Task <ActionResult <Flight> > DeleteFlight(MAANPP20ContextFlight _context, int id)
        {
            var flight = await _context.Flights
                         .Include(presedanje => presedanje.presedanje)
                         .ThenInclude(gradoviPresedanja => gradoviPresedanja.gradoviPresedanja)
                         .Include(luggage => luggage.luggage)
                         .Include(ocene => ocene.ocene)
                         .Include(allSeatsForThisFlight => allSeatsForThisFlight.allSeatsForThisFlight)
                         .FirstOrDefaultAsync(i => i.id == id);

            if (flight == null)
            {
                return(null);
            }
            else if (flight.deleted == true)
            {
                return(null);
            }

            flight.deleted = true;
            foreach (var seat in flight.allSeatsForThisFlight)
            {
                seat.deleted = true;
            }

            flight.presedanje.deleted = true;
            foreach (var gradPresedanja in flight.presedanje.gradoviPresedanja)
            {
                gradPresedanja.deleted = true;
            }

            flight.luggage.deleted = true;

            // TO DO: brisanje ocena

            _context.Entry(flight).State = EntityState.Modified;
            //_context.Flights.Remove(flight);
            await _context.SaveChangesAsync();

            return(flight);
        }
Beispiel #13
0
        public async Task <FriendForFlight> DeclineFriendForFlight(MAANPP20ContextFlight _context, string invitationString)
        {
            var friendForFlight = await _context.FriendForFlights
                                  .Where(x => x.deleted == false)
                                  .FirstOrDefaultAsync(x => x.invitationString == invitationString);

            if (friendForFlight == null)
            {
                return(null);
            }
            if (friendForFlight.deleted == true)
            {
                return(null);
            }

            var seat = await _context.AvioSedista
                       .Where(x => x.reserved == true)
                       .FirstOrDefaultAsync(x => x.id == friendForFlight.seatId);

            if (seat == null)
            {
                return(null);
            }
            seat.reserved = false;
            _context.Entry(seat).State = EntityState.Modified;

            friendForFlight.deleted = true;
            _context.Entry(friendForFlight).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                throw;
            }

            return(friendForFlight);
        }
        public async Task <Aeroplane> UpdatePlane(MAANPP20ContextFlight _context, Aeroplane aeroplane)
        {
            _context.Entry(aeroplane).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlaneExists(_context, aeroplane.id))
                {
                    return(null);
                }
                else
                {
                    throw;
                }
            }

            return(aeroplane);
        }
Beispiel #15
0
        public async Task <ActionResult <FlightDestination> > AddFlightCompany(MAANPP20ContextFlight _context, FlightDestination flightDestination)
        {
            var flightCompany = await _context.FlightCompanies
                                .Include(address => address.address)
                                .Include(destinations => destinations.destinations)
                                .Include(flights => flights.flights)
                                .Include(ocene => ocene.ocene)
                                .FirstOrDefaultAsync(i => i.id == flightDestination.CompanyID);

            if (flightCompany == null)
            {
                return(null);
            }

            //dodaj mu destinaciju i sacuvaj izmene u kompaniji
            flightCompany.destinations.Add(flightDestination);

            _context.FlightDestinations.Add(flightDestination);

            await _context.SaveChangesAsync();

            return(flightDestination);
        }
Beispiel #16
0
        public async Task <FlightDestination> UpdateFlightCompany(MAANPP20ContextFlight _context, FlightDestination flightDestination)
        {
            _context.Entry(flightDestination.startAddress).State = EntityState.Modified;
            _context.Entry(flightDestination.endAddress).State   = EntityState.Modified;
            _context.Entry(flightDestination).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FlightDestinationExists(_context, flightDestination.id))
                {
                    return(null);
                }
                else
                {
                    throw;
                }
            }

            return(flightDestination);
        }
        public async Task <ActionResult <Aeroplane> > DeletePlane(MAANPP20ContextFlight _context, int id)
        {
            var plane = await _context.Aeroplanes
                        .Where(x => x.deleted == false)
                        .FirstOrDefaultAsync(i => i.id == id);

            if (plane == null)
            {
                return(null);
            }
            else if (plane.deleted == true)
            {
                return(null);
            }

            plane.deleted = true;

            _context.Entry(plane).State = EntityState.Modified;

            //_context.Aeroplanes.Remove(plane);
            await _context.SaveChangesAsync();

            return(plane);
        }
Beispiel #18
0
        public async Task <ActionResult <FlightReservation> > DeleteFlightReservation(MAANPP20ContextFlight _context, int id)
        {
            var flightReservation = await _context.FlightReservations
                                    .Where(x => x.deleted == false)
                                    .FirstOrDefaultAsync(i => i.id == id);

            if (flightReservation == null)
            {
                return(null);
            }
            else if (flightReservation.deleted == true)
            {
                return(null);
            }
            var flight = await _context.Flights
                         .Where(x => x.deleted == false)
                         .FirstOrDefaultAsync(x => x.id == flightReservation.flightId);

            if (flight == null)
            {
                return(null);
            }
            else
            {
                if (CanDelete(flight.datumPolaska))
                {
                    AvioSediste avioSediste = await _context.AvioSedista
                                              .Where(x => x.deleted == false)
                                              .FirstOrDefaultAsync(id => id.id == flightReservation.seatId);

                    if (avioSediste == null)
                    {
                        return(null);
                    }
                    if (avioSediste.isFastReservation == true)
                    {
                        return(null);
                    }
                    if (avioSediste.deleted == true)
                    {
                        return(null);
                    }
                    if (avioSediste.reserved == false)
                    {
                        return(null);
                    }
                    avioSediste.reserved = false;
                    _context.Entry(avioSediste).State = EntityState.Modified;

                    flightReservation.deleted = true;

                    _context.Entry(flightReservation).State = EntityState.Modified;

                    await _context.SaveChangesAsync();

                    return(flightReservation);
                }
                else
                {
                    return(null);
                }
            }
        }
Beispiel #19
0
        public async Task <ActionResult <FlightReservation> > AddFlightReservation(MAANPP20ContextFlight _context, FlightReservation flightReservation)
        {
            User user = await _context.Users.Where(x => x.deleted == false)
                        .Include(flightReservations => flightReservations.flightReservations)
                        .FirstOrDefaultAsync(id => id.Id == flightReservation.UserIdForPOST);

            if (user == null)
            {
                return(null);
            }

            AvioSediste avioSediste = await _context.AvioSedista
                                      .Where(x => x.deleted == false)
                                      .FirstOrDefaultAsync(id => id.id == flightReservation.seatId);

            if (avioSediste == null)
            {
                return(null);
            }
            if (avioSediste.isFastReservation == true)
            {
                return(null);
            }
            if (avioSediste.deleted == true)
            {
                return(null);
            }
            if (avioSediste.reserved == true)
            {
                return(null);
            }
            avioSediste.reserved = true;
            //_context.Entry(avioSediste).State = EntityState.Modified;

            foreach (var friend in flightReservation.friendForFlights)
            {
                AvioSediste avioSediste1 = await _context.AvioSedista
                                           .Where(x => x.deleted == false)
                                           .FirstOrDefaultAsync(id => id.id == friend.seatId);

                if (avioSediste1 == null)
                {
                    return(null);
                }
                if (avioSediste1.isFastReservation == true)
                {
                    return(null);
                }
                if (avioSediste1.deleted == true)
                {
                    return(null);
                }
                if (avioSediste1.reserved == true)
                {
                    return(null);
                }
                avioSediste1.reserved = true;
                //_context.Entry(avioSediste1).State = EntityState.Modified;
            }
            bool saveFailed;

            do
            {
                saveFailed = false;
                try
                {
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    saveFailed = true;
                    return(null);
                }
                catch (Exception e)
                {
                    throw;
                }
            } while (saveFailed);

            foreach (var friendForFlight in flightReservation.friendForFlights)
            {
                friendForFlight.invitationString = RandomString(_context);
                friendForFlight.reservationDate  = DateTime.Now;
            }

            user.flightReservations.Add(flightReservation);
            // ako je user iskoristion svoj bonus
            if (flightReservation.userBonus == true)
            {
                user.bonus = 0;
            }
            else
            {
                // ako nije, proverava se da li je dosao do 100%?
                if (user.bonus < 100)
                {
                    user.bonus += 1;
                }
            }

            try
            {
                _context.Entry(user).State = EntityState.Modified;
            }
            catch (Exception e)
            {
                throw;
            }

            _context.FlightReservations.Add(flightReservation);



            try
            {
                SendMail(flightReservation.friendForFlights as List <FriendForFlight>);
                await _context.SaveChangesAsync();

                //else BadRequest();
            }
            catch (Exception e)
            {
                return(null);
            }
            //await _context.SaveChangesAsync();

            return(flightReservation);
        }
Beispiel #20
0
        public async Task <ActionResult <FastFlightReservation> > AddFastFlightReservations(MAANPP20ContextFlight _context, FastFlightReservation fastFlightReservation)
        {
            User user = await _context.Users.Where(x => x.deleted == false)
                        .Include(fastFlightReservations => fastFlightReservations.fastFlightReservations)
                        .FirstOrDefaultAsync(id => id.Id == fastFlightReservation.UserIdForPOST);

            if (user == null)
            {
                return(null);
            }
            AvioSediste avioSediste = await _context.AvioSedista
                                      .Where(x => x.deleted == false)
                                      .FirstOrDefaultAsync(id => id.id == fastFlightReservation.seatId);

            if (avioSediste == null)
            {
                return(null);
            }
            if (avioSediste.isFastReservation == false)
            {
                return(null);
            }
            if (avioSediste.deleted == true)
            {
                return(null);
            }
            if (avioSediste.reserved == true)
            {
                return(null);
            }
            avioSediste.reserved = true;
            //_context.Entry(avioSediste).State = EntityState.Modified;

            bool saveFailed;

            do
            {
                saveFailed = false;
                try
                {
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    saveFailed = true;
                    return(null);
                }
                catch (Exception e)
                {
                    throw;
                }
            } while (saveFailed);


            user.fastFlightReservations.Add(fastFlightReservation);
            // ako je user iskoristion svoj bonus
            if (fastFlightReservation.userBonus == true)
            {
                user.bonus = 0;
            }
            else
            {
                // ako nije, proverava se da li je dosao do 100%?
                if (user.bonus < 100)
                {
                    user.bonus += 1;
                }
            }

            try
            {
                _context.Entry(user).State = EntityState.Modified;
            }
            catch (Exception e)
            {
                throw;
            }

            _context.FastFlightReservations.Add(fastFlightReservation);



            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                throw;
            }
            //await _context.SaveChangesAsync();

            return(fastFlightReservation);
        }
        public async Task <ActionResult <Friend> > AddFriend(MAANPP20ContextFlight _context, string id)
        {
            if (id == null)
            {
                return(null);
            }
            string myId  = null;
            string hisId = null;

            try
            {
                myId  = id.Split('|')[0];
                hisId = id.Split('|')[1];
            }
            catch
            {
                return(null);
            }


            var user = await _context.Users.Where(x => x.deleted == false)
                       .Include(address => address.address)
                       .Include(friends => friends.friends)
                       //.ThenInclude()
                       .FirstOrDefaultAsync(i => i.Id == myId);

            if (user == null)
            {
                return(null);
            }

            var friendUser = await _context.Users.Where(x => x.deleted == false)
                             .Include(address => address.address)
                             .Include(friends => friends.friends)
                             .FirstOrDefaultAsync(i => i.Id == hisId);

            if (friendUser == null)
            {
                return(null);
            }

            // dodajem njega kod sebe u listu prijatelja
            var friend = new Friend();

            friend.messages = new List <Message>();
            friend.myId     = user.Id;
            friend.hisId    = friendUser.Id;
            user.friends.Add(friend);

            //_context.Entry(user.friends).State = EntityState.Added;
            _context.Entry(user).State = EntityState.Modified;

            // sebe dodajem kod njega u listu prijatelja
            var friend2 = new Friend();

            friend2.messages = new List <Message>();
            friend2.myId     = friendUser.Id;
            friend2.hisId    = user.Id;
            friendUser.friends.Add(friend2);
            _context.Entry(friendUser).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                //if (!FlightExists(flight.id))
                //{
                return(null);
                //}
                //else
                //{
                //    throw;
                //}
            }

            return(friend);
        }
Beispiel #22
0
        public async Task <ActionResult <Message> > AddFriendRequest(MAANPP20ContextFlight _context, Message message)
        {
            if (message.myId == message.hisId)
            {
                return(null);
            }

            var user = await _context.Users
                       .Include(address => address.address)
                       .Include(friends => friends.friends)
                       .ThenInclude(messages => messages.messages)
                       .FirstOrDefaultAsync(i => i.Id == message.myId);

            if (user == null)
            {
                return(null);
            }

            foreach (var friend in user.friends)
            {
                if (friend.deleted == false)
                {
                    if (friend.hisId == message.hisId)
                    {
                        friend.messages.Add(message);
                    }
                }
            }
            // ja sam poslao zahtev
            _context.Messages.Add(message);

            var he = await _context.Users
                     .Include(address => address.address)
                     .Include(friends => friends.friends)
                     .ThenInclude(messages => messages.messages)
                     .FirstOrDefaultAsync(i => i.Id == message.hisId);


            if (he == null)
            {
                return(null);
            }

            var tempMessage = new Message();

            tempMessage.hisId    = message.myId;
            tempMessage.myId     = message.hisId;
            tempMessage.isUnread = message.isUnread;
            tempMessage.dateTime = message.dateTime;
            tempMessage.text     = message.text;
            foreach (var friend in he.friends)
            {
                if (friend.deleted == false)
                {
                    if (friend.myId == message.hisId)
                    {
                        friend.messages.Add(tempMessage);
                    }
                }
            }
            // ja sam poslao zahtev
            _context.Messages.Add(tempMessage);

            await _context.SaveChangesAsync();

            return(message);
        }