Exemplo n.º 1
0
        public LenLevel Add(LenLevel entity)
        {
            using (var db = new Entities())
            {
                if (CheckRepeat(entity, db))
                {
                    Errors.Set("Error", "等级名称已经存在!");
                }
                else
                {
                    entity.CreateDate = DateTime.Now;
                    entity.CreateUserID = CurrentUserBiz.CurrentUser.ID;
                    entity.ModifyDate = DateTime.Now;
                    entity.ModifyUserID = CurrentUserBiz.CurrentUser.ID;

                    db.LenLevel.Add(entity);

                    Errors = db.GetErrors();

                    if (!HasError)
                    {
                        db.SaveChanges();
                    }
                }
                return entity;
            }
        }
Exemplo n.º 2
0
        public LenLevel Edit(LenLevel entity)
        {
            using (var db = new Entities())
            {
                if (CheckRepeat(entity, db))
                {
                    Errors.Set("Error", "等级名称已经存在!");
                }
                else
                {
                    var entry = db.Entry(entity);
                    //entry.State = EntityState.Modified;
                    entry.State = EntityState.Unchanged;
                    entry.Property(q => q.LevelName).IsModified = true;
                    entry.Property(q => q.ModifyDate).IsModified = true;
                    entry.Property(q => q.ModifyUserID).IsModified = true;

                    Errors = db.GetErrors();
                    if (!HasError)
                    {
                        db.SaveChanges();
                    }
                }

                return entity;
            }
        }
Exemplo n.º 3
0
 private bool CheckRepeat(LenLevel entity, Entities db)
 {
     if (entity != null)
     {
         return db.LenLevel.Any(q => q.LevelName.ToUpper() == entity.LevelName.ToUpper() && q.ID != entity.ID);
     }
     return false;
 }