Ejemplo n.º 1
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());
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
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 !"));
        }
Ejemplo n.º 5
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 !"));
        }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
0
        public async Task <Customer> SignUp(Customer oCustomer)
        {
            var _context = new TGDDContext();


            _oCustomer = new Customer();

            try
            {
                Customer customer = await this.CheckRecordExistence(oCustomer);

                if (customer != null)
                {
                    var newCustomerId = _context.Customers.Max(p => p.Id) + 1;
                    oCustomer.Id = newCustomerId;

                    _context.Customers.Add(customer);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(oCustomer);
        }
Ejemplo n.º 9
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());
        }
Ejemplo n.º 10
0
        public async Task <ActionResult <IEnumerable <Contact> > > GetContacts()
        {
            var _context = new TGDDContext();

            List <Order> Orders = await _context.Orders.OrderBy(order => order.Date).ToListAsync();

            List <int> day   = new List <int>();
            List <int> month = new List <int>();
            List <int> year  = new List <int>();

            foreach (Order order in Orders)
            {
                day.Add(order.Date.Value.Day);
                month.Add(order.Date.Value.Month);
                year.Add(order.Date.Value.Year);
            }


            //for (int i = 0; i < 52; i++)
            //{

            //}


            var contactGetAll = new ContactGetAll();

            return(await contactGetAll.Excute());
        }
Ejemplo n.º 11
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 !"));
        }
Ejemplo n.º 12
0
        public async Task <ActionResult <IList <long?> > > Excute()
        {
            var _context = new TGDDContext();


            var p = await _context.Orders.ToListAsync();

            //Customer t = await _context.Customers.Where(c => c.Id == CustomerId).Include(customer => customer.Favorites).FirstOrDefaultAsync();
            //List<Favorite> f = t.Favorites.ToList();

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


            //IList<Favorite> favorites = await _context.Favorites.ToListAsync();

            //IList<Favorite> favorites = null;

            var productsId = new List <long?>();

            if (f.Count < 1)
            {
                return(NotFound("Không có sản phẩm yêu thích !"));
            }
            else
            {
                foreach (var item in f)
                {
                    productsId.Add(item.ProductId);
                }
            }
            return(productsId);
        }
Ejemplo n.º 13
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 !"));
        }
Ejemplo n.º 14
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));
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
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));
        }
Ejemplo n.º 17
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));
        }
Ejemplo n.º 18
0
 public LoginController(IConfiguration config, TGDDContext context)
 {
     _config  = config;
     _context = context;
     //AssigndataUtils._context = _context;
     SecurityUtils._context = _context;
     SecurityUtils._config  = config;
 }
Ejemplo n.º 19
0
        public static bool IsAdmin(TGDDContext _context, string username)
        {
            Admin admin = null;

            admin = _context.Admins.FirstOrDefault(a => a.UserName == username);

            return(admin != null ? true : false);
        }
Ejemplo n.º 20
0
        public async Task <ActionResult <IEnumerable <Comment> > > Excute()
        {
            var _context = new TGDDContext();

            var comments = _context.Comments.Include(c => c.Customer);


            return(await comments.ToListAsync());
        }
Ejemplo n.º 21
0
        public async Task <ActionResult <Order> > Excute()
        {
            var _context = new TGDDContext();
            var order    = await _context.Orders.FindAsync(OrderId);

            if (order == null)
            {
                return(NotFound("Không tìm thấy đơn hàng !"));
            }
            return(order);
        }
Ejemplo n.º 22
0
        public async Task <ActionResult <IEnumerable <Order> > > Excute()
        {
            var _context = new TGDDContext();

            var orders = _context.Orders.Include(o => o.OrderDetails).ThenInclude(d => d.Product)
                         .Include(o => o.Status)
                         .Include(o => o.Customer)
                         .Include(o => o.OrderDetails);

            return(await orders.ToListAsync());
        }
Ejemplo n.º 23
0
        public async Task <ActionResult <Voucher> > Excute()
        {
            var _context = new TGDDContext();
            var voucher  = await _context.Vouchers.FindAsync(VoucherId);

            if (voucher == null)
            {
                return(NotFound());
            }
            return(voucher);
        }
        public async Task <ActionResult <Customer> > Excute()
        {
            var      _context = new TGDDContext();
            Customer customer = _context.Customers.FirstOrDefault(c => c.UserName == Username);

            if (customer == null)
            {
                return(NotFound());
            }
            return(customer);
        }
Ejemplo n.º 25
0
        public async Task <ActionResult <Customer> > Excute()
        {
            var _context  = new TGDDContext();
            var customers = await _context.Customers.FindAsync(Id);

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

            return(customers);
        }
Ejemplo n.º 26
0
        public async Task <ActionResult <List <Comment> > > Excute()
        {
            var _context = new TGDDContext();

            List <Comment> comments = await _context.Comments.Where(c => c.ProductId == ProductId).ToListAsync();

            if (comments.Count < 1)
            {
                return(NotFound());
            }
            return(comments);
        }
Ejemplo n.º 27
0
        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());
        }
Ejemplo n.º 28
0
        public async Task <ActionResult <IEnumerable <Product> > > Excute()
        {
            var _context = new TGDDContext();

            var products = await _context.Products.Include(p => p.Descriptions)
                           .Include(p => p.Images)
                           .Include(p => p.Category)
                           .Include(p => p.Brand)
                           .Include(p => p.Comments)
                           .ToListAsync();

            return(products);
        }
Ejemplo n.º 29
0
        public async Task <Customer> FindAccount(string username)
        {
            var _context = new TGDDContext();

            Customer userinfo = await _context.Customers.FirstOrDefaultAsync(c => c.UserName == username);

            if (userinfo == null)
            {
                userinfo = await _context.Customers.FirstOrDefaultAsync(c => c.Email == username);
            }

            return(userinfo);
        }
Ejemplo n.º 30
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();
        }