示例#1
0
 public FuelResult(DateTimeOffset timestamp, Station station, PriceStatus priceStatus)
 {
     TimeStamp   = timestamp;
     Station     = station;
     PriceStatus = priceStatus;
 }
        public PriceStatus modifybook(WishListModel wish)
        {
            string s = "";

            PriceStatus pr = new PriceStatus();



            try
            {
                using (var dbcontext = new Orchard9Entities())
                {
                    double?amount = 0;
                    if ((from d in dbcontext.tblWishlists where d.ISBN == wish.ISBN select d).Count() > 0)
                    {
                        amount = (from d in dbcontext.tblWishlists where d.ISBN == wish.ISBN select d.CurrentPrice).FirstOrDefault();
                    }
                    else
                    {
                        amount = (from d in dbcontext.tblBooks where d.ISBN == wish.ISBN select d.Price).FirstOrDefault();
                    }
                    var dis = Convert.ToDouble(wish.price);

                    var query = (from e in dbcontext.tblWishlists
                                 join d in dbcontext.tblBooks on e.ISBN equals d.ISBN
                                 join x in dbcontext.tblUsers on e.UserId equals x.UserId
                                 where e.UserId == x.UserId && wish.ISBN == d.ISBN
                                 select new PriceModel()
                    {
                        mailid = x.EmailId
                    }).ToList();



                    if ((from d in dbcontext.tblBooks where d.ISBN == wish.ISBN select d.Price).ToList().Count == 0)
                    {
                        pr.statusMessage = "This book does not exist";

                        return(pr);
                    }
                    if (amount == dis)
                    {
                        pr.statusMessage = "no changes";
                        pr.statusList    = query;
                        pr.changedPrice  = 0;
                        pr.bookName      = wish.BookName;
                    }
                    else if (amount > dis)

                    {
                        pr.changedPrice  = amount - dis;
                        pr.statusList    = query;
                        pr.statusMessage = "reduced";
                        pr.bookName      = wish.BookName;
                    }
                    else
                    {
                        pr.changedPrice  = dis - amount;
                        pr.statusList    = query;
                        pr.bookName      = wish.BookName;
                        pr.statusMessage = "increased";
                    }



                    dbcontext.tblBooks.Where(h => h.ISBN == wish.ISBN).ToList().ForEach(h =>
                    {
                        h.Price        = wish.price;
                        h.Publisher    = wish.Publisher;
                        h.Author       = wish.Author;
                        h.Rating       = wish.rating;
                        h.BookName     = wish.BookName;
                        h.Description  = "jj";
                        h.Category     = "hhh";
                        h.isactive     = true;
                        h.BookImageUrl = wish.BookImageUrl;
                    });
                    dbcontext.tblWishlists.Where(h => h.ISBN == wish.ISBN).ToList().ForEach(h =>
                    {
                        h.CurrentPrice = wish.price;
                    });
                    dbcontext.SaveChanges();
                }
            }

            catch (Exception e)
            {
                s = e.Message;
                pr.statusMessage = s;
            }
            return(pr);
        }