Пример #1
0
        protected void OnClick(object sender, EventArgs e)
        {
            using (var dataContext = new EPGDataModel())
            {
                if (!string.IsNullOrEmpty(hidRight.Value))
                {
                    var activeIds = hidRight.Value.Substring(0, hidRight.Value.Length - 1).Split(',');

                    foreach (var item in activeIds)
                    {
                        var id      = Convert.ToInt64(item);
                        var dbEntry = dataContext.ActiveChannels.FirstOrDefault(c => c.Srno.Equals(id));

                        if (dbEntry != null)
                        {
                            dbEntry.IsActive = true;
                            dataContext.Entry(dbEntry).State = EntityState.Modified;
                        }
                    }

                    dataContext.SaveChanges();

                    PopulateInactive(Convert.ToInt64(ddlSourceXml.SelectedValue));
                    PopulateActive(Convert.ToInt64(ddlSourceXml.SelectedValue));
                    lblMsg.Text = "Selection Saved!";
                }

                if (!string.IsNullOrEmpty(hidLeft.Value))
                {
                    var inActiveIds = hidLeft.Value.Substring(0, hidLeft.Value.Length - 1).Split(',');

                    foreach (var item in inActiveIds)
                    {
                        var id      = Convert.ToInt64(item);
                        var dbEntry = dataContext.ActiveChannels.FirstOrDefault(c => c.Srno.Equals(id));

                        if (dbEntry != null)
                        {
                            dbEntry.IsActive = false;
                            dataContext.Entry(dbEntry).State = EntityState.Modified;
                        }
                    }

                    dataContext.SaveChanges();

                    PopulateInactive(Convert.ToInt64(ddlSourceXml.SelectedValue));
                    PopulateActive(Convert.ToInt64(ddlSourceXml.SelectedValue));
                    lblMsg.Text = "Selection Saved!";
                }
            }
        }
Пример #2
0
        protected void gvUsers_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            var row      = gvUsers.Rows[e.RowIndex];
            var userId   = Convert.ToString(gvUsers.DataKeys[e.RowIndex].Values[0]);
            var userName = (row.FindControl("txtName") as TextBox).Text;
            var email    = (row.FindControl("txtUserEmailAddress") as TextBox).Text;
            var pass     = (row.FindControl("txtPassword") as TextBox).Text;
            var type     = (row.FindControl("ddlUserType") as DropDownList).SelectedValue;

            using (var dataContext = new EPGDataModel())
            {
                var user = dataContext.Users.Find(userName);

                user.UserEmailAddress = email;
                user.Password         = pass;
                user.PasswordSalt     = pass;
                user.UserType         = type;
                try
                {
                    dataContext.Entry(user).State = EntityState.Modified;
                    dataContext.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (var eve in ex.EntityValidationErrors)
                    {
                        Console.WriteLine(
                            "Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
            }
            gvUsers.EditIndex = -1;
            BindGrid();
        }
Пример #3
0
        protected void gvXMLSource_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            var row        = gvXMLSource.Rows[e.RowIndex];
            var srno       = Convert.ToInt32(gvXMLSource.DataKeys[e.RowIndex].Values[0]);
            var sourceUrl  = (row.FindControl("txtSourceURL") as TextBox).Text;
            var sourceType = (row.FindControl("ddlGridSourceType") as DropDownList).SelectedValue;


            using (var dataContext = new EPGDataModel())
            {
                var source = dataContext.SourceURLs.Find(srno);

                source.Url       = sourceUrl;
                source.Type      = sourceType;
                source.EntryDate = DateTime.Today;
                source.IsActive  = true;
                try
                {
                    dataContext.Entry(source).State = EntityState.Modified;
                    dataContext.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (var eve in ex.EntityValidationErrors)
                    {
                        Console.WriteLine(
                            "Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
            }
            gvXMLSource.EditIndex = -1;
            BindGrid();
        }