public async Task <IActionResult> AgreeTaxiOffer(int?id)
        {
            if (id != null)
            {
                TaxiOffer taxiOffer = await db.TaxiOffers.FirstOrDefaultAsync(p => p.Id == id);

                ApplicationUser user = await userManager.FindByIdAsync(taxiOffer.OfferOwnerId);

                String curDateTime = DateTime.Now.ToString("yyyy-MM-dd") + " " + DateTime.Now.ToString("HH:mm",
                                                                                                       System.Globalization.DateTimeFormatInfo.InvariantInfo);
                _logger.LogInformation(curDateTime);
                if (user.IsAvaliable == null || DateTime.Parse(user.IsAvaliable) < DateTime.Parse(curDateTime))
                {
                    //taxiOffer.OfferStatus = "Выполняется";
                    db.TaxiOffers.Update(taxiOffer);
                    await db.SaveChangesAsync();

                    return(View(taxiOffer));
                }
                else
                {
                    ViewData["Avaliable"] = user.IsAvaliable;
                    return(View(taxiOffer));
                }
            }
            return(NotFound());
        }
        public async Task <IActionResult> RemoveTaxiOffer(int?offerId)
        {
            List <TaxiOffer> taxi = await db.Offers.ToListAsync();

            if (offerId != null)
            {
                TaxiOffer offer = await db.Offers.FirstOrDefaultAsync(p => p.Id == offerId);

                if (offer != null)
                {
                    db.Offers.Remove(offer);
                    await db.SaveChangesAsync();

                    taxi = await db.Offers.ToListAsync();

                    for (int i = 0; i < taxi.Count; i++)
                    {
                        if (taxi[i].Place.IndexOf('|') > 0)
                        {
                            taxi[i].Place = taxi[i].Place.Remove(0, taxi[i].Place.IndexOf('|') + 1);
                        }
                    }
                    return(Json(taxi, new JsonSerializerSettings
                                                 {
                                            ContractResolver = new CamelCasePropertyNamesContractResolver()
                                                                               
                    }));
                }
            }
            return(Json(taxi, new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()  
            }));
        }
        public async Task <IActionResult> EditTaxiOffer(TaxiOffer taxiOffer)
        {
            db.TaxiOffers.Update(taxiOffer);
            await db.SaveChangesAsync();

            return(RedirectToAction("TaxiOffers"));
        }
        public async Task <IActionResult> CreateOffer([FromBody] TaxiOffer Offer)
        {
            db.Offers.Add(Offer);
            await db.SaveChangesAsync();

            return(Json(Offer.Place, new JsonSerializerSettings {
                                    ContractResolver = new CamelCasePropertyNamesContractResolver()
            }));
        }
        public async Task <IActionResult> EditTaxiOffer([FromBody] TaxiOffer taxiOfferNew)
        {
            //TaxiOrder taxiOrder = await db.TaxiOrders.FirstOrDefaultAsync(p => p.Id == taxiOrderNew.Id);
            //taxiOrder = taxiOrderNew;
            db.Offers.Update(taxiOfferNew);

            await db.SaveChangesAsync();

            return(Json(taxiOfferNew, new JsonSerializerSettings  {
                                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                                                                   
            }));
        }
        public async Task <IActionResult> ConfirmDeleteTaxiOffer(int?id)
        {
            if (id != null)
            {
                TaxiOffer taxiOffer = await db.TaxiOffers.FirstOrDefaultAsync(p => p.Id == id);

                if (taxiOffer != null)
                {
                    return(View(taxiOffer));
                }
            }
            return(NotFound());
        }
        public async Task <IActionResult> CreateTaxiOffer(TaxiOffer taxiOffer)
        {
            var user = await GetCurrentUserAsync();

            var userId = user?.Id;

            db.Users.Update(user);
            taxiOffer.OfferOwnerId = userId;
            taxiOffer.OfferStatus  = "Свободен";
            db.TaxiOffers.Add(taxiOffer);
            await db.SaveChangesAsync();

            return(RedirectToAction("TaxiOffers"));
        }
        public async Task <IActionResult> DeleteTaxiOffer(int?id)
        {
            if (id != null)
            {
                TaxiOffer offer = await db.TaxiOffers.FirstOrDefaultAsync(p => p.Id == id);

                if (offer != null)
                {
                    db.TaxiOffers.Remove(offer);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("TaxiOffers"));
                }
            }
            return(NotFound());
        }
        public async Task <IActionResult> OfferById(int index)
        {
            if (index != null)
            {
                TaxiOffer taxiOffer = await db.Offers.FirstOrDefaultAsync(p => p.Id == index);

                if (taxiOffer != null)
                {
                    return(Json(taxiOffer, new JsonSerializerSettings
                                                 {
                                            ContractResolver = new CamelCasePropertyNamesContractResolver()
                                                                               
                    }));
                }
            }
            return(NotFound());
        }
Exemple #10
0
        public async Task <IActionResult> AgreeTaxiOffer(int?id)
        {
            if (id != null)
            {
                TaxiOffer taxiOffer = await db.TaxiOffers.FirstOrDefaultAsync(p => p.Id == id);

                if (taxiOffer != null)
                {
                    //taxiOffer.OfferStatus = "Выполняется";
                    db.TaxiOffers.Update(taxiOffer);
                    await db.SaveChangesAsync();

                    return(View(taxiOffer));
                }
            }
            return(NotFound());
        }
        public async Task <IActionResult> EditTaxiOffer(int?editedOfferId)
        {
            if (editedOfferId != null)
            {
                TaxiOffer taxiOffer = await db.Offers.FirstOrDefaultAsync(p => p.Id == editedOfferId);

                taxiOffer.Place = taxiOffer.Place.Remove(0, taxiOffer.Place.IndexOf('|') + 1);
                if (taxiOffer != null)
                {
                    return(Json(taxiOffer, new JsonSerializerSettings
                                                 {
                                            ContractResolver = new CamelCasePropertyNamesContractResolver()
                                                                               
                    }));
                }
            }
            return(NotFound());
        }
        public async Task <IActionResult> GetTaxiOfferByOwner(string receiverId)
        {
            _logger.LogInformation("2asd13221adfdsfsdfsdfsdf" + receiverId);
            if (receiverId != null)
            {
                _logger.LogInformation("2" + receiverId);
                TaxiOffer taxiOffer = await db.Offers.FirstOrDefaultAsync(p => p.OfferOwnerId == receiverId);

                taxiOffer.Place = taxiOffer.Place.Remove(0, taxiOffer.Place.IndexOf('|') + 1);
                _logger.LogInformation(taxiOffer.Place);
                return(Json(taxiOffer, new JsonSerializerSettings
                                             {
                                        ContractResolver = new CamelCasePropertyNamesContractResolver()
                                                                           
                }));
            }
            return(NotFound());
        }