Example #1
0
        public Model.LogProduct Add(LogProduct log)
        {
            this.Context.LogProducts.Add(log);
            this.Context.SaveChanges();

            return(log);
        }
        public LogProduct Add(LogProduct logProduct)
        {
            this.Context.LogProduct.Add(logProduct);
            this.Context.SaveChanges();

            return(logProduct);
        }
Example #3
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            using (ShopManagementContext context = new ShopManagementContext())
            {
                _productRepository    = new ProductRepository(context);
                _logProductRepository = new LogProductRepository(context);
                int userid = Convert.ToInt32(lbl_UserId.Text);
                var user   = context.Users.Where(y => y.Id == userid).FirstOrDefault();
                if (String.IsNullOrEmpty(tbx_productName.Text) || String.IsNullOrEmpty(txb_Count.Text) ||
                    String.IsNullOrEmpty(txb_Price.Text) || String.IsNullOrEmpty(cmb_Category.Text) || rtb_Description.Text == "")
                {
                    MessageBox.Show("İzahat hissəsin doldurun");
                }

                else
                {
                    Product product = new Product()
                    {
                        Id          = Convert.ToInt32(dgw_ProductTable.CurrentRow.Cells[0].Value),
                        Name        = tbx_productName.Text,
                        CategoryId  = Convert.ToInt32(cmb_Category.Text.Split('.')[0]),
                        Price       = Convert.ToDecimal(txb_Price.Text),
                        Count       = Convert.ToInt32(txb_Count.Text),
                        UserId      = user.Id,
                        PhoneNumber = user.Phone,
                        Status      = (int)Status.Active,
                        ExpireDate  = dtp_Expire.Value
                    };


                    LogProduct logProduct = new LogProduct()
                    {
                        ProductId   = product.Id,
                        Description = rtb_Description.Text,
                        Status      = (int)Status.Modified,
                        UserId      = user.Id,
                        Date        = DateTime.Now
                    };
                    _productRepository.Update(product);
                    _productRepository.Save();

                    _logProductRepository.Insert(logProduct);
                    _logProductRepository.Save();
                    Clear();

                    if (user.RoleId == (int)Enums.Role.Admin)
                    {
                        GetAllProduct();
                    }
                    else
                    {
                        GetProductInsertedByUser();
                    }
                }
            }
        }
Example #4
0
        private void btn_Delete_Click(object sender, EventArgs e)
        {
            using (ShopManagementContext context = new ShopManagementContext())
            {
                _productRepository    = new ProductRepository(context);
                _logProductRepository = new LogProductRepository(context);
                int userid = Convert.ToInt32(lbl_UserId.Text);
                var user   = context.Users.Where(y => y.Id == userid).FirstOrDefault();
                if (rtb_Description.Text == "")
                {
                    MessageBox.Show("Izahat mətnini daxil edin");
                }
                else
                {
                    Product product = new Product()
                    {
                        Id   = Convert.ToInt32(dgw_ProductTable.CurrentRow.Cells[0].Value),
                        Name = dgw_ProductTable.CurrentRow.Cells[1].Value.ToString(),

                        CategoryId  = Convert.ToInt32(dgw_ProductTable.CurrentRow.Cells[7].Value.ToString()),
                        Price       = Convert.ToDecimal(dgw_ProductTable.CurrentRow.Cells[2].Value.ToString()),
                        Count       = Convert.ToInt32(dgw_ProductTable.CurrentRow.Cells[3].Value.ToString()),
                        UserId      = user.Id,
                        PhoneNumber = user.Phone,
                        Status      = (int)Status.Deactive,
                        ExpireDate  = dtp_Expire.Value
                    };

                    LogProduct logProduct = new LogProduct()
                    {
                        ProductId   = product.Id,
                        Description = rtb_Description.Text,
                        Status      = (int)Status.Deleted,
                        UserId      = user.Id,
                        Date        = DateTime.Now
                    };
                    _productRepository.Update(product);
                    _logProductRepository.Insert(logProduct);


                    _productRepository.Update(product);
                    _productRepository.Save();
                    if (user.RoleId == (int)Enums.Role.Admin)
                    {
                        GetAllProduct();
                    }
                    else
                    {
                        GetProductInsertedByUser();
                    }
                }
            }
        }
Example #5
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            using (ShopManagementContext context = new ShopManagementContext())
            {
                productRepository    = new ProductRepository(context);
                logProductRepository = new LogProductRepository(context);
                int     userid  = Convert.ToInt32(lbl_UserId.Text);
                var     user    = context.Users.Where(y => y.Id == userid).FirstOrDefault();
                Product product = new Product()
                {
                    Id            = Convert.ToInt32(dgw_ProductTable.CurrentRow.Cells[0].Value),
                    Name          = txb_PrUpdateName.Text,
                    CategoryId    = Convert.ToInt32(cmb_UpdatePr.Text.Split('.')[0]),
                    Price         = Convert.ToDecimal(txb_PrUpdatePrice.Text),
                    Count         = Convert.ToInt32(txb_PrUpdateCount.Text),
                    CreatedUserId = user.Id,
                    PhoneNumber   = user.Phone,
                    Status        = 0,
                };
                if (rtb_Description.Text == null)
                {
                    MessageBox.Show("Izahat mətnini daxil edin");
                }
                else
                {
                    LogProduct logProduct = new LogProduct()
                    {
                        ProductId   = product.Id,
                        Description = rtb_Description.Text,
                        Status      = 1,
                        UserId      = user.Id,
                        Date        = DateTime.Now
                    };
                    productRepository.Update(product);
                    logProductRepository.Insert(logProduct);
                }

                GetAllProduct();
            }
        }
Example #6
0
        private void SortByExpireDate()
        {
            using (ShopManagementContext context = new ShopManagementContext())
            {
                _productRepository    = new ProductRepository(context);
                _logProductRepository = new LogProductRepository(context);
                var list = _productRepository.GetAll();
                var user = context.Users.Where(u => u.RoleId == (int)Enums.Role.Admin).FirstOrDefault();

                var sortedList = list.Where(p => p.ExpireDate.Day.CompareTo(DateTime.Now.Day) == 0);
                foreach (var i in sortedList)
                {
                    i.Status      = (int)Enums.Status.Expired;
                    i.Name        = i.Name;
                    i.Id          = i.Id;
                    i.PhoneNumber = i.PhoneNumber;
                    i.Price       = i.Price;
                    i.SoldedCount = i.SoldedCount;
                    i.ExpireDate  = i.ExpireDate;
                    i.SoldedTotal = i.SoldedTotal;
                    i.UserId      = i.UserId;
                    i.CategoryId  = i.CategoryId;
                    i.Count       = i.Count;
                    _productRepository.Update(i);
                    _productRepository.Save();
                    LogProduct logProduct = new LogProduct()
                    {
                        ProductId   = i.Id,
                        Description = "İstifadə tarxi bitib",
                        Status      = (int)Status.Expired,
                        UserId      = user.Id,
                        Date        = i.ExpireDate
                    };
                    _logProductRepository.Insert(logProduct);
                    _logProductRepository.Save();
                }
            }
        }