当前位置: 首页>>代码示例>>C#>>正文


C# Entities.SaveChanges方法代码示例

本文整理汇总了C#中Entities.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# Entities.SaveChanges方法的具体用法?C# Entities.SaveChanges怎么用?C# Entities.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Entities的用法示例。


在下文中一共展示了Entities.SaveChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: btnSave_Click

    //保存
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Entities mydb = new Entities();
                  {
                      L_Tags Lt = new L_Tags();
                   if (_Id != 0)
                       Lt = mydb.L_Tags.First(p => p.TID == _Id);

                   Lt.TName = txtName.Text.Trim();
                   Lt.TContent = this.txtTag.Text;
                   Lt.TNotice = "";

                if (_Id == 0)
                {
                    mydb.L_Tags.AddObject(Lt);
                    mydb.SaveChanges();
                    JscriptPrint("自定义标签添加成功啦!", "list.aspx", "Success");
                }
                else
                {
                    mydb.SaveChanges();
                    JscriptPrint("自定义标签修改成功啦!", "list.aspx", "Success");
                }
         }

            // bll.Add(model);
            //保存日志
            //SaveLogs("[资讯模块]添加文章:" + model.Title);
            //JscriptPrint("文章发布成功啦!", "Add.aspx?classId=" + ddlClassId.SelectedValue, "Success");
    }
开发者ID:priceLiu,项目名称:CMS,代码行数:31,代码来源:Add.aspx.cs

示例2: btnSave_Click

    //保存
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Entities mydb = new Entities();
                  {
                   Manages Lt = new Manages();
                   if (_Id != 0)
                   {
                       Lt = mydb.Manages.First(p => p.MID == _Id);
                       if (txtNew.Text.Trim().Equals("") || txtNew2.Text.Trim().Equals(""))
                       {
                           JscriptPrint("密码不能为空!", "", "Error");
                           return;
                       }
                       if (txtNew.Text.Trim() != txtNew2.Text.Trim())
                       {
                           JscriptPrint("两次密码不一致!", "", "Error");
                           return;
                       }
                       if (_isOne != 0)
                       {
                           Lt.MPWD = DESEncrypt.Encrypt(this.txtNew.Text.Trim());
                           mydb.SaveChanges();
                           JscriptPrint("对用户密码修改成功!", "", "Success");
                       }
                       else
                       {

                           if (txtOld.Text.Trim().Equals(""))
                           {
                               JscriptPrint("密码不能为空!", "", "Error");
                               return;
                           }
                           if (DESEncrypt.Encrypt(this.txtOld.Text.Trim()) != Lt.MPWD)
                           {
                               JscriptPrint("老密码不正确!", "", "Error");
                               return;
                           }
                           else
                           {

                               Lt.MPWD = DESEncrypt.Encrypt(this.txtNew.Text.Trim());
                               mydb.SaveChanges();
                               JscriptPrint("修改成功!", "", "Success");
                           }

                       }
                   }

         }

            // bll.Add(model);
            //保存日志
            //SaveLogs("[资讯模块]添加文章:" + model.Title);
            //JscriptPrint("文章发布成功啦!", "Add.aspx?classId=" + ddlClassId.SelectedValue, "Success");
    }
开发者ID:priceLiu,项目名称:CMS,代码行数:56,代码来源:PwAdd.aspx.cs

示例3: CreateMarketingCampaign

        public static MarketingCampaign CreateMarketingCampaign(string companyName, string website, string city, string country,
            string username, string email, string phone, HttpFileCollectionBase postedFiles, string description,
            HttpPostedFileBase logoFile, string referringURL, Action<EntityContext, Company> createPortfolios)
        {
            var context = new Entities();

            if (Account.Exists(username))
                throw new Exception("The username already exists.");

            var account = new Account();
            account.Username = username;
            account.Password = AgileFx.Security.CryptoUtil.HashPassword(Guid.NewGuid().ToString());
            account.Status = ACCOUNT_STATUS.ACTIVE;
            account.LastLoginDate = DateTime.Now;
            account.DateAdded = DateTime.Now;
            account.Type = ACCOUNT_TYPE.COMPANY;
            account.Email = email;

            var company = new Company();
            company.Account = account;
            company.Name = companyName;
            company.Website = website;
            company.City = city;
            company.Country = country;
            company.Phone = phone;

            if (logoFile.ContentLength > 0)
                company.SaveLogo(logoFile);

            company.Description = description;

            foreach (var tag in context.Tag.Where(t => t.Name == "Web Design" || t.Name == ""))
                company.Tags.Add(tag);

            createPortfolios(context, company);

            context.AddObject(company);
            context.SaveChanges();

            var marketingCamp = new MarketingCampaign();
            marketingCamp.Account = account.Id;
            marketingCamp.DateCreated = DateTime.UtcNow;
            marketingCamp.DateModified = DateTime.UtcNow;
            marketingCamp.ReferringURL = referringURL;
            marketingCamp.Status = MARKETING_CAMPAIGN_STATUS.NEW;
            marketingCamp.Token = Guid.NewGuid();

            context.AddObject(marketingCamp);
            context.SaveChanges();

            return marketingCamp;
        }
开发者ID:jeswin,项目名称:CanYouCode,代码行数:52,代码来源:MarketingUtil.cs

示例4: ActualizarDatosEstablecimiento

 public ActionResult ActualizarDatosEstablecimiento(Dir_Establecimientos establecimiento,Ges_Informante informante, Ges_Georreferencia georeferencia)
 {
     using (Entities db = new Entities())
     {
         if (ModelState.IsValid)
         {
             try
             {
                 establecimiento.FechaActualizacion = DateTime.Now;
                 db.Entry(establecimiento).State = EntityState.Modified;
                 // falta validar cuando no exista informante ni georeferencia, asi debe agregar un nuevo registro(ambos casos)
                 //db.Entry(informante).State = EntityState.Modified;
                 //georeferencia.Latitud = Convert.ToString(georeferencia.Latitud);
                 //georeferencia.Longitud = Convert.ToString(georeferencia.Longitud);
                 //georeferencia.FechaGeorreferencia = DateTime.Now;
                 //db.Entry(georeferencia).State = EntityState.Modified;
                 db.SaveChanges();
             }
             catch (Exception e)
             {
                 return Json(e.Message);
             }
             return Json(1);
         }
     }
     return Json(0);
 }
开发者ID:simadine,项目名称:simad,代码行数:27,代码来源:DirectorioController.cs

示例5: Guardar

        public ByARpt Guardar(GD_DOCUMENTOSDTO a)
        {
            using (ctx = new Entities())
            {
                GD_DOCUMENTOS f = new GD_DOCUMENTOS();
                f.NOMBRE = a.NOMBRE;
                f.LONGITUD = a.LONGITUD;
                try
                {
                    f.ID = ctx.GD_DOCUMENTOS.Max(t => t.ID) + 1;
                }
                catch {
                    f.ID = 1;
                }
                
                f.TYPE = a.TYPE;
                f.URL = a.URL;
                f.DESCRIPCION = a.DESCRIPCION;
                f.GD_DDOCUMENTOS = new GD_DDOCUMENTOS();
                f.GD_DDOCUMENTOS.DOCUMENTO = a.DOCUMENTO;
                f.ESTADO = "PE";
                f.FEC_REG = DateTime.Now;
                f.USUARIO = a.USUARIO;
                ctx.GD_DOCUMENTOS.Add(f);
                ctx.SaveChanges();
                byaRpt.Mensaje = "OK";
                byaRpt.id = f.ID.ToString();
                byaRpt.Error = false;

            }

            return byaRpt;
        }
开发者ID:borisgr04,项目名称:ByASircc4v2016,代码行数:33,代码来源:GestionDOC.cs

示例6: CancelarLiquidacion

 public ByARpt CancelarLiquidacion(decimal ID_LIQ)
 {
     using (ctx = new Entities())
     {
         try
         {
             ByARpt res = new ByARpt();
             SL_LIQESTAMPILLAS liquidacion = ctx.SL_LIQESTAMPILLAS.Where(t => t.ID == ID_LIQ).FirstOrDefault();
             if (liquidacion != null)
             {
                 liquidacion.ESTADO = "IN";
                 ctx.SaveChanges();
                 res.Mensaje = "Operación Realizada Satisfactoriamente";
                 res.Error = false;
                 return res;
             }
             else
             {
                 res.Mensaje = "No se encuentra liquidación";
                 res.Error = true;
                 return res;
             }
         }
         catch
         {
             ByARpt res = new ByARpt();
             res.Mensaje = "Ha ocurrido un error...";
             res.Error = true;
             return res;
         }
     }
 }
开发者ID:borisgr04,项目名称:ByA_Signus,代码行数:32,代码来源:mSL_LIQESTAMPILLAS.cs

示例7: btnSave_Click

    //保存
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Entities mydb = new Entities();
                  {
                      L_Feedback Lfb = new L_Feedback();
                      Lfb = mydb.L_Feedback.First(p => p.FID == _Id);

                   //Lt.FNmae = txtName.Text.Trim();
                   //Lt.Fother = this.txtTag.Text;
                   //Lt.F1 = this.TextC.Text.Trim();

                      if  (this.CheckBox1.Checked)
                          Lfb.FLock = "1";
                      else
                          Lfb.FLock = "0";
                      Lfb.FReContent = this.txtRe.Text.Trim();

                      Lfb.FReTime = DateTime.Now.ToString();

                    mydb.SaveChanges();
                    JscriptPrint("回复成功啦!", "FBlist.aspx", "Success");
                }

            // bll.Add(model);
            //保存日志
            //SaveLogs("[资讯模块]添加文章:" + model.Title);
            //JscriptPrint("文章发布成功啦!", "Add.aspx?classId=" + ddlClassId.SelectedValue, "Success");
    }
开发者ID:priceLiu,项目名称:CMS,代码行数:29,代码来源:FBAdd.aspx.cs

示例8: CreateGame

 public Game CreateGame(Guid userId)
 {
     var newGame = new Models.Game()
     {
         ID = Guid.NewGuid(),
         UserID = userId
     };
     using (var triviaContext = new Entities())
     {
         var questions = triviaContext.Questions.Take(20);
         foreach (var q in questions)
         {
             var newGameQuestion = new GameQuestion
             {
                 ID = Guid.NewGuid(),
                 GameID = newGame.ID,
                 QuestionID = q.ID
             };
             newGame.GameQuestions.Add(newGameQuestion);
         }
         triviaContext.AddToGames(newGame);
         triviaContext.SaveChanges();
     }
     using (var triviaContext = new Entities())
     {
         var game = triviaContext.Games
             .Include("GameQuestions")
             .Include("GameQuestions.Question")
             .Include("GameQuestions.Question.Answers")
             .FirstOrDefault(g => g.ID == newGame.ID);
         return game;
     }
 }
开发者ID:narph,项目名称:seinfeld-trivia,代码行数:33,代码来源:GameRepository.cs

示例9: btnSave_Click

    //保存
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Entities mydb = new Entities();
                  {
                      L_RForm Lt = new L_RForm();
                      Lt = mydb.L_RForm.First(p => p.FrID == _Id);

                   //Lt.FNmae = txtName.Text.Trim();
                   //Lt.Fother = this.txtTag.Text;
                   //Lt.F1 = this.TextC.Text.Trim();

                      if  (this.CheckBox1.Checked)
                      Lt.FrReOk = 0;
                      Lt.FrRepaly = this.txtRe.Text.Trim();

                      Lt.FrReTime = DateTime.Now;

                    mydb.SaveChanges();
                    JscriptPrint("回复成功啦!", "Rlist.aspx", "Success");
                }

            // bll.Add(model);
            //保存日志
            //SaveLogs("[资讯模块]添加文章:" + model.Title);
            //JscriptPrint("文章发布成功啦!", "Add.aspx?classId=" + ddlClassId.SelectedValue, "Success");
    }
开发者ID:priceLiu,项目名称:CMS,代码行数:27,代码来源:RAdd.aspx.cs

示例10: btnSubmitCreateAccount_Click

    protected void btnSubmitCreateAccount_Click(object sender, EventArgs e)
    {
        try
        {
            Entities dbContext = new Entities();

            Customer customer = new Customer();
            customer.FirstName = txtFirstName.Text;
            customer.LastName = txtLastName.Text;
            customer.EmailAddress = txtEmailAddress.Text;
            customer.Password = WebUser.HashPassword(txtPassword.Text);
            customer.ContactNumber = txtContactNumber.Text;
            customer.CreatedAt = DateTime.Now;

            dbContext.Customers.AddObject(customer);

            dbContext.SaveChanges();

            lblFormResponse.Text = "Your account was sucessfully created. You may <a href=\"" + Request.ApplicationPath.TrimEnd('/') + "/Default.aspx\">login</a> now.";

            // temporary
            //Response.Redirect("~/Default.aspx");
        }
        catch (EntityDataSourceValidationException ex)
        {
            throw new Exception(ex.Message);
        }
        catch (Exception ex)
        {
            lblFormResponse.Text = ex.Message;
        }
    }
开发者ID:jayrulez,项目名称:oursit,代码行数:32,代码来源:CreateAccount.aspx.cs

示例11: btnSubmitUpdateAccount_Click

    protected void btnSubmitUpdateAccount_Click(object sender, EventArgs e)
    {
        try
        {
            Entities dbContext = new Entities();
            int customerId = WebUser.GetInstance().Id;
            Customer customer = dbContext.Customers.FirstOrDefault(c => c.Id == customerId);
            if(customer == null)
            {
                throw new Exception("Could not locate the current customer account in the database. Try again or contact administrator.");
            }

            customer.FirstName = txtFirstName.Text;
            customer.LastName = txtLastName.Text;
            customer.EmailAddress = txtEmailAddress.Text;
            customer.ContactNumber = txtContactNumber.Text;
            if(txtPassword.Text.Length > 0)
            {
                customer.Password = WebUser.HashPassword(txtPassword.Text);
            }

            dbContext.SaveChanges();

            lblFormResponse.Text = "Your account was sucessfully updated.";
        }catch(Exception ex)
        {
            lblFormResponse.Text = ex.Message;
        }
    }
开发者ID:jayrulez,项目名称:oursit,代码行数:29,代码来源:Account.aspx.cs

示例12: StartAdmission

        public void StartAdmission()
        {
            using (var entities = new Entities())
            {
                entities.Configuration.AutoDetectChangesEnabled = false;

                var majorDictionary = new Dictionary<Major, EnrollingMajor>();
                foreach (var major in entities.Majors)
                    majorDictionary.Add(major, new EnrollingMajor(major));

                this.majors = majorDictionary.Values.ToArray();

                var candidateList = new List<EnrollingCandidate>();
                foreach (var candidate in entities.Candidates)
                {
                    var options = from option in GetOptions(candidate)
                                  select majorDictionary[option];

                    var scores = GetScores(candidate);

                    Debug.Assert(options.Count() == scores.Count());

                    candidateList.Add(new EnrollingCandidate(candidate, options, scores));
                }
                this.candidates = candidateList.ToArray();

                RunAlgorithm();
                SaveResults();

                entities.SaveChanges();
            }
        }
开发者ID:TaQuangNgoc,项目名称:EnrollmentSystem,代码行数:32,代码来源:Admission.cs

示例13: btnSave_Click

    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (this.txtName.Text == "")
            {
                JscriptPrint("没有选择任何文档!","","Success");

            }
            else
            {
                Entities mydb = new Entities();
                string allids = Request.QueryString["ids"];
                string[] allidss = allids.Remove(allids.Length - 1).Split('-');
                foreach (var item in allidss)
                {
                    int newid = int.Parse(item);
                    int fid = int.Parse(this.DropDownList1.SelectedValue);
                    L_Newss onenews = mydb.L_Newss.Single(p => p.NID == newid);
                    onenews.ClassId = fid;
                    mydb.SaveChanges();

                }

                JscriptPrint("移动完成!", "", "Success");
            }
    }
开发者ID:priceLiu,项目名称:CMS,代码行数:25,代码来源:Move.aspx.cs

示例14: Exluir

 public static void Exluir(string NomeAcao)
 {
     Entities Context = new Entities();
     TB_TIPO_ACAO query = Context.TB_TIPO_ACAO.Where(t => t.IDT_TIPO_ACAO == NomeAcao).FirstOrDefault();
     Context.TB_TIPO_ACAO.DeleteObject(query);
     Context.SaveChanges();
 }
开发者ID:KleberRibeiro89,项目名称:d5solucoes,代码行数:7,代码来源:TipoAcao.cs

示例15: TeacherAdd

 public bool TeacherAdd(Entities db, Guid campusId, Guid departmentId, int ordinal, string name, string phone, string passwordInitial, State state, string email, string idCard, bool? gender, DateTime? birthday, string nationality, string birthplace, string address, string account, bool? perstaff, bool sync, out Guid gid, string ex)
 {
     gid = db.GetId();
     try
     {
         string key, salt;
         var password = HomoryCryptor.Encrypt(passwordInitial, out key, out salt);
         var user = new User
         {
             Id = gid,
             Account = account,
             RealName = name,
             DisplayName = name,
             Stamp = Guid.NewGuid(),
             Type = UserType.教师,
             Password = password,
             PasswordEx = null,
             CryptoKey = key,
             CryptoSalt = salt,
             Icon = "~/CommonX/默认/用户.png",
             State = state,
             Ordinal = ordinal,
             Description = null
         };
         var userTeacher = new Homory.Model.Teacher
         {
             Id = user.Id,
             Phone = phone,
             Email = email,
             Gender = gender,
             Birthday = birthday,
             Birthplace = birthplace,
             Address = address,
             Nationality = nationality,
             IDCard = idCard,
             PerStaff = perstaff ?? true,
             Sync = sync
         };
         var relation = new DepartmentUser
         {
             DepartmentId = departmentId,
             UserId = user.Id,
             TopDepartmentId = campusId,
             Type = DepartmentUserType.部门主职教师,
             State = State.启用,
             Ordinal = 0,
             Time = DateTime.Now
         };
         db.User.Add(user);
         db.Teacher.Add(userTeacher);
         db.DepartmentUser.Add(relation);
         db.SaveChanges();
         try { UserHelper.InsertUserEx(name, "C984AED014AEC7623A54F0591DA07A85FD4B762D", sync, state, account, departmentId.ToString().ToUpper(), gid.ToString().ToUpper(), phone, idCard, ordinal, 0, "1000", ex); } catch { }
         return true;
     }
     catch
     {
         return false;
     }
 }
开发者ID:Homory-Temp,项目名称:LeYi,代码行数:60,代码来源:Import.aspx.cs


注:本文中的Entities.SaveChanges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。