Example #1
0
        private Sales_new GetListForSales(Sales_new s)
        {
            List <Customer> cust = db.Customer.ToList();

            foreach (var c in cust)
            {
                string cname = c.Name;

                s.custNames.Add(cname);
            }


            List <Product> prod = db.Product.ToList();

            foreach (var c in prod)
            {
                string cname = c.Name;
                s.prodNames.Add(cname);
            }

            List <Store> st = db.Store.ToList();

            foreach (var c in st)
            {
                string cname = c.Name;
                s.storeNames.Add(cname);
            }

            return(s);
        }
Example #2
0
        public Sales_new GetSaleInfo()
        {
            Sales_new s = new Sales_new();

            GetListForSales(s);
            return(s);
        }
Example #3
0
        public Sales_new GetSalesData(int id)
        {
            //we need to get current data along with custname,storename and productname

            try
            {
                Sales sale = db.Sales.Find(id);

                Sales_new s = new Sales_new();
                s = GetListForSales(s);
                // int custId = sale.Customerid;
                int prodId = sale.Productid;
                s.Storename    = db.Store.Find(sale.Storeid).Name;
                s.Customername = db.Customer.Find(sale.Customerid).Name;
                s.Productname  = db.Product.Find(sale.Productid).Name;
                s.Id           = sale.Id;
                s.DateSold     = sale.DateSold.ToShortDateString();

                //we need to add allcustnames and add all prodnames and all storenames



                // s.store= db.Store.ToList();
                // s.customer = db.Customer.ToList();
                // s.product = db.Product.ToList();

                return(s);
            }
            catch
            {
                throw;
            }
        }
Example #4
0
        public IEnumerable <Sales_new> GetAllSales()
        {
            try
            {
                // return db.Sales.ToList();
                List <Sales>     sales     = db.Sales.ToList();
                List <Sales_new> sales_new = new List <Sales_new>();


                foreach (var sale in sales)
                {
                    Sales_new s = new Sales_new();
                    // int custId = sale.Customerid;
                    int prodId = sale.Productid;
                    s.Storename    = db.Store.Find(sale.Storeid).Name;
                    s.Customername = db.Customer.Find(sale.Customerid).Name;
                    s.Productname  = db.Product.Find(sale.Productid).Name;
                    s.Id           = sale.Id;

                    s.DateSold = sale.DateSold.ToShortDateString();
                    sales_new.Add(s);
                }

                return(sales_new);
            }
            catch
            {
                throw;
            }
        }
Example #5
0
 public int AddSales(Sales_new sales_new)
 {
     try
     {
         Sales sale = invokeSale(sales_new);
         db.Sales.Add(sale);
         db.SaveChanges();
         return(1);
     }
     catch
     {
         throw;
     }
 }
Example #6
0
        /*
         * id: this.state.salesdata.id,
         *      Productname: this.state.salesdata.productname,
         *      Customername: this.state.salesdata.customername,
         *      Storename: this.state.salesdata.storename,
         *      DateSold: this.state.salesdata.dateSold
         */



        public int UpdateSales(Sales_new sales)
        {
            try
            {
                Sales sale = invokeSale(sales);

                sale.Id = sales.Id;
                db.Entry(sale).State = Microsoft.EntityFrameworkCore.EntityState.Modified;

                db.SaveChanges();
                return(1);
            }
            catch
            {
                throw;
            }
        }
Example #7
0
        private Sales invokeSale(Sales_new s)
        {
            CultureInfo provider = CultureInfo.InvariantCulture;
            Sales       sale     = new Sales();

            //add custid and prod id and store id to this


            //var id = (from b in db.Store
            //              where b.Name == sales.Storename
            //            select b.Id).FirstOrDefault();
            sale.Storeid    = db.Store.First(a => a.Name == s.Storename).Id;
            sale.Productid  = db.Product.First(a => a.Name == s.Productname).Id;
            sale.Customerid = db.Customer.First(a => a.Name == s.Customername).Id;

            //db.Store.Where(b => b.Name == sales.Storename).);
            //sale.Storeid= db.Store.Find(sales.Storename).Id;
            // sale.Customerid = db.Customer.Find(sales.Customername).Id;
            // sale.Productid = db.Product.Find(sales.Productname).Id;
            sale.DateSold = DateTime.Parse(s.DateSold);

            return(sale);
        }