public async Task <Guid> Handle(CreateNewsCommand request, CancellationToken cancellationToken)
        {
            _content.Newses.Add(request.News);
            var id = request.News.id;

            _content.SaveChanges();

            return(await Task.FromResult(id));
        }
Exemple #2
0
        public async Task <Guid> Handle(CreateCommentCommand request, CancellationToken cancellationToken)
        {
            _context.Comment.Add(request.Comment);         //add comment to db
            var id = request.Comment.id;

            _context.SaveChanges();

            return(await Task.FromResult(id));
        }
Exemple #3
0
 public ActionResult Edit(DONHANG dt)
 {
     if (ModelState.IsValid)
     {
         db.Entry(dt).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Exemple #4
0
        public ActionResult ThanhToan([Bind(Include = "MADH,TENKH,DIACHI,DIENTHOAI,EMAIL,TRANGTHAI,NGAYTAO,GHICHU")]
                                      DONHANG donhang, string tenkh, string diachi, string sdt, string email, string ghichu, string trangthai)
        {
            donhang.TENKH     = tenkh;
            donhang.DIACHI    = diachi;
            donhang.DIENTHOAI = sdt;
            donhang.EMAIL     = email;

            donhang.NGAYTAO = DateTime.Now;
            donhang.GHICHU  = ghichu;
            if (trangthai == "0")
            {
                donhang.TRANGTHAI = false;
            }
            else
            {
                donhang.TRANGTHAI = true;
            }

            var     cart = (Cart)Session[CartSession];
            decimal tong = 0;

            try
            {
                if (cart != null)
                {
                    db.DONHANGs.Add(donhang);
                    db.SaveChanges();
                    var ID = (from x in db.DONHANGs orderby x.MADH descending select x.MADH).Take(1).Single();
                    foreach (var item in cart.Lines)
                    {
                        var CTDonHang = new CTDONHANG();
                        CTDonHang.MASP = item.SANPHAM.MASP;
                        CTDonHang.MADH = ID;
                        CTDonHang.GIA  = item.SANPHAM.GIA - item.SANPHAM.GIAMGIA * item.SANPHAM.GIA / 100;
                        CTDonHang.SL   = item.Quantity;

                        db.CTDONHANGs.Add(CTDonHang);
                        tong += (item.SANPHAM.GIA - item.SANPHAM.GIAMGIA * item.SANPHAM.GIA / 100).GetValueOrDefault(0) * item.Quantity;

                        SANPHAM sp     = db.SANPHAMs.SingleOrDefault(n => n.MASP == CTDonHang.MASP);
                        int     sl1    = (int)sp.SOLUONG;
                        int     sl2    = item.Quantity;
                        int     conlai = sl1 - sl2;
                        sp.SOLUONG         = conlai;
                        db.Entry(sp).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                }
            }
            catch (DbEntityValidationException ex)
            {
                var errorMessages     = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage);
                var fullErrorMessages = string.Join(";", errorMessages);
                var exceptionMessages = string.Concat(ex.Message, "The validation errors are: ", fullErrorMessages);
                throw new DbEntityValidationException(exceptionMessages, ex.EntityValidationErrors);
            }
            cart = null;
            Session[CartSession] = cart;
            return(RedirectToAction("ThanhCong"));
        }
Exemple #5
0
 public void Save()
 {
     _context.SaveChanges();
 }
Exemple #6
0
        void initObjects(DbContent db)
        {
            List <Genre> genres = db.Genre.ToList();
            List <Actor> actors = db.Actor.ToList();
            List <Film>  films  = db.Film.ToList();

            if (!db.Genre.Any())
            {
                genres = new List <Genre>
                {
                    new Genre {
                        name = "Fantasy"
                    },
                    new Genre {
                        name = "Drama"
                    },
                    new Genre {
                        name = "Triller"
                    },
                    new Genre {
                        name = "Western"
                    },
                };
                db.AddRange(genres);
                db.SaveChanges();
            }
            if (!db.Actor.Any())
            {
                actors = new List <Actor>
                {
                    new Actor {
                        fullName = "John Cristopher \"Johnny\" Depp"
                    },
                    new Actor {
                        fullName = "Armand Douglas \"Armie\" Hammer"
                    },
                    new Actor {
                        fullName = "Keanu Charles Reeves"
                    },
                    new Actor {
                        fullName = "Michael Nyqvist"
                    },
                    new Actor {
                        fullName = "Laurence J. Fishburne"
                    },
                    new Actor {
                        fullName = "Tom Hanks"
                    },
                    new Actor {
                        fullName = "Robin Virginia Gayle Wright"
                    },
                    new Actor {
                        fullName = "Edward Harrison Norton"
                    },
                    new Actor {
                        fullName = "William Bradley \"Brad\" Pitt"
                    },
                    new Actor {
                        fullName = "David Morse"
                    },
                    new Actor {
                        fullName = "Tim Robbins"
                    },
                    new Actor {
                        fullName = "Morgan Freeman"
                    },
                };
                db.AddRange(actors);
                db.SaveChanges();
            }
            if (!db.Film.Any())
            {
                films.Add(new Film {
                    name = "Pirates of the Caribbean on stranger tides", genre = genres.First(g => g.name.Contains("Fantasy")), imgPath = "PotC.jpg"
                });
                films.Add(new Film {
                    name = "The Shawshank Redemption", genre = genres.First(g => g.name.Contains("Drama")), imgPath = "TSR.jpg"
                });
                films.Add(new Film {
                    name = "The Green Mile", genre = genres.First(g => g.name.Contains("Drama")), imgPath = "TGM.jpg"
                });
                films.Add(new Film {
                    name = "Fight Club", genre = genres.First(g => g.name.Contains("Triller")), imgPath = "FC.jpg"
                });
                films.Add(new Film {
                    name = "Forrest Gump", genre = genres.First(g => g.name.Contains("Drama")), imgPath = "FG.jpg"
                });
                films.Add(new Film {
                    name = "The Matrix", genre = genres.First(g => g.name.Contains("Fantasy")), imgPath = "TM.jpg"
                });
                films.Add(new Film {
                    name = "John Wick", genre = genres.First(g => g.name.Contains("Triller")), imgPath = "JW.jpg"
                });
                films.Add(new Film {
                    name = "The Lone Ranger", genre = genres.First(g => g.name.Contains("Western")), imgPath = "TLR.jpg"
                });

                db.AddRange(films);
                db.SaveChanges();
                Film film = null;
                film = films.First(f => f.name.Contains("Pirates"));
                film.FilmActor.Add(new FilmActor {
                    FilmId = film.id, ActorId = actors.First(a => a.fullName.Contains("Depp")).id
                });


                film = films.First(f => f.name.Contains("Shawshank"));
                film.FilmActor.Add(new FilmActor {
                    FilmId = film.id, ActorId = actors.First(a => a.fullName.Contains("Tim")).id
                });
                film.FilmActor.Add(new FilmActor {
                    FilmId = film.id, ActorId = actors.First(a => a.fullName.Contains("Morgan")).id
                });


                film = films.First(f => f.name.Contains("Green"));
                film.FilmActor.Add(new FilmActor {
                    FilmId = film.id, ActorId = actors.First(a => a.fullName.Contains("Tom")).id
                });
                film.FilmActor.Add(new FilmActor {
                    FilmId = film.id, ActorId = actors.First(a => a.fullName.Contains("David")).id
                });


                film = films.First(f => f.name.Contains("Fight"));
                film.FilmActor.Add(new FilmActor {
                    FilmId = film.id, ActorId = actors.First(a => a.fullName.Contains("Edward")).id
                });
                film.FilmActor.Add(new FilmActor {
                    FilmId = film.id, ActorId = actors.First(a => a.fullName.Contains("Brad")).id
                });

                film = films.First(f => f.name.Contains("Forrest"));
                film.FilmActor.Add(new FilmActor {
                    FilmId = film.id, ActorId = actors.First(a => a.fullName.Contains("Tom")).id
                });
                film.FilmActor.Add(new FilmActor {
                    FilmId = film.id, ActorId = actors.First(a => a.fullName.Contains("Robin")).id
                });

                film = films.First(f => f.name.Contains("Matrix"));
                film.FilmActor.Add(new FilmActor {
                    FilmId = film.id, ActorId = actors.First(a => a.fullName.Contains("Keanu")).id
                });
                film.FilmActor.Add(new FilmActor {
                    FilmId = film.id, ActorId = actors.First(a => a.fullName.Contains("Laurence")).id
                });

                film = films.First(f => f.name.Contains("Wick"));
                film.FilmActor.Add(new FilmActor {
                    FilmId = film.id, ActorId = actors.First(a => a.fullName.Contains("Keanu")).id
                });
                film.FilmActor.Add(new FilmActor {
                    FilmId = film.id, ActorId = actors.First(a => a.fullName.Contains("Michael")).id
                });

                film = films.First(f => f.name.Contains("Lone"));
                film.FilmActor.Add(new FilmActor {
                    FilmId = film.id, ActorId = actors.First(a => a.fullName.Contains("Depp")).id
                });
                film.FilmActor.Add(new FilmActor {
                    FilmId = film.id, ActorId = actors.First(a => a.fullName.Contains("Armand")).id
                });

                db.SaveChanges();
            }
        }