コード例 #1
0
        public decimal SummOfGoodsSold()
        {
            decimal summ = 0;

            using (OnlineStoreEntities db = new OnlineStoreEntities())
            {
                List <orderDTO> orders = new List <orderDTO>();

                orders = mapper.Map <List <orderDTO> >(db.C_order_.ToList());
                DateTime now = DateTime.Now;

                foreach (orderDTO order in orders)
                {
                    //   if ((now - order.sell_time).TotalDays < 30)
                    if (now.Month == order.sell_time.Month)

                    {
                        product_id prod = db.product_id
                                          .Where(u => u.product_id1 == order.product_id)
                                          .FirstOrDefault();
                        productDTO new_prod = mapper.Map <productDTO>(prod);

                        summ += new_prod.price;
                    }
                }//дали розбити .сума куплениї можна прото поточний місяць і з знижкою 3 параметри брати ід продукт ід і знижку і ставити там
            }
            return(summ);
        }
コード例 #2
0
 public void AddUser(userDTO user)
 {
     using (var db = new OnlineStoreEntities())
     {
         user_id target = mapper.Map <user_id>(user);
         db.user_id.Add(target);
         db.SaveChanges();
     }
 }
コード例 #3
0
 //[any methods]
 protected void Session_Start()
 {
     // 'using' will call entity.Dispose() at the end of the block so you
     // don't have to bother about disposing your entity
     using (OnlineStoreEntities entity = new OnlineStoreEntities()){
         // store your categories inside a Session variable as a List<Category>
         Session["Categories"] = entity.Categories.ToList();
     }
 }
コード例 #4
0
        public List <productDTO> GetAllProducts()
        {
            List <productDTO> products = new List <productDTO>();

            using (OnlineStoreEntities db = new OnlineStoreEntities())
            {
                products = mapper.Map <List <productDTO> >(db.product_id.ToList());
            }
            return(products);
        }
コード例 #5
0
        public List <userDTO> GetAllUsers()
        {
            List <userDTO> users = new List <userDTO>();

            using (OnlineStoreEntities db = new OnlineStoreEntities())
            {
                users = mapper.Map <List <userDTO> >(db.user_id.ToList());
                return(users);
            }
        }
コード例 #6
0
        public userDTO GetUserByID(int Id)
        {
            using (OnlineStoreEntities db = new OnlineStoreEntities())
            {
                user_id target = db.user_id
                                 .Where(u => u.id == Id)
                                 .FirstOrDefault();

                return(mapper.Map <userDTO>(target));
            }
        }
コード例 #7
0
 public void DeleteUser(int id)
 {
     using (OnlineStoreEntities db = new OnlineStoreEntities())
     {
         //db.user_id.Attach(user);
         // db.user_id.Remove(user);
         user_id target = db.user_id
                          .Where(u => u.id == id)
                          .FirstOrDefault();
         db.Entry(target).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
コード例 #8
0
 protected void Session_Start()
 {
     // 'using' will call entity.Dispose() at the end of the block so you
     // don't have to bother about disposing your entity
     using (OnlineStoreEntities entity = new OnlineStoreEntities()){
         HttpContext context = HttpContext.Current;
         if (context != null && context.Session != null)
         {
             // fill the Session var with the Categories from your database
             context.Session["Categories"] = entity.Categories.ToList();
         }
     }
 }
コード例 #9
0
 public void SetDiscountForUser(int Id, int productId, int discount)
 {
     using (OnlineStoreEntities db = new OnlineStoreEntities())
     {
         discountDTO add = new discountDTO
         {
             id         = Id,
             product_id = productId,
             discount1  = discount
         };
         db.discounts.Add(mapper.Map <discount>(add));
         db.SaveChanges();
     }
 }
コード例 #10
0
        public int UpdateUser(userDTO user)
        {
            using (OnlineStoreEntities db = new OnlineStoreEntities())
            {
                user_id target = db.user_id
                                 .Where(u => u.id == user.id)
                                 .FirstOrDefault();
                //target = mapper.Map<user_id>(user);
                target.user_name  = user.user_name;
                target.first_Name = user.first_Name;
                target.last_Name  = user.last_Name;
                target.address    = user.address;

                db.SaveChanges();
                return(target.id);
            }
        }
コード例 #11
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                User user = null;

                using (OnlineStoreEntities db = new OnlineStoreEntities())
                {
                    user = db.Users.FirstOrDefault(u => u.Login == model.Login);
                }
                if (user == null)
                {
                    string salt     = Hashing.Hashing.CreateSalt();
                    string hashPass = Hashing.Hashing.GenerateHash(model.Password + salt);

                    using (OnlineStoreEntities db = new OnlineStoreEntities())
                    {
                        db.Users.Add(new User {
                            Login    = model.Login,
                            Password = hashPass,
                            RoleId   = 2,
                            Salt     = salt,
                            Email    = "",
                            FullName = "",
                            Money    = 1000000
                        });
                        db.SaveChanges();

                        user = db.Users.Where(u => u.Login == model.Login && u.Password == hashPass).FirstOrDefault();
                    }
                    if (user != null)
                    {
                        FormsAuthentication.SetAuthCookie(model.Login, true);

                        return(RedirectToAction("Index", "Test"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Пользователь с такими логином уже существует");
                }
            }

            return(View(model));
        }
コード例 #12
0
        public ActionResult Login(LoginModel model)
        {
            User user = null;

            using (OnlineStoreEntities db = new OnlineStoreEntities())
            {
                user = db.Users.FirstOrDefault(u => u.Login == model.Login);
            }

            string hashPass = Hashing.Hashing.GenerateHash(model.Password + user.Salt);

            if (hashPass == user.Password)
            {
                FormsAuthentication.SetAuthCookie(model.Login, true);
                return(RedirectToAction("Index", "Test"));
            }
            else
            {
                ModelState.AddModelError("", "Неверный логин или пароль");
            }

            return(View(model));
        }
コード例 #13
0
 public CartRepository(OnlineStoreEntities dbContext)
 {
     this.dbContext = dbContext;
 }
コード例 #14
0
 public ShippingRepository(OnlineStoreEntities dbContext)
 {
     this.dbContext = dbContext;
 }
コード例 #15
0
 public OrderDetailRepository(OnlineStoreEntities dbContext)
 {
     this.dbContext = dbContext;
 }