Пример #1
0
        public BillSell CreateBillSell(Employe employe, Customer customer = null, Tables table = null)
        {
            if (customer == null && !table.status)
            {
                CustomerService cust      = new CustomerService(_context);
                var             _customer = cust.GetCustomer(Constants.Constants.customerDefault);

                BillSell billSell = new BillSell()
                {
                    createDate = DateTime.Now,
                    totalMoney = 0,
                    status     = false,
                };
                UserService userService = new UserService(_context);
                billSell.Employe = userService.GetUser(employe);
                TableService tableService = new TableService(_context);
                billSell.Table = tableService.GetTables(table);
                _context.Entry(billSell);
                _context.BillSells.Attach(billSell);

                _context.BillSells.Add(billSell);
                _context.SaveChanges();

                tableService.SetStatusTable(table, true);
                return(billSell);
            }
            return(null);
        }
Пример #2
0
 public bool SetStatusTable(Tables tables, bool status)
 {
     try
     {
         var table = _context.Tables.FirstOrDefault(x => x.Id == tables.Id);
         table.status = status;
         _context.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
     }
     return(false);
 }
Пример #3
0
        //public List<string> GetAllNameString()
        //{
        //    return _context.Offices.Select(x => x.nameOffice).ToList();
        //}

        public bool Insert(string name)
        {
            var off = _context.Offices.Where(x => x.nameOffice == name).SingleOrDefault();

            if (off == null)
            {
                Office _off = new Office {
                    nameOffice = name, createdDay = DateTime.Now, updatedDay = DateTime.Now
                };
                _context.Offices.Add(_off);
                _context.SaveChanges();
                return(true);
            }
            return(false);
        }
Пример #4
0
 public bool Delete(string Id)
 {
     try
     {
         Guid _id = new Guid(Id);
         var  sup = _context.Suppliers.Where(x => x.Id == _id).SingleOrDefault();
         if (sup == null)
         {
             return(false);
         }
         _context.Suppliers.Remove(sup);
         _context.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
     }
     return(false);
 }
Пример #5
0
        public bool updateArea(object are)
        {
            try
            {
                List <Area> areas = are as List <Area>;
                foreach (Area item in areas)
                {
                    var some = _context.Areas.Where(x => x.Id == item.Id).SingleOrDefault();
                    some.nameArea = item.nameArea;
                    some.Note     = item.Note;
                    _context.SaveChanges();
                }
                return(true);
            }
            catch (Exception)
            {
            }

            return(false);
        }
Пример #6
0
        public DetailBillSell CreateDetailBillSell(BillSell billSell, Product product, int number)
        {
            DetailBillSell detailBillSell = new DetailBillSell
            {
                Quantum = number,
                Total   = product.priceProduct * number,
            };
            ProductService productService = new ProductService(_context);

            detailBillSell.Product = productService.GetProduct(product);
            BillSellService billSellService = new BillSellService(_context);

            detailBillSell.BillSells = new List <BillSell>()
            {
                billSellService.GetBillWithId(billSell.Id)
            };
            _context.DetailBillSells.Add(detailBillSell);
            _context.SaveChanges();
            return(detailBillSell);
        }
        public bool Delete(string Id)
        {
            try
            {
                Guid _id = new Guid(Id);

                var product = _context.Products.Where(x => x.Id == _id).Include(x => x.Unit).Include(x => x.ProductType).SingleOrDefault();
                if (product == null)
                {
                    return(false);
                }
                _context.Products.Remove(product);
                _context.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
            }
            return(false);
        }
        public bool Update(object tables)
        {
            try
            {
                DataTable dataTable = new DataTable();
                dataTable.Clear();
                dataTable.Columns.Add("Id", typeof(string));
                dataTable.Columns.Add("userName", typeof(string));
                dataTable.Columns.Add("password", typeof(string));
                dataTable.Columns.Add("fullName", typeof(string));
                dataTable.Columns.Add("sex", typeof(bool));
                dataTable.Columns.Add("birthDay", typeof(string));
                dataTable.Columns.Add("address", typeof(string));
                dataTable.Columns.Add("phoneNumber", typeof(string));
                dataTable.Columns.Add("email", typeof(string));
                dataTable.Columns.Add("dayAtWork", typeof(string));
                dataTable.Columns.Add("statusOfWork", typeof(bool));
                dataTable.Columns.Add("nameOffice", typeof(string));

                OfficeService officeService = new OfficeService(_context);

                dataTable = tables as DataTable;
                int i = 0;
                foreach (DataRow item in dataTable.Rows)
                {
                    Guid     Id           = new Guid(item.Table.Rows[i]["Id"].ToString());
                    string   username     = item.Table.Rows[i]["userName"].ToString();
                    string   password     = item.Table.Rows[i]["password"].ToString();
                    string   fullName     = item.Table.Rows[i]["fullName"].ToString();
                    bool     sex          = (bool)item.Table.Rows[i]["sex"];
                    DateTime birthDay     = Convert.ToDateTime(item.Table.Rows[i]["birthDay"].ToString());
                    string   address      = item.Table.Rows[i]["address"].ToString();
                    string   phoneNumber  = item.Table.Rows[i]["phoneNumber"].ToString();
                    string   email        = item.Table.Rows[i]["email"].ToString();
                    DateTime dayAtWork    = Convert.ToDateTime(item.Table.Rows[i]["dayAtWork"].ToString());
                    bool     statusOfWork = (bool)(item.Table.Rows[i]["statusOfWork"]);
                    string   nameOffice   = item.Table.Rows[i]["nameOffice"].ToString();

                    Office off = officeService.GetOffice(nameOffice);
                    if (off != null)
                    {
                        var user = _context.Employes.Where(x => x.Id == Id).Include(x => x.Offices).SingleOrDefault();
                        user.userName = username;
                        if (user.password != password)
                        {
                            user.password = GenerateHash.Instance.ComputeSha256Hash(password);
                        }
                        user.fullName     = fullName;
                        user.sex          = sex;
                        user.birthDay     = birthDay;
                        user.address      = address;
                        user.phoneNumber  = phoneNumber;
                        user.email        = email;
                        user.dayAtWork    = dayAtWork;
                        user.statusOfWork = statusOfWork;
                        user.Offices      = off;
                        _context.SaveChanges();
                    }
                    i++;
                }
                return(true);
            }
            catch (Exception)
            {
            }
            return(false);
        }