No Metadata Documentation available.
Наследование: ObjectContext
        public ActionResult AjaxDeleteCustomer(int customerId)
        {
            try
            {
                var context = new SampleEntities();
                var customer = context.Customers.Single(c => c.ID == customerId);
                bool orders = customer.Orders.Any();

                if (orders)
                {
                    Response.StatusCode = 500;
                    Response.AppendHeader("message", "This customer has order history, and cannot be deleted until all orders are deleted.");
                }
                else
                {
                    context.Customers.DeleteObject(customer);
                    context.SaveChanges();
                }
            }
            catch (System.Exception e)
            {
                Response.StatusCode = 500;
                Response.AppendHeader("message", "There was an issue deleting this customer. Please contact tech support with this message: " + Utility.GetInnermostException(e).Message);
            }

            return View(new GridModel(GetCustomers()));
        }
        public ActionResult AjaxAddOrder(int customerId)
        {
            if (ModelState.IsValid)
            {
                var context = new SampleEntities();
                var customer = context.Customers.Single(c => c.ID == customerId);
                var order = new Order();

                try
                {
                    UpdateModel(order);
                    customer.Orders.Add(order);
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    Response.StatusCode = 500;
                    Response.AppendHeader("message",
                                          "There was an issue adding order to customer \"" + customer.FirstName + " " + customer.LastName +
                                          "\". Please contact tech support with this message: " + Utility.GetInnermostException(e).Message);
                }
            }

            return View(new GridModel(GetOrders(customerId)));
        }
        public ChannelsViewModel()
        {
            var context = new SampleEntities();

            var channels = context.OrderChannels
                   .OrderBy(c => c.Name)
                   .Select(c =>
                           new SelectListItem
                           {
                               Selected = false,
                               Text = c.Name,
                               Value = SqlFunctions.StringConvert((double)c.ID)
                           });

            Channels = channels.ToList();
        }
 public CustomersViewModel()
 {
     var context = new SampleEntities();
     Customers = from c in context.Customers
                 orderby c.LastName, c.FirstName
                 select
                     new CustomerViewModel
                         {
                             CustomerId = c.ID,
                             FirstName = c.FirstName,
                             LastName = c.LastName,
                             MiddleName = c.MiddleName,
                             MiddleInitial = c.MiddleName == "" ? "" : " " + c.MiddleName.Substring(0, 1) + ".",
                             AccountNumber = c.AccountNumber
                         };
 }
 public OrdersViewModel(int customerId)
 {
     var context = new SampleEntities();
     Orders = from o in context.Orders
              orderby o.DatePlaced
              where o.CustomerID == customerId
              select
                  new OrderViewModel
                      {
                          OrderId = o.ID,
                          CustomerId = o.CustomerID,
                          DatePlaced = o.DatePlaced,
                          OrderSubtotal = o.OrderSubtotal,
                          OrderTax = o.OrderTax,
                          OrderTotal = o.OrderTotal,
                          OrderChannelId = o.OrderChannel.ID,
                          OrderChannelName = o.OrderChannel.Name
                      };
 }
        public ActionResult AjaxAddCustomer(string lastName, string firstName)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var context = new SampleEntities();
                    var customer = new Customer();
                    UpdateModel(customer);
                    context.Customers.AddObject(customer);
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    Response.StatusCode = 500;
                    Response.AppendHeader("message",
                                          "There was an issue adding customer \"" + firstName + " " + lastName +
                                          "\". Please contact tech support with this message: " + Utility.GetInnermostException(e).Message);
                }
            }

            return View(new GridModel(GetCustomers()));
        }
Пример #7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ObjEntity = new SampleEntities();

        LoadMotherTongueCombo();

        if (!IsPostBack)
        {
            LoadProfileForCombo();
            LoadReligionCombo();
            LoadCountryCombo();
        }
    }
Пример #8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ObjEntity = new SampleEntities();

        string TxtName = Convert.ToString(Session["Sessionname"]);
        string TxtDob = Convert.ToString(Session["SessionDOB"]);
        string TxtGender = Convert.ToString(Session["SessionGender"]);
        string Txtreligion = Convert.ToString(Session["SessionReligion"]);
        string TxtMotherTon = Convert.ToString(Session["SessionMotherTon"]);
        string TxtCaste = Convert.ToString(Session["SessionCaste"]);
        string TxtCountry = Convert.ToString(Session["SessionCountry"]);
        string TxtMobile = Convert.ToString(Session["SessionMobile"]);
        string TxtEmail = Convert.ToString(Session["SessionEmail"]);
        string TxtPwd = Convert.ToString(Session["SessionPSW"]);
        Lbl_CountryName.Text = TxtCountry;
        Lbl_CasteName.Text = TxtCaste;

        LoadHigherEduCombo();
        LoadOccupCombo();
        LoadCurrencyCombo();
        SubCaste();
        RegionalSitesn();

        //according to religion caste will be change to dropdown or textbox

        if (Txtreligion == "Hindu")
        {
            Txt_Caste.Visible= false;
            DDL_SubCaste.Visible = true;
        }
        else
        {
            Txt_Caste.Visible = true;
            DDL_SubCaste.Visible = false;
        }

        if (!IsPostBack)
        {
            LoadStarCombo();
            LoadStateCombo();
        }
    }
        private bool ValidateCustomer(CustomerViewModel model)
        {
            var context = new SampleEntities();

            return !context.Customers.Any(c => c.LastName.ToLower() == model.LastName.ToLower() &&
                                               c.FirstName.ToLower() == model.FirstName.ToLower() &&
                                               (model.MiddleName == null ? c.MiddleName == null : c.MiddleName.ToLower() == model.MiddleName.ToLower()) &&
                                               c.ID != model.CustomerId);
        }
        public ActionResult AjaxSaveOrder(int customerId, int orderId)
        {
            if (ModelState.IsValid)
            {
                var context = new SampleEntities();
                var order = context.Customers.Single(c => c.ID == customerId).Orders.Single(o => o.ID == orderId);

                try
                {
                    UpdateModel(order);
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    Response.StatusCode = 500;
                    Response.AppendHeader("message",
                                          "There was an issue editing data for this order. Please contact tech support with this message: " + e.Message);
                }
            }

            return View(new GridModel(GetOrders(customerId)));
        }
        public ActionResult AjaxSaveCustomer(int customerId, string lastName, string firstName)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var context = new SampleEntities();
                    var customer = context.Customers.Single(c => c.ID == customerId);
                    UpdateModel(customer);
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    Response.StatusCode = 500;
                    Response.AppendHeader("message",
                                          "There was an issue editing data for customer \"" + firstName + " " + lastName +
                                          "\". Please contact tech support with this message: " + e.Message);
                }
            }

            return View(new GridModel(GetCustomers()));
        }
        public ActionResult AjaxDeleteOrder(int customerId, int orderId)
        {
            try
            {
                var context = new SampleEntities();
                var customer = context.Customers.Single(c => c.ID == customerId);
                var order = customer.Orders.Single(o => o.ID == orderId);
                context.DeleteObject(order);
                context.SaveChanges();
            }
            catch (System.Exception e)
            {
                Response.StatusCode = 500;
                Response.AppendHeader("message", "There was an issue deleting order " + orderId + ". Please contact tech support with this message: " + Utility.GetInnermostException(e).Message);
            }

            return View(new GridModel(GetOrders(customerId)));
        }