示例#1
0
        public void DeleteEvent(int idEvent)
        {
            Models.DataContext context = new Models.DataContext();
            Event tmp = new Event {
                Id = idEvent
            };

            context.Event.Remove(tmp);
            context.SaveChanges();

            Event currentEvent = null;

            foreach (var destination in _destinations)
            {
                foreach (var evt in destination.Event)
                {
                    if (evt.Id == idEvent)
                    {
                        currentEvent = evt;
                        break;
                    }
                }
            }
            if (currentEvent != null)
            {
                _destinations.Where(d => d.Id == currentEvent.DestinationId).First().Event.Remove(currentEvent);
            }
        }
示例#2
0
        public void AddDestination(Destination destination)
        {
            destination.TravelId = TravelHelper.Instance.Travel.Id;
            Models.DataContext context = new Models.DataContext();
            var newDestination         = context.Destination.Add(destination);

            context.SaveChanges();
            _destinations.Add(newDestination.Entity);
        }
示例#3
0
        public bool CreateWine(CreateWineRequest request)
        {
            try
            {
                var wineList = MapRequestToWineListModel(request);
                _dataContext.Winelists.Add(wineList);

                var persisted = _dataContext.SaveChanges();
                return(persisted >= 1);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(false);
            }
            catch (DbUpdateException)
            {
                return(false);
            }
        }
示例#4
0
        public void AddEvent(Event newEvent, EventType type)
        {
            Models.DataContext context = new Models.DataContext();
            var eventInDb = context.Event.Add(newEvent);

            context.SaveChanges();
            newEvent.Id   = eventInDb.Entity.Id;
            newEvent.Type = type;
            _destinations.Where(d => d.Id == newEvent.DestinationId).First().Event.Add(newEvent);
        }
示例#5
0
        public void DeleteDestination(int id)
        {
            Models.DataContext context = new Models.DataContext();
            Destination        tmp     = new Destination {
                Id = id
            };

            context.Destination.Remove(tmp);
            context.SaveChanges();
            _destinations.Remove(_destinations.Where(d => d.Id == id).Single());
        }
示例#6
0
 public ActionResult NewUser(User user)
 {
     if (!ModelState.IsValid)
     {
         return(View("Register", user));
     }
     else
     {
         //Registrar el Usuario en la Base de Datos si previamente no existe
         using (var context = new Models.DataContext())
         {
             if (!context.Users.Any(x => x.IdUser == user.IdUser))
             {
                 context.Users.Add(user);
                 context.SaveChanges();
             }
         }
         return(RedirectToAction("Index"));
     }
 }
示例#7
0
 public string this[string setting]
 {
     get
     {
         return(_dbContext.Config.SingleOrDefault(q => q.ConfigID == setting)?.Value);
     }
     set
     {
         try
         {
             _dbContext.Config.SingleOrDefault(q => q.ConfigID == setting).Value = value;
         }
         catch
         {
             _dbContext.Config.Add(new Models.Data.Config()
             {
                 ConfigID = setting, Value = value
             });
         }
         _dbContext.SaveChanges();
     }
 }
 public ActionResult NewUser(User user)
 {
     if (!ModelState.IsValid)
     {
         return View("Register", user);
     }
     else
     {
         //Registrar el Usuario en la Base de Datos si previamente no existe
         using (var context = new Models.DataContext())
         {
             if (!context.Users.Any(x => x.IdUser == user.IdUser))
             {
                 context.Users.Add(user);
                 context.SaveChanges();
             }
         }
         return RedirectToAction("Index");
     }
 }