コード例 #1
0
        public ActionResult Save(ClientsViewModel form)
        {
            System.Threading.Thread.Sleep(2500);

            if (!ModelState.IsValid)
            {
                return(View(nameof(Index), form));
            }

            using (var context = new SalesEntities())
            {
                if (form.Id != 0)
                {
                    var clientToUpdate = context.Clients.SingleOrDefault(e => e.Id == form.Id);
                    clientToUpdate.Email     = form.Email;
                    clientToUpdate.FirstName = form.FirstName;
                    clientToUpdate.LastName  = form.LastName;
                    clientToUpdate.Discount  = form.Discount;
                }
                else
                {
                    Clients entity = new Clients(form);
                    context.Clients.Add(entity);
                }

                context.SaveChanges();
            }

            TempData["Success"] = true;
            return(Redirect(nameof(Index)));
        }
コード例 #2
0
        // GET: Users
        public ActionResult Index(int id = 0)
        {
            ViewBag.Header = "Lista de Clientes";

            if (TempData.ContainsKey("Success"))
            {
                TempData.Remove("Success");
                ViewBag.Success = true;
            }

            ClientsViewModel clientsViewModel = null;

            if (id != 0)
            {
                using (var context = new SalesEntities())
                {
                    var resultClient = context.Clients.SingleOrDefault(e => e.Id == id);
                    clientsViewModel = new ClientsViewModel(resultClient);
                }
            }
            else
            {
                clientsViewModel = new ClientsViewModel();
            }

            return(View(clientsViewModel));
        }
コード例 #3
0
 /// <summary> Populates <see cref="Values"/> from the data service. </summary>
 /// <param name="dataClient"></param>
 internal static void PopulateValues(SalesEntities dataClient)
 {
     if (Values == null)
     {
         Values = dataClient.PhoneNumberTypes.ToList();
     }
 }
コード例 #4
0
        public void RunVariousQueriesForProfiling()
        {
            var context = new SalesEntities();

            //simple query
            (from c in context.Customers select c).ToList();

            //query with variable parameter
            string sort = "Robert";

            (from c in context.Customers orderby c.LastName where c.FirstName == sort select c).ToList();

            //query with hard coded parameter
            (from c in context.Customers orderby c.LastName where c.FirstName == "Robert" select c).ToList();

            //Entity SQL via Query Builder Methods
            context.Customers.OrderBy("it.LastName").Where("it.FirstName='Robert'").ToList();

            //Entity SQL with forced parameters
            var query          = context.CreateQuery <Customer>("SELECT VALUE c FROM SalesEntities.Customers AS c WHERE c.FirstName=@fn");
            var whereParameter = new ObjectParameter("fn", "Robert");

            query.Parameters.Add(whereParameter);
            query.ToList();

            //sql injection with LINQ to Entities?
            sort = "John';EXEC sys.sp_helpuser--";
            (from c in context.Customers orderby c.LastName where c.FirstName == sort select c).ToList();

            //sql injection with Entity SQL?
            sort = "John';EXEC sys.sp_helpuser--";
            var esql = "it.FirstName=" + sort;

            context.Customers.Where(esql).ToList();
        }
        public void ReturnsASingleCustomer()
        {
            var   context = new SalesEntities();
            Order order   = (from o in context.Orders orderby o.SubTotal descending select o).SingleOrDefault();

            Assert.IsNotNull(order);
        }
コード例 #6
0
        public MainWindow()
        {
            InitializeComponent();

            //_now = DateTime.Now;
            _now      = DateTime.Now;
            _today    = new DateTime(_now.Year, _now.Month, _now.Day, 0, 0, 0);
            _tomorrow = _today.AddDays(3);
            comboName.IsTextSearchEnabled = false;

            using (var context = new SalesEntities())
            {
                _orderItems = context.SaleItems.Where(x => x.Active).ToList();
                _dates      = context.EventDates.Where(x => x.Date >= DateTime.Now).Select(x => x.Date).OrderBy(x => x).ToList();
                _times      = context.EventDates.Where(x => x.Active).Select(x => x.Date).OrderBy(x => x).ToList();
                context.Database.ExecuteSqlCommand("UPDATE TicketSales Set Name=UPPER(NAME) WHERE Name<>UPPER(NAME) COLLATE Latin1_General_CS_AS ");
            }

            string[] args = Environment.GetCommandLineArgs();
            _programState = ProgramState.EventDay;
            if (args.Contains("presale"))
            {
                _programState         = ProgramState.Presale;
                groupToGo.Visibility  = Visibility.Collapsed;
                groupNotes.Visibility = Visibility.Collapsed;
            }
        }
コード例 #7
0
        private void comboName_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (comboName.SelectedValue == null || string.IsNullOrEmpty(comboName.SelectedValue.ToString()))
            {
                return;
            }

            if (comboName.SelectedIndex < 0)
            {
                return;
            }

            var text        = comboName.SelectedValue.ToString();
            var orderNumber = "";

            using (var context = new SalesEntities())
            {
                var sale = context.TicketSales.ToList()
                           .FirstOrDefault(
                    x =>
                    x.EventDate >= _today && x.EventDate <= _tomorrow && text == SaleToDropdownText(x) && x.IsValid &&
                    !x.IsFulfilled);


                if (sale != null)
                {
                    orderNumber = sale.OrderNumber;
                }
            }
            LoadDataFromOrderNumber(orderNumber);
        }
コード例 #8
0
        private DateTime GetEventDate()
        {
            DateTime results = DateTime.Now;
            var      now     = DateTime.Now;

            try
            {
                using (var context = new SalesEntities())
                {
                    var eventDates = context.EventDates.OrderBy(x => x.Date).ToList();
                    var lastDate   = eventDates.FirstOrDefault(x => x.Date >= now.AddMinutes(-30) && x.Date <= now);
                    if (lastDate != null)
                    {
                        results = lastDate.Date;
                    }
                    else
                    {
                        var nextDate = eventDates.FirstOrDefault(x => x.Date >= now);
                        if (nextDate != null)
                        {
                            results = nextDate.Date;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(results);
        }
コード例 #9
0
        private void btnPrintReport_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var context = new SalesEntities())
                {
                    var salesItems    = context.SaleItems.ToList();
                    var ticketSales   = context.TicketSales.ToList();
                    var ticketDetails = context.TicketDetails.ToList();
                    var eventDates    = context.EventDates.ToList();

                    var backup = new Backup()
                    {
                        EventDates    = eventDates,
                        SaleItems     = salesItems,
                        TicketDetails = ticketDetails,
                        TicketSales   = ticketSales
                    };
                    BackupData(backup);

                    var reportsWindow = new ReportsWindow(context);
                    reportsWindow.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #10
0
        public void QueryingWithNavigationProperties()
        {
            var context = new SalesEntities();


            //var query = from c in context.Customers
            //            where c.Orders.Sum(o => o.SubTotal) > 10000
            //            from o in c.Orders
            //            select new { c.Company, Orders = o };

            ////par navegar entre la informacion
            var orders = (from o in context.Orders
                          where o.Customer.SalesPerson == "linda3"
                          select new { o.SalesOrderNumber, o.Customer.Company }).ToList();
            //aqui lo que estoy haciendo es que cogo los customers y le digo que las ordenes de se customers haga una suma
            //de todos los subtotales que pertenecen a ese customer sumelos osea haga un total final y luego lo compara
            //si es mayor que 1000 y crea un objeto anomimo que tiene los campos company y orders
            //hace que la consulta se anidada y que sea mas limpia en sql (from o in c.Orders)
            //esto me da una sola orden no una coleccion de ordenes
            var query2 = from c in context.Customers
                         where c.Orders.Sum(o => o.SubTotal) > 1000
                         from o in c.Orders
                         select new { c.Company, o };

            var query = from c in context.Customers
                        where c.Orders.Any()
                        select new { c.Company, Orders = c.Orders };
            var customers = query.ToList();
        }
コード例 #11
0
 public ActionResult TableResult()
 {
     using (var context = new SalesEntities())
     {
         var result = context.Search(string.Empty, true).ToList();
         return(PartialView(result));
     }
 }
コード例 #12
0
 public ActionResult List()
 {
     using (var context = new SalesEntities())
     {
         var Clients = context.Clients.ToList();
         return(PartialView("List.Partial", Clients));
     }
 }
        public void GroupedQueries()
        {
            var context = new SalesEntities();

            var query = from o in context.Orders
                        group o by o.DueDate
                        into mygroupedorders
                        select mygroupedorders;
        }
        public void GetObjectByKeyReturnsAnObject()
        {
            var    context = new SalesEntities();
            var    key     = new EntityKey("SalesEntities.Customers", "CustomerID", 16);
            object customer;

            Assert.IsTrue(context.TryGetObjectByKey(key, out customer));
            Assert.IsInstanceOfType(customer, typeof(Customer));
        }
コード例 #15
0
        static IEnumerable <string> getTheUserListName()
        {
            var x = new List <string>();

            using (SalesEntities e = new SalesEntities())
            {
                x = e.customers.Where(m => m.currid == "EUR").Select(m => m.compname).ToList();
            }
            return(x);
        }
コード例 #16
0
        static currencies LiefereMirDieWährung(string lk)
        {
            currencies all;

            using (SalesEntities e = new SalesEntities())
            {
                all = e.currencies.Where(m => m.currid == lk).FirstOrDefault();
            }
            return(all);
        }
コード例 #17
0
        static List <currencies> LiefereMirAlleWährungen()
        {
            List <currencies> all;

            using (SalesEntities e = new SalesEntities())
            {
                all = e.currencies.Take(5).ToList();
            }
            return(all);
        }
コード例 #18
0
        static string getTheUserName()
        {
            string x = string.Empty;

            using (SalesEntities e = new SalesEntities())
            {
                x = e.customers.Where(m => m.currid == "EUR").Select(m => m.compname).FirstOrDefault();
            }
            return(x);
        }
コード例 #19
0
        public JsonResult GetSalesOrderDetailerRecords(JQGridSettings JQGrid)
        {
            int TotapPages   = 0;
            int TotalRecords = 0;

            int SalesOrderID = int.Parse(Request.QueryString["SalesOrderID"]);

            IEnumerable <SalesOrderDetail> SOHIE = null;
            IQueryable <SalesOrderDetail>  SOHIQ = null;

            using (SalesEntities DB = new SalesEntities())
            {
                DB.Configuration.LazyLoadingEnabled   = false;
                DB.Configuration.ProxyCreationEnabled = false;

                SOHIQ = DB.SalesOrderDetails.AsQueryable().Where(d => d.SalesOrderID == SalesOrderID).Select(d => d);

                #region :::Soring-Searching:::
                if (JQGrid._search)
                {
                    JQGridFilters _filters = JsonConvert.DeserializeObject <JQGridFilters>(JQGrid.filters);
                    SOHIQ = SOHIQ.JQGridToolBarSearch(_filters);
                }
                else
                {
                    SOHIQ = SOHIQ.JQGridSorting(JQGrid.sidx, JQGrid.sord);
                }
                #endregion

                #region :::Pagination
                SOHIE = SOHIQ.AsEnumerable();
                try
                {
                    TotapPages   = Convert.ToInt32(Math.Ceiling((double)SOHIE.Count() / (double)JQGrid.rows));
                    TotalRecords = SOHIE.Count();
                    SOHIE        = SOHIE.Skip((JQGrid.page - 1) * JQGrid.rows).Take(JQGrid.rows).ToList();
                }
                catch (Exception e)
                {
                    throw;
                }
                #endregion
            }

            var jsonReader = new
            {
                root    = SOHIE,
                page    = JQGrid.page,
                total   = TotapPages,
                records = TotalRecords
            };


            return(Json(jsonReader, JsonRequestBehavior.AllowGet));
        }
コード例 #20
0
        static List <string> getTheUserListNameList()
        {
            List <string> x = null;

            using (SalesEntities e = new SalesEntities())
            {
                x = new List <string>();
                x = e.customers.Where(m => m.currid == "EUR").Select(m => m.compname).DefaultIfEmpty().ToList();
            }
            return(x);
        }
コード例 #21
0
        static List <customers> LiefereMirAlleKunden()
        {
            List <customers> all = null;

            using (SalesEntities e = new SalesEntities())
            {
                all = new List <customers>();
                all = e.customers.ToList();
            }
            return(all);
        }
コード例 #22
0
        public void GetSomeCustomers()
        {
            var context   = new SalesEntities();
            var query     = from c in context.Customers orderby c.LastName where c.FirstName == "Robert" select c;
            var customers = query.ToList();

            foreach (var cust in customers)
            {
                Debug.WriteLine(cust.LastName.Trim() + ", " + cust.FirstName);
            }
        }
コード例 #23
0
        public void GetSomeCustomersUsingLinqMethod()
        {
            var context   = new SalesEntities();
            var query     = context.Customers.OrderBy(c => c.LastName).Where(c => c.FirstName == "Robert");
            var customers = query.ToList();

            foreach (var cust in customers)
            {
                Debug.WriteLine(cust.LastName.Trim() + ", " + cust.FirstName);
            }
        }
        private List <MiniCustomer> ExploreQueryProjections()
        {
            var context = new SalesEntities();
            var query   = from c in context.Customers select new MiniCustomer {
                FirstName = c.FirstName, LastName = c.LastName, CustomerID = c.CustomerID
            };

            return(query.ToList());
            //foreach (var whatever in query)
            //  Debug.WriteLine(whatever.FirstName.Trim() + ' ' + whatever.LastName);
        }
コード例 #25
0
        static void ConsumingWCFDataServices()
        {
            SalesEntities entities = new SalesEntities(new Uri("http://localhost:50434/WcfDataService1.svc/"));

            var products = entities.Products.ToList();


            foreach (var product in products)
            {
                Console.WriteLine("Id: {0}, Name: {1}, Price: {2}", product.ProductID, product.ProductName, product.ProductPrice);
            }
        }
コード例 #26
0
        static IEnumerable <Name> GetAllCustomers()
        {
            var y = new List <Name>();

            using (SalesEntities e = new SalesEntities())
            {
                y = e.customers.Select(s => new Name {
                    Countryname = s.compname, ID = (int)s.custid
                }).ToList();
            }
            return(y);
        }
コード例 #27
0
        public async Task <ActionResult> DeleteAsync(int id)
        {
            using (var context = new SalesEntities())
            {
                var clientDelete = await context.Clients.SingleOrDefaultAsync(e => e.Id == id);

                context.Clients.Remove(clientDelete);
                await context.SaveChangesAsync();
            }

            return(Redirect(nameof(Index)));
        }
コード例 #28
0
        public ActionResult Index(int?page, DateTime?filterDateSaleFrom, DateTime?filterDateSaleTo, int?filterUser, int?filterProduct, int?filterSalary)
        {
            int         pageSize   = 20;
            int         pageNumber = (page ?? 1);
            List <Sale> sales      = SalesEntities.GetSales(filterDateSaleFrom, filterDateSaleTo, filterUser, filterProduct, filterSalary);

            ViewBag.Products = new SelectList(ListsForFilters.Products, "Id", "Name");
            ViewBag.Users    = new SelectList(ListsForFilters.Users, "Id", "Login");
            ViewBag.ACC      = new SelectList(ListsForFilters.ACC, "Value", "Text");

            return(View(sales.OrderByDescending(d => d.SaleDate).ThenByDescending(d => d.CreateDate).ToPagedList(pageNumber, pageSize)));
        }
コード例 #29
0
        public void GetSomeCustomersUsingESQLRawQuerying()
        {
            var context = new SalesEntities(); //I needed this in the test, but you shouldn't need it in regular code

            using (var conn = new EntityConnection("name=SalesEntities"))
            {
                conn.Open();
                EntityCommand cmd = conn.CreateCommand();
                cmd.CommandText = "SELECT VALUE c FROM SalesEntities.Customers AS c " +
                                  "WHERE c.FirstName='Robert' ORDER BY c.LastName";
                EntityDataReader rdr = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.CloseConnection);
            }
        }
コード例 #30
0
        public ActionResult DeleteCustomer(int customerId)
        {
            using (SalesEntities entities = new SalesEntities())
            {
                Sell Sale = (from c in entities.Sells
                             where c.CustomerId == customerId
                             select c).FirstOrDefault();
                entities.Sells.Remove(Sale);
                entities.SaveChanges();
            }

            return(new EmptyResult());
        }