Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Date")] Excursion excursion)
        {
            if (id != excursion.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    excursion.IdexcursionGuide = Convert.ToInt32(Request.Form["ExGd"]);
                    _context.Update(excursion);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ExcursionExists(excursion.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdexcursionGuide"] = new SelectList(_context.ExcurionGuide, "Id", "Id", excursion.IdexcursionGuide);
            return(View(excursion));
        }
        public ExcursionsControllerTests() : base()
        {
            apiRoute = "excursions";
            var stringContent = new StringContent(JsonConvert.SerializeObject(new RegisterDto {
                Email = "*****@*****.**", FirstName = "Aaaa", LastName = "Aaa", Password = "******"
            }), Encoding.UTF8, "application/json");
            var response       = client.PostAsync("accounts/register", stringContent);
            var jsonString     = response.Result.Content.ReadAsStringAsync();
            var model          = JsonConvert.DeserializeObject <bool>(jsonString.Result);
            var stringContent2 = new StringContent(JsonConvert.SerializeObject(new LoginDto {
                Email = "*****@*****.**", Password = "******"
            }), Encoding.UTF8, "application/json");
            var response2   = client.PostAsync("accounts/login", stringContent2);
            var jsonString2 = response2.Result.Content.ReadAsStringAsync();
            var model2      = JsonConvert.DeserializeObject <User>(jsonString2.Result);

            client.DefaultRequestHeaders.Add("Authorization", $"Bearer {model2.Token}");
            testId         = Guid.Parse("ffe5e70a-8338-4135-85d5-0fbe348cc697");
            unexistingId   = Guid.Parse("ffa5e70a-8338-4135-85d5-0fbe348cc697");
            testExcursion1 = new Excursion {
                Id = Guid.Parse("ffe5e70a-8338-4135-85d5-0fbe348cc697"), Name = "Jihn Sniw"
            };
            testExcursion2 = new Excursion {
                Id = Guid.Parse("ffe5e70a-8338-4135-85d5-0fbe348cc695"), Name = "Jick Blick"
            };
        }
Ejemplo n.º 3
0
 public ExcursionModel(Excursion excursion)
 {
     excursionID   = excursion.excursionID;
     dateExcursion = excursion.dateExcursion;
     cost          = excursion.cost;
     courseID      = excursion.courseID;
 }
Ejemplo n.º 4
0
 public ActionResult ComprarExcursion(int?idExcursion)
 {
     if (Session["rol"] != null && Session["rol"].ToString() == "Cliente")
     {
         if (idExcursion != null)
         {
             Excursion miExcursion = Agencia.getInstancia.buscarExcursionPorId((int)idExcursion);
             ViewBag.miExcursion = miExcursion;
             ViewBag.PrecioUY    = Agencia.getInstancia.cotizarExcursionUY(miExcursion);
         }
         else if (Session["rol"] != null && Session["rol"].ToString() == "Operador")
         {
             return(RedirectToAction("../Reportes/IndexVerClientes"));
         }
         else
         {
             ViewBag.Mensaje = "no me llego un id, no se si debo mostrar error o no";
         }
         return(View("IndexComprarExcursion"));
     }
     else
     {
         return(RedirectToAction("../Usuario/IndexLogin"));
     }
 }
        public IActionResult ChangeStatus([FromBody] Excursion excursion)
        {
            //TODO: make scheduler for status, i think
            try
            {
                var status = _context.Excursions.FirstOrDefault(x => x.Id == excursion.Id);
                if (status != null && status.Status)
                {
                    status.Status = false;
                }
                else if (status != null && status.Status == false)
                {
                    status.Status = true;
                }

                _context.SaveChanges();
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
                return(BadRequest(e.Message));
            }
            _logger.LogInformation("Status for excursion: {0} was changed by user: {1}", excursion.Id, User.Identity.Name);
            return(Ok("Excursion status was changed"));
        }
Ejemplo n.º 6
0
        public void DesactivarExcursionesAsociados(int CodigoDestino)
        {
            Excursion        aux = new Excursion();
            List <Excursion> ExcursionesActivas      = db.Excursiones.Where(m => m.Activo == true).ToList();
            List <Excursion> ExcursionesDesactivadar = new List <Excursion>();

            foreach (Excursion ex in ExcursionesActivas)
            {
                foreach (Estadia es in ex.ExcursionEstadias)
                {
                    if (es.Destino.Codigo == CodigoDestino)
                    {
                        ExcursionesDesactivadar.Add(ex);
                    }
                }
                foreach (Transporte tr in ex.ExcursionesTransportes)
                {
                    if (tr.CiudadOrigen.Codigo == CodigoDestino || tr.CiudadDestino.Codigo == CodigoDestino)
                    {
                        ExcursionesDesactivadar.Add(ex);
                    }
                }
            }
            foreach (Excursion ED in ExcursionesDesactivadar)
            {
                aux = db.Excursiones.Find(ED.Id);
                if (aux.Activo == true)
                {
                    aux.Activo          = false;
                    aux.Cliente         = db.Usuarios.Find(aux.Cliente.Id);
                    db.Entry(aux).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> PutExcursion(long id, Excursion excursion)
        {
            if (id != excursion.id)
            {
                return(BadRequest());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ExcursionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public void DesactivarExcursionesConTransporte(int TransporteId)
        {
            Excursion        aux = new Excursion();
            List <Excursion> ExcursionesActivas    = db.Excursiones.Where(m => m.Activo == true).ToList();
            List <Excursion> ExcursionesDesactivar = new List <Excursion>();

            foreach (Excursion ex in ExcursionesActivas)
            {
                foreach (Transporte tr in ex.ExcursionesTransportes)
                {
                    if (tr.Id == TransporteId)
                    {
                        ExcursionesDesactivar.Add(ex);
                    }
                }
            }
            foreach (Excursion ED in ExcursionesDesactivar)
            {
                aux = db.Excursiones.Find(ED.Id);
                if (aux.Activo == true)
                {
                    aux.Activo          = false;
                    aux.Cliente         = db.Usuarios.Find(aux.Cliente.Id);
                    db.Entry(aux).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
        }
        protected void BtnConfirmar_Click(object sender, EventArgs e)
        {
            int       numExc      = Convert.ToInt32(Request.QueryString["Codigo"]);
            int       cantMayores = Convert.ToInt32(TxtMayores.Text);
            int       cantMenores = Convert.ToInt32(TxtMenores.Text);
            Excursion exc         = Agencia.Instancia.BuscarExcursionEnListaPorCodigo(numExc);

            if (exc.Stock < (cantMayores + cantMenores))
            {
                LiteralMsj.Text = "No hay Stock disponible para la cantidad de personas ingresadas";
            }
            else
            {
                int cantPersonas = cantMayores + cantMenores;
                exc.Stock = exc.Stock - cantPersonas;
                Agencia.Instancia.AgregarCompra(exc);
                Venta v = new Venta(DateTime.Today, cantPersonas);
                v.AgregarVenta(exc);
                Agencia.Instancia.AgregarVenta(v);
                LiteralMsj.Text = "Compra realizada";
                string detalleNuevaCompra = "<table class='table'><tr><th>Código</th><th>Descripción</th><th>Fecha de Inicio</th><th>Stock Disponible</th></tr>";
                foreach (Excursion ex in Agencia.Instancia.ObtenerListaCompras())
                {
                    detalleNuevaCompra += $"<tr><td>{ex.Codigo}</td><td>{ex.Descripcion}</td><td>{ex.FechaIni}</td><td>{ex.Stock}</td></tr>";
                }
                detalleNuevaCompra      += "</table>";
                LiteralListaCompras.Text = detalleNuevaCompra;
            }
        }
        public async Task <IActionResult> CreateAsync([FromBody] Excursion excursion)
        {
            var getQuery = new CreateExcursion.Command(excursion);
            var res      = await _mediator.Send(getQuery);

            return(Ok(res));
        }
Ejemplo n.º 11
0
        public async Task <bool> ExcursionCreate(ExcursionCreateInputModel model)
        {
            var validLanguageIds = new HashSet <int>(await languageServices.GetAll().Select(l => l.Id).ToListAsync());

            var excursionToAdd = new Excursion()
            {
                Arrival         = model.Arrival,
                Departure       = model.Departure,
                LastUpdated     = model.LastUpdated,
                TouristCapacity = model.TouristCapacity,
                LastUpdatedBy   = model.LastUpdatedBy,
                EndPoint        = model.EndPoint,
                PricePerAdult   = model.Price,
                PricePerChild   = model.ChildPrice,
                StartingPoint   = model.StartingPoint,
                ExcursionTypeId = model.ExcursionTypeId
            };

            excursionToAdd.LanguageExcursions = model
                                                .LanguageIds.Where(l => validLanguageIds.Contains(l))
                                                .Distinct()
                                                .Select(id => new LanguageExcursion()
            {
                Excursion  = excursionToAdd,
                LanguageId = id
            })
                                                .ToList();

            await context.Excursions.AddAsync(excursionToAdd);

            await context.SaveChangesAsync();

            return(true);
        }
        public async Task <IActionResult> UpdateAsync([FromBody] Excursion excursion)
        {
            var command = new UpdateExcursion.Command(excursion);
            var res     = await _mediator.Send(command);

            return(Ok(res));
        }
Ejemplo n.º 13
0
        [Authorize(Roles = "admin")] //TODO:CHECK
        public async Task <IActionResult> Update([FromBody] Excursion excursion)
        {
            try
            {
                if (User.IsInRole("admin"))
                {
                    _logger.LogInformation("Try to update excursion: {0}", excursion.Id);
                    _context.Excursions.Update(excursion);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    _logger.LogWarning("Access denied for user: {0}", User.Identity.Name);
                    return(Forbid("Access denied"));
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
                return(BadRequest(e.Message));
            }

            //TODO:

            _logger.LogInformation("Excursions was update by user: {0}", User.Identity.Name);
            return(Ok());
        }
Ejemplo n.º 14
0
        public void ExecuteAddCommand()
        {
            if (buttonAddFunction == "Добавить")
            {
                Excursion exc = new Excursion()
                {
                    Name = Name, Price = (int)Price, ExDate = ExDate, Type = Type, Duration = (int)Duration, Description = Description
                };
                Repositories.RExcursions.Add(exc);
                Repositories.RTicketSales.Add(new TicketSale()
                {
                    Excursion = exc, Price = (int)TicketPrice, Amount = (int)TicketAmount, Notes = TicketNotes
                });
                ClearFields();
            }
            else
            {
                CurrentExcursion.Name        = Name;
                CurrentExcursion.Price       = (int)Price;
                CurrentExcursion.ExDate      = ExDate;
                CurrentExcursion.Type        = Type;
                CurrentExcursion.Duration    = (int)Duration;
                CurrentExcursion.Description = Description;
                Repositories.RExcursions.Update(CurrentExcursion);

                CurrentTicket.Amount = (int)TicketAmount;
                CurrentTicket.Price  = (int)TicketPrice;
                CurrentTicket.Notes  = TicketNotes;
                Repositories.RTicketSales.Update(CurrentTicket);

                ClearFields();
                ButtonAddFunction = "Добавить";
            }
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Description,ThePriceInclude,ImageURL,Duration,ExCityID,Date,Price,HotelName,HotelLink,DocLink")] Excursion excursion)
        {
            if (id != excursion.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(excursion);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ExcursionExists(excursion.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                ViewData["CityID"] = new SelectList(_context.ExCities, "ID", "ID", excursion.ExCityID);
                return(RedirectToAction(nameof(ExcursionList)));
            }
            return(View(excursion));
        }
Ejemplo n.º 16
0
        public async Task <ActionResult <Excursion> > PostExcursion(Excursion excursion)
        {
            _context.Excursion.Add(excursion);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetExcursion", new { id = excursion.id }, excursion));
        }
Ejemplo n.º 17
0
        public ActionResult DeleteConfirmed(int id)
        {
            Excursion excursion = db.Excursions.Find(id);

            db.Excursions.Remove(excursion);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task <Excursion> Create(Excursion excursion)
        {
            await _dbContext.Excursions.AddAsync(excursion);

            await _dbContext.SaveChangesAsync();

            return(excursion);
        }
Ejemplo n.º 19
0
        public void CreateOrUpdate(ExcursionBindingModel model)
        {
            using (var context = new ZooDatabase())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        Excursion elem = model.Id.HasValue ? null : new Excursion();
                        if (model.Id.HasValue)
                        {
                            elem = context.Excursions.FirstOrDefault(rec => rec.Id ==
                                                                     model.Id);
                            if (elem == null)
                            {
                                throw new Exception("Элемент не найден");
                            }
                            elem.ClientId        = model.ClientId;
                            elem.ExcursionCreate = model.ExcursionCreate;
                            elem.Final_Cost      = model.Final_Cost;
                            elem.Status          = model.Status;
                            context.SaveChanges();
                        }
                        else
                        {
                            elem.ClientId        = model.ClientId;
                            elem.ExcursionCreate = model.ExcursionCreate;
                            elem.Final_Cost      = model.Final_Cost;
                            elem.Status          = model.Status;
                            context.Excursions.Add(elem);
                            context.SaveChanges();
                            var routes = model.RouteForExcursions
                                         .GroupBy(rec => rec.RouteId)
                                         .Select(rec => new
                            {
                                RouteId = rec.Key,
                            });

                            foreach (var route in routes)
                            {
                                context.RouteForExcursions.Add(new RouteForExcursion
                                {
                                    ExcursionId = elem.Id,
                                    RouteId     = route.RouteId,
                                });
                                context.SaveChanges();
                            }
                        }
                        transaction.Commit();
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 20
0
 private Excursion CreateModel(ExcursionBindingModel model, Excursion excursion)
 {
     excursion.Name      = model.Name;
     excursion.Price     = model.Price;
     excursion.Duration  = model.Duration;
     excursion.PlaceID   = model.PlaceID;
     excursion.TouristID = model.TouristID;
     return(excursion);
 }
        public async void Delete(Guid id)
        {
            Excursion ex = new Excursion {
                Id = id
            };

            _dbContext.Excursions.Attach(ex);
            _dbContext.Excursions.Remove(ex);
            await _dbContext.SaveChangesAsync();
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Excursion aux = db.Excursiones.Find(id);

            aux.Activo          = false;
            aux.Cliente         = db.Usuarios.Find(aux.Cliente.Id);
            db.Entry(aux).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 23
0
        public override string ToString()
        {
            string temp = "";

            temp = "Excursion\n Id : " + Excursion.ToString();
            foreach (CustomExcursionDTO item in CustomExcursions)
            {
                temp += "CustomExcursions\n Id : " + item.ToString();
            }
            return(temp);
        }
Ejemplo n.º 24
0
 public ActionResult Edit([Bind(Include = "Location,Budget,LeadID,ExcursionID,Start_Date,End_Date")] Excursion excursion)
 {
     if (ModelState.IsValid)
     {
         db.Entry(excursion).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.LeadID = new SelectList(db.AspNetUsers, "Id", "FirstName", excursion.LeadID);
     return(View(excursion));
 }
Ejemplo n.º 25
0
        public Excursion ToDTO()
        {
            var excursion = new Excursion()
            {
                excursionID   = excursionID,
                dateExcursion = dateExcursion,
                cost          = cost,
                courseID      = courseID
            };

            return(excursion);
        }
        public async Task <ActionResult <Excursion> > PostExcursion(Excursion excursion)
        {
            excursion.Activity = await _context.Activities.FindAsync(excursion.Activity.Id);

            excursion.Creator = await _context.People.FindAsync(excursion.Creator.Id);
            await getWeatherAsync(excursion);

            _context.Excursions.Add(excursion);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetExcursion", new { id = excursion.Id }, prepareExcursion(excursion)));
        }
Ejemplo n.º 27
0
        public IActionResult addExcur(int vacationId, string name, int Importance, string category)
        {
            Excursion excursion = new Excursion();

            excursion.Name       = name;
            excursion.Importance = Importance;
            excursion.Category   = category;
            excursion.VacationId = vacationId;
            _repo.Excursion.CreateExcursion(excursion);
            _repo.Save();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 28
0
        private Guid Create(string name, IEnumerable <ExcursionSightDto> sights)
        {
            var newSights    = TypeAdapter.Adapt <IEnumerable <ExcursionSight> >(sights);
            var newExcursion = new Excursion {
                Id = Guid.NewGuid(), Name = name, ExcursionSights = newSights
            };

            _uow.Excursions.Create(newExcursion);
            _uow.Save();

            return(newExcursion.Id);
        }
Ejemplo n.º 29
0
        public async Task <IActionResult> Create([Bind("ID,Name,Description,ThePriceInclude,ImageURL,Duration,ExCityID,Date,Price,HotelName,HotelLink,DocLink")] Excursion excursion)
        {
            if (ModelState.IsValid)
            {
                _context.Add(excursion);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(ExcursionList)));
            }
            ViewData["CityID"] = new SelectList(_context.ExCities, "ID", "ID", excursion.ExCityID);
            return(View(excursion));
        }
Ejemplo n.º 30
0
        public void AddRandomNumberOfExcursion(int number)
        {
            var travelAgency = new TravelAgencyDbContext();

            var allDestinations = travelAgency.Destinations
                                  .Select(d => new
            {
                ID   = d.DestinationId,
                Name = d.Country
            })
                                  .ToList();

            var allTransportIds = travelAgency.Transports
                                  .Select(d => d.TransportId)
                                  .ToList();

            var allGuideId = travelAgency.Guides
                             .Select(d => d.GuideId)
                             .ToList();

            for (int i = 0; i < number; i++)
            {
                if (i % 100 == 0)
                {
                    travelAgency.SaveChanges();
                    travelAgency.Dispose();
                    travelAgency = new TravelAgencyDbContext();
                }

                var startDate         = new DateTime(2015, this.rand.Next(1, 13), this.rand.Next(1, 29));
                var endDate           = startDate.AddDays(this.rand.Next(5, 15));
                var currentCountryObj = allDestinations[this.rand.Next(0, allDestinations.Count - 1)];

                var exursion = new Excursion
                {
                    Name           = this.Names[this.rand.Next(0, this.Names.Length)] + currentCountryObj.Name,
                    StartDate      = startDate,
                    EndDate        = endDate,
                    DestinationId  = currentCountryObj.ID,
                    Clients        = this.rand.Next(0, 150),
                    PricePerClient = (decimal)this.rand.Next(500, 10000),
                    TransportId    = allTransportIds[this.rand.Next(0, allTransportIds.Count - 1)],
                    GuideId        = allGuideId[this.rand.Next(0, allGuideId.Count - 1)],
                    ExpenseId      = this.rand.Next(0, 10)
                };

                travelAgency.Excursions.Add(exursion);
            }

            travelAgency.SaveChanges();
            travelAgency.Dispose();
        }
        public void AddRandomNumberOfExcursion(int number)
        {
            var travelAgency = new TravelAgencyDbContext();

            var allDestinations = travelAgency.Destinations
                .Select(d => new
                {
                    ID = d.DestinationId,
                    Name = d.Country
                })
                .ToList();

            var allTransportIds = travelAgency.Transports
                .Select(d => d.TransportId)
                .ToList();

            var allGuideId = travelAgency.Guides
                .Select(d => d.GuideId)
                .ToList();

            for (int i = 0; i < number; i++)
            {
                if (i % 100 == 0)
                {
                    travelAgency.SaveChanges();
                    travelAgency.Dispose();
                    travelAgency = new TravelAgencyDbContext();
                }

                var startDate = new DateTime(2015, this.rand.Next(1, 13), this.rand.Next(1, 29));
                var endDate = startDate.AddDays(this.rand.Next(5, 15));
                var currentCountryObj = allDestinations[this.rand.Next(0, allDestinations.Count - 1)];

                var exursion = new Excursion
                {
                    Name = this.Names[this.rand.Next(0, this.Names.Length)] + currentCountryObj.Name,
                    StartDate = startDate,
                    EndDate = endDate,
                    DestinationId = currentCountryObj.ID,
                    Clients = this.rand.Next(0, 150),
                    PricePerClient = (decimal)this.rand.Next(500, 10000),
                    TransportId = allTransportIds[this.rand.Next(0, allTransportIds.Count - 1)],
                    GuideId = allGuideId[this.rand.Next(0, allGuideId.Count - 1)],
                    ExpenseId = this.rand.Next(0, 10)
                };

                travelAgency.Excursions.Add(exursion);
            }

            travelAgency.SaveChanges();
            travelAgency.Dispose();
        }
Ejemplo n.º 32
0
 public void AddToExcursion(Excursion excursion)
 {
     base.AddObject("Excursion", excursion);
 }
Ejemplo n.º 33
0
 public static Excursion CreateExcursion(long id, string text, string title, int sortOrder, bool popular, string name, int excursionType)
 {
     Excursion excursion = new Excursion();
     excursion.Id = id;
     excursion.Text = text;
     excursion.Title = title;
     excursion.SortOrder = sortOrder;
     excursion.Popular = popular;
     excursion.Name = name;
     excursion.ExcursionType = excursionType;
     return excursion;
 }