コード例 #1
0
        public async Task <IActionResult> PutCarts(long id, Cart carts)
        {
            if (id != carts.Id)
            {
                return(BadRequest());
            }

            _context.Entry(carts).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CartsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> PutUseVoucher(long id, UseVoucher useVoucher)
        {
            if (id != useVoucher.Id)
            {
                return(BadRequest());
            }

            _context.Entry(useVoucher).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UseVoucherExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #3
0
        public async Task <IActionResult> PutYearStatistical(long id, YearStatistical yearStatistical)
        {
            if (id != yearStatistical.Id)
            {
                return(BadRequest());
            }

            _context.Entry(yearStatistical).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!YearStatisticalExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #4
0
        public async Task <IActionResult> Excute()
        {
            var _context = new TGDDContext();
            var order    = new Order();


            order = await _context.Orders.Include(o => o.OrderDetails).Where(order => order.Id == OrderId).FirstOrDefaultAsync();

            order.StatusId = StatusId;

            // update stock , buying time
            if (this.StatusId == 4)
            {
                ProductsAutoUpdate productsAutoUpdate = new ProductsAutoUpdate();
                List <OrderDetail> orderDetails       = order.OrderDetails.ToList();
                foreach (OrderDetail orderDetail in orderDetails)
                {
                    Product product = await _context.Products.FindAsync(orderDetail.ProductId);

                    product.BuyingTimes -= orderDetail.Quantity;
                    product.Stock       += orderDetail.Quantity;

                    _context.Entry(product).State = EntityState.Modified;
                }
                await _context.SaveChangesAsync();
            }

            _context.Entry(order).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                bool orderExist = _context.Orders.Any(o => o.Id == order.Id);
                if (!orderExist)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok("Chuyển trạng thái thành công !"));
        }
コード例 #5
0
        public async Task <ActionResult <Contact> > Excute()
        {
            var _context = new TGDDContext();

            contact.Id      = _context.Contacts.Max(c => c.Id) + 1;
            contact.Date    = DateTime.Now;
            contact.IsReply = false;


            _context.Contacts.Add(contact);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                bool contactExist = _context.Contacts.Any(c => c.Id == contact.Id);
                if (contactExist)
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetContact", new { id = contact.Id }, contact));
        }
コード例 #6
0
        public async Task <ActionResult <Comment> > Excute()
        {
            AssigndataUtils AssigndataUtils = new AssigndataUtils();
            var             _context        = new TGDDContext();


            var comment = AssigndataUtils.AssignComment(commentDTO, 0);

            _context.Comments.Add(comment);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                bool commentExist = _context.Comments.Any(e => e.Id == comment.Id);
                if (commentExist)
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }
            return(CreatedAtAction("GetComments", new { id = comment.Id }, comment));
        }
コード例 #7
0
        public async Task <ActionResult <Favorite> > Excute()
        {
            var _context = new TGDDContext();

            var newFavoriteId = _context.Favorites.Max(c => c.Id) + 1;

            Favorite.Id = newFavoriteId;

            _context.Favorites.Add(Favorite);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                var favoriteExist = _context.Favorites.Any(f => f.Id == Favorite.Id);
                if (favoriteExist)
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetFavorite", new { id = Favorite.Id }, Favorite));
        }
コード例 #8
0
        public async Task <IActionResult> Excute()
        {
            AssigndataUtils AssigndataUtils = new AssigndataUtils();
            var             _context        = new TGDDContext();

            Voucher voucherUpdate = AssigndataUtils.AssignVoucher(voucherDTO, voucherDTO.Id);

            _context.Entry(voucherUpdate).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                bool voucherExist = _context.Vouchers.Any(voucher => voucher.Id == voucherUpdate.Id);
                if (!voucherExist)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok("Update Voucher thành công !"));
        }
コード例 #9
0
        public async Task <ActionResult <Favorite> > Excute()
        {
            var _context = new TGDDContext();
            var favorite = new Favorite();

            List <Favorite> favorites = await _context.Favorites.Where(f => f.ProductId == Favorite.ProductId).ToListAsync();

            foreach (Favorite f in favorites)
            {
                if (f.CustomerId == Favorite.CustomerId)
                {
                    favorite = f;
                    break;
                }
            }

            if (favorite == null)
            {
                return(NotFound());
            }

            _context.Favorites.Remove(favorite);
            await _context.SaveChangesAsync();

            return(favorite);
        }
コード例 #10
0
        public async Task <ActionResult <IEnumerable <Circle> > > GetCircle()
        {
            List <OrderDetail> orderDetails = await _context.OrderDetails.Include(o => o.Product).ToListAsync();

            List <Circle> circles = await _context.Circle.ToListAsync();

            var c = new int[4];

            foreach (OrderDetail orderDetail in orderDetails)
            {
                c[orderDetail.Product.CategoryId.Value - 1] += orderDetail.Quantity.Value;
            }

            int tmp = 0;

            foreach (Circle circle in circles)
            {
                circle.SoldQuantity          = c[tmp];
                _context.Entry(circle).State = EntityState.Modified;
                tmp++;
            }

            await _context.SaveChangesAsync();



            return(await _context.Circle.Include(c => c.Category).ToListAsync());
        }
コード例 #11
0
        public async Task <ActionResult <Customer> > Excute()
        {
            var      _context = new TGDDContext();
            Customer customer = _context.Customers.FirstOrDefault(customer => customer.UserName == Username);

            if (customer == null)
            {
                return(BadRequest());
            }
            else
            {
                customer.Password = SecurityUtils.CreateMD5(Password);

                _context.Entry(customer).State = EntityState.Modified;
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                bool customerExist = _context.Customers.Any(c => c.Id == customer.Id);
                if (!customerExist)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(Ok());
        }
コード例 #12
0
        public async Task <ActionResult <Product> > Excute()
        {
            AssigndataUtils AssigndataUtils = new AssigndataUtils();
            var             _context        = new TGDDContext();

            Product newProduct = await AssigndataUtils.AssignProduct(productDTO, 0);

            _context.Products.Add(newProduct);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                bool productExist = _context.Products.Any(p => p.Id == newProduct.Id);
                if (productExist)
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }
            return(CreatedAtAction("GetProducts", new { id = newProduct.Id }, newProduct));
        }
コード例 #13
0
        public async Task <IActionResult> Excute()
        {
            //if (id != comments.Id)
            //{
            //    return BadRequest();
            //}
            AssigndataUtils AssigndataUtils = new AssigndataUtils();

            var _context = new TGDDContext();

            Comment comment = AssigndataUtils.AssignComment(CommentDTO, CommentId);

            _context.Entry(comment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                bool commentExist = _context.Comments.Any(e => e.Id == CommentId);
                if (!commentExist)
                {
                    return(NotFound("Không tìm thấy comment!"));
                }
                else
                {
                    throw;
                }
            }
            return(Ok("Chỉnh sửa thành công !"));
        }
コード例 #14
0
        public async Task <ActionResult <Voucher> > Excute()
        {
            AssigndataUtils AssigndataUtils = new AssigndataUtils();

            Voucher newVoucher = AssigndataUtils.AssignVoucher(voucherDTO, 0);

            var _context = new TGDDContext();

            _context.Vouchers.Add(newVoucher);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                bool voucherExist = _context.Vouchers.Any(voucher => voucher.Id == newVoucher.Id);

                if (voucherExist)
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }
            return(CreatedAtAction("GetVoucher", new { id = newVoucher.Id }, newVoucher));
        }
コード例 #15
0
        public async Task <IActionResult> Excute()
        {
            var _context = new TGDDContext();
            var contact  = await _context.Contacts.FindAsync(ContactId);

            contact.IsReply = true;

            _context.Entry(contact).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                bool contactExist = _context.Contacts.Any(c => c.Id == ContactId);
                if (!contactExist)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #16
0
        public async Task <ActionResult> Excute()
        {
            var _context = new TGDDContext();

            Customer customer = await _context.Customers.FindAsync(CustomerId);

            customer.Password = SecurityUtils.CreateMD5(NewPassword);

            //OldPassword = SecurityUtils.CreateMD5(OldPassword);

            //if(OldPassword == customer.Password)
            //{
            //    customer.Password = SecurityUtils.CreateMD5(NewPassword);
            //}
            //else
            //{
            //    return BadRequest("Mật khẩu hiện tại không đúng !");
            //}

            _context.Entry(customer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch
            {
                throw;
            };

            return(Ok("Đổi mật khẩu thành công !"));
        }
コード例 #17
0
        public async Task <ActionResult <Customer> > Excute()
        {
            var _context = new TGDDContext();

            var newCustomerId = _context.Customers.Max(c => c.Id) + 1;

            Customer.Id       = newCustomerId;
            Customer.Password = SecurityUtils.CreateMD5(Customer.Password);

            _context.Customers.Add(Customer);
            try
            {
                await _context.SaveChangesAsync();

                {
                    MailClass mailClass = GetMailObject(Customer);
                    await _mailService.SendMail(mailClass);
                }
            }
            catch (DbUpdateException)
            {
                bool customerExist = _context.Customers.Any(c => c.Id == Customer.Id);
                if (customerExist)
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }
            return(CreatedAtAction("GetCustomers", new { id = Customer.Id }, Customer));
        }
コード例 #18
0
        public async Task <ActionResult <Image> > Excute()
        {
            var _context = new TGDDContext();
            var images   = _context.Images.Where(image => image.ProductId == ProductId).ToList();

            if (images.Count < 1)
            {
                return(NotFound());
            }
            else
            {
                foreach (Image img in images)
                {
                    _context.Images.Remove(img);
                }
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch
            {
                return(BadRequest("Đã xảy ra lỗi"));
            }

            return(Ok());
        }
コード例 #19
0
        public async Task <IActionResult> Excute()
        {
            var _context = new TGDDContext();

            Customer customer = _context.Customers.Where(customer => customer.UserName == Username).FirstOrDefault();

            if (customer == null)
            {
                return(BadRequest("Không tìm thấy tài khoản!"));
            }

            if (customer.Password == Pw)
            {
                customer.Verified = true;

                _context.Entry(customer).State = EntityState.Modified;
                try
                {
                    await _context.SaveChangesAsync();
                }
                catch
                {
                    return(BadRequest());
                }
            }
            else
            {
                return(BadRequest());
            }
            return(Ok("Xác thực thành công !"));
        }
コード例 #20
0
        public async Task <IActionResult> Excute()
        {
            AssigndataUtils AssigndataUtils = new AssigndataUtils();

            var _context = new TGDDContext();
            var order    = new Order();

            order = await AssigndataUtils.AssignOrder(OrderDTO, Id);

            if (order.StatusId == 4)
            {
                ProductsAutoUpdate productsAutoUpdate = new ProductsAutoUpdate();
                List <OrderDetail> orderDetails       = order.OrderDetails.ToList();
                foreach (OrderDetail orderDetail in orderDetails)
                {
                    Product product = await _context.Products.FindAsync(orderDetail.ProductId);

                    product.BuyingTimes -= orderDetail.Quantity;
                    product.Stock       += orderDetail.Quantity;

                    _context.Entry(product).State = EntityState.Modified;
                }
                await _context.SaveChangesAsync();
            }

            _context.Entry(order).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                bool orderExist = _context.Orders.Any(o => o.Id == order.Id);
                if (!orderExist)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok("Cập nhật thành công !"));
        }
コード例 #21
0
        public async Task <ActionResult <IEnumerable <TopProduct> > > GetTopProducts()
        {
            List <long> productId = await _context.Products.OrderByDescending(p => p.BuyingTimes).Select(p => p.Id).Take(10).ToListAsync();

            List <TopProduct> topProducts = await _context.TopProducts.ToListAsync();

            int tmp = 0;

            foreach (TopProduct topProduct in topProducts)
            {
                topProduct.ProductId             = productId[tmp];
                _context.Entry(topProduct).State = EntityState.Modified;
                tmp++;
            }

            await _context.SaveChangesAsync();

            return(await _context.TopProducts.Include(top => top.Product).ThenInclude(p => p.Images).ToListAsync());
        }
コード例 #22
0
ファイル: VoucherUse.cs プロジェクト: minhlnd0302/API_NetCore
        public async Task <ActionResult <UseVoucher> > Excute()
        {
            var _context = new TGDDContext();

            Voucher voucher = _context.Vouchers.FirstOrDefault(voucher => voucher.Code == UserVoucherDTO.CodeVoucher);

            if (voucher == null)
            {
                return(NotFound("Voucher khồn tồn tại"));
            }
            else
            {
                DateTime date = DateTime.Now;

                if (date < voucher.StartDate && date > voucher.EndDate)
                {
                    return(NotFound("Voucher đã hết hạn"));
                }
                //UseVoucher useVoucher = _context.UseVouchers.FirstOrDefault(useVoucher.VoucherId == voucher.Id && useVoucher.CustomerId == UserVoucherDTO.CustomerId);

                UseVoucher useVoucher = _context.UseVouchers.Where(useVoucher => useVoucher.VoucherId == voucher.Id && useVoucher.CustomerId == UserVoucherDTO.CustomerId).FirstOrDefault();

                if (useVoucher == null)
                {
                    long newId = _context.UseVouchers.Max(useVoucher => useVoucher.Id) + 1;

                    useVoucher = new UseVoucher
                    {
                        Id         = newId,
                        CustomerId = UserVoucherDTO.CustomerId,
                        Used       = true,
                        VoucherId  = voucher.Id,
                        Voucher    = voucher,
                    };

                    _context.UseVouchers.Add(useVoucher);

                    try
                    {
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateException)
                    {
                        throw;
                    }
                }
                else
                {
                    return(NotFound("Voucher đã được sử dụng !"));
                };
            }
            return(Ok());
        }
コード例 #23
0
        public async void newYear(Order order, TGDDContext _context, int year)
        {
            long newYearId = _context.YearStatisticals.Max(YearStatistical => YearStatistical.Id) + 1;

            YearStatistical yearStatistica = new YearStatistical
            {
                Id        = newYearId,
                TotalYear = order.Total,
                Year      = year,
            };

            _context.YearStatisticals.Add(yearStatistica);
            await _context.SaveChangesAsync();
        }
コード例 #24
0
        public void UpdateQuantity(long ProductId, int Quantity)
        {
            var     _context = new TGDDContext();
            Product product  = _context.Products.Find(ProductId);

            if (product != null)
            {
                product.Stock       -= Quantity;
                product.BuyingTimes += Quantity;
            }
            _context.Entry(product).State = EntityState.Modified;

            _context.SaveChangesAsync();
        }
コード例 #25
0
        public async void newMonth(Order order, TGDDContext _context, long yeaId, int month)
        {
            long             newMonthId       = _context.YearStatisticals.Max(y => y.Id) + 1;
            MonthStatistical monthStatistical = new MonthStatistical
            {
                Id         = newMonthId,
                YearId     = yeaId,
                TotalMonth = order.Total,
                Month      = month
            };

            _context.MonthStatisticals.Add(monthStatistical);
            await _context.SaveChangesAsync();
        }
コード例 #26
0
        public async Task <ActionResult <Contact> > DeleteContact(long id)
        {
            var contact = await _context.Contacts.FindAsync(id);

            if (contact == null)
            {
                return(NotFound());
            }

            _context.Contacts.Remove(contact);
            await _context.SaveChangesAsync();

            return(contact);
        }
コード例 #27
0
        public async Task <ActionResult <Product> > Excute()
        {
            var _context = new TGDDContext();
            var products = await _context.Products.FindAsync(ProductId);

            if (products == null)
            {
                return(NotFound("Không tìm thấy sản phẩm !"));
            }

            _context.Products.Remove(products);
            await _context.SaveChangesAsync();

            return(Ok("Xóa sản phẩm thành công !"));
        }
コード例 #28
0
        public async Task <ActionResult <Customer> > DeleteCustomers(long id)
        {
            var _context = new TGDDContext();
            var customer = await _context.Customers.FindAsync(id);

            if (customer == null)
            {
                return(NotFound());
            }

            _context.Customers.Remove(customer);
            await _context.SaveChangesAsync();

            return(customer);
        }
コード例 #29
0
        public async Task <ActionResult <Notification> > Excute()
        {
            var _context     = new TGDDContext();
            var notification = await _context.Notifications.FindAsync(NotificationId);

            if (notification == null)
            {
                return(NotFound());
            }

            _context.Notifications.Remove(notification);
            await _context.SaveChangesAsync();

            return(notification);
        }
コード例 #30
0
        public async Task <ActionResult <Voucher> > Excute()
        {
            var _context = new TGDDContext();

            var voucher = await _context.Vouchers.FindAsync(VoucherId);

            if (voucher == null)
            {
                return(NotFound());
            }

            _context.Vouchers.Remove(voucher);
            await _context.SaveChangesAsync();

            return(voucher);
        }