public CodeStyleFilesViewModel(CodeStyleFiles codeStyleFiles)
 {
     if (codeStyleFiles is null)
     {
         Name = "new rules";
         Id   = -1;
     }
     else
     {
         Name     = codeStyleFiles.Name;
         Id       = codeStyleFiles.Id;
         StyleCop = System.Text.Encoding.UTF8.GetString(codeStyleFiles.StyleCopFile);
         RuleSet  = System.Text.Encoding.UTF8.GetString(codeStyleFiles.RulesetFile);
     }
 }
        public IActionResult PostNewRecord(string json)
        {
            CodeStyleFilesViewModel jsonRecord = JsonConvert.DeserializeObject <CodeStyleFilesViewModel>(json);
            CodeStyleFiles          newRecord  = new CodeStyleFiles
            {
                Name         = jsonRecord.Name,
                RulesetFile  = System.Text.Encoding.UTF8.GetBytes(jsonRecord.RuleSet),
                StyleCopFile = System.Text.Encoding.UTF8.GetBytes(jsonRecord.StyleCop)
            };

            var  x           = _db.CodeStyleFiles.Add(newRecord);
            var  beforeState = x.State;
            int  r           = _db.SaveChanges();
            var  afterState  = x.State;
            bool ok          = beforeState == EntityState.Added && afterState == EntityState.Unchanged && r == 1;

            return(Content(ok ? "/Administration/CodeStyleRules/ChangeRecord?id=" + newRecord.Id.ToString() : "error"));
        }
Exemplo n.º 3
0
 public CodeStyleFilesViewModel(CodeStyleFiles f)
 {
     Id   = f.Id;
     Name = f.Name;
 }