Exemple #1
0
 public IActionResult CrearNotaA(Nota nota)
 {
     nota.UltimaModificacion = DateTime.Now;
     _context.notas.Add(nota);
     _context.SaveChanges();
     return(RedirectToAction("Index"));
 }
Exemple #2
0
        public IActionResult Index()
        {
            ViewBag.UserId = HttpContext.Session.GetInt32("UserId");
            if (ViewBag.UserId == null)
            {
                return(RedirectToAction("Index", "Logins"));
            }
            ViewBag.Wallet = dbContext.Users.Where(u => u.user_id == HttpContext.Session.GetInt32("UserId")).First().wallet;

            var AllAuctions = dbContext.Auctions
                              .Include(auction => auction.creator)
                              .OrderByDescending(auction => auction.created_at).ToList();

            // this will process auctions
            foreach (var auction in AllAuctions)
            {
                if ((int)(DateTime.Now - auction.created_at).TotalDays < 0)
                {
                    if (auction.highest_bidder_id != 0)// Only if somebody has placed a bid, will it continue
                    {
                        var bidder = dbContext.Users.FirstOrDefault(u => u.user_id == auction.highest_bidder_id);
                        auction.creator.wallet += auction.highest_bid;
                        bidder.wallet          -= auction.highest_bid;
                    }
                    dbContext.Auctions.Remove(auction);
                    dbContext.SaveChanges();
                }
            }
            // auctions have been processed, grab remaining

            AllAuctions = dbContext.Auctions
                          .Include(auction => auction.creator)
                          .OrderByDescending(auction => auction.created_at).ToList();
            return(View(AllAuctions));
        }
Exemple #3
0
        public ActionResult Create([Bind(Include = "ID,Name,BirthDate,BirthCity")] Artists artists)
        {
            if (ModelState.IsValid)
            {
                db.Artists.Add(artists);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(artists));
        }
Exemple #4
0
        public ActionResult Create([Bind(Include = "ID,GoatID,CustomerID,GoatName,CustomerFirst,CustomerLast,LotAddress,LotDescription")] Lot lot)
        {
            if (ModelState.IsValid)
            {
                db.Lots.Add(lot);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(lot));
        }
        public ActionResult Create([Bind(Include = "ID,Name")] Genres genres)
        {
            if (ModelState.IsValid)
            {
                db.Genres.Add(genres);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(genres));
        }
Exemple #6
0
        public ActionResult Create([Bind(Include = "ItemID,ItemName,ItemDescription,SellerID")] Item item)
        {
            if (ModelState.IsValid)
            {
                db.Items.Add(item);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.SellerID = new SelectList(db.Sellers, "SellerID", "Sellername", item.SellerID);
            return(View(item));
        }
        public ActionResult Create([Bind(Include = "ID,Title,Start,Duration,Location,PersonID")] Event @event)
        {
            if (ModelState.IsValid)
            {
                db.Events.Add(@event);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.PersonID = new SelectList(db.Persons, "ID", "Name", @event.PersonID);
            return(View(@event));
        }
Exemple #8
0
        public ActionResult Create([Bind(Include = "ID,Title,ArtistID")] ArtWorks artWorks)
        {
            if (ModelState.IsValid)
            {
                db.ArtWorks.Add(artWorks);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }


            ViewBag.ArtistID = new SelectList(db.Artists, "ID", "Name", artWorks.ArtistID);
            return(View(artWorks));
        }
Exemple #9
0
        public ActionResult Create([Bind(Include = "ID,ArtWorkID,GenreID")] Classifications classifications)
        {
            if (ModelState.IsValid)
            {
                db.Classifications.Add(classifications);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ArtWorkID = new SelectList(db.ArtWorks, "ID", "Title", classifications.ArtWorkID);
            ViewBag.GenreID   = new SelectList(db.Genres, "ID", "Name", classifications.GenreID);
            return(View(classifications));
        }
        //  public ActionResult Create([Bind(Include = "ID,Timestamp,EventID,PersonID")] RSVP rSVP)
        // {
        public ActionResult Create([Bind(Include = "ID,EventID,PersonID")] RSVP rSVP)
        {
            rSVP.Timestamp = DateTime.Now;
            if (ModelState.IsValid)
            {
                db.RSVPs.Add(rSVP);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.EventID  = new SelectList(db.Events, "ID", "Title", rSVP.EventID);
            ViewBag.PersonID = new SelectList(db.Persons, "ID", "Name", rSVP.PersonID);
            return(View(rSVP));
        }
        public ActionResult Create([Bind(Include = "BidID,ItemID,BuyerID,Price,Stamp")] Bid bid)
        {
            if (ModelState.IsValid)
            {
                bid.Stamp = DateTime.Now;
                db.Bids.Add(bid);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.BuyerID = new SelectList(db.Buyers, "BuyerID", "Buyername", bid.BuyerID);
            ViewBag.ItemID  = new SelectList(db.Items, "ItemID", "ItemName", bid.ItemID);
            return(View(bid));
        }
Exemple #12
0
        public ContactsVM()
        {
            var db = new FinalContext();

            ContactList = db.People.Local;
            db.People.Load();
            EmailList   = new ObservableCollection <Email>();
            AddressList = new ObservableCollection <Address>();
            PhoneList   = new ObservableCollection <Phone>();
            TypeList    = new ObservableCollection <CType>();

            SaveCommand      = new DelegateCommand(() => db.SaveChanges());
            AddPersonCommand = new DelegateCommand(() => {
                CurrentPerson = new Person();
                ContactList.Add(CurrentPerson);
                db.People.Add(CurrentPerson);
            });
            AddEmailCommand = new DelegateCommand(() => {
                var em = new Email();
                CurrentPerson.Emails.Add(em);
            });
            DeletePersonCommand = new DelegateCommand(() => {
                db.People.Remove(CurrentPerson);
                ContactList.Remove(CurrentPerson);
            });
            AddPhoneCommand = new DelegateCommand(() => {
                var pn = new Phone();
                CurrentPerson.Phones.Add(pn);
            });
            AddAddressCommand = new DelegateCommand(() => {
                var ad = new Address();
                CurrentPerson.Addresses.Add(ad);
            });
            DeleteAddressCommand = new DelegateCommand(() => {
                db.Addresses.Remove(CurrentAddress);
                AddressList.Remove(CurrentAddress);
            });
            DeletePhoneCommand = new DelegateCommand(() => {
                db.Phones.Remove(CurrentPhone);
                PhoneList.Remove(CurrentPhone);
            });
            DeleteEmailCommand = new DelegateCommand(() => {
                db.Emails.Remove(CurrentEmail);
                EmailList.Remove(CurrentEmail);
            });
        }
Exemple #13
0
        public IActionResult AddUser(User NewUser)
        {
            if (ModelState.IsValid)
            {
                if (dbContext.Users.Any(u => u.email == NewUser.email))
                {
                    ModelState.AddModelError("email", "email exists!");
                    return(View("Index"));
                }

                PasswordHasher <User> hasher = new PasswordHasher <User>();
                NewUser.password = hasher.HashPassword(NewUser, NewUser.password);

                dbContext.Users.Add(NewUser);
                dbContext.SaveChanges();

                HttpContext.Session.SetInt32("UserId", NewUser.user_id);
                return(RedirectToAction("Index", "Final"));
            }
            else
            {
                return(View("Index"));
            }
        }
Exemple #14
0
 public void AddPost(ForumModel forum)
 {
     //throw new NotImplementedException();
     context.Posts.Add(forum);
     context.SaveChanges();
 }
Exemple #15
0
 public void Save()
 {
     //var db = new FinalContext();
     db.Configuration.ProxyCreationEnabled = false;
     db.SaveChanges();
 }