Beispiel #1
0
        public IActionResult Create(Models.Record record)
        {
            _context.Records.Add(record);
            _context.SaveChanges();

            return(CreatedAtRoute("GetRecord", new { id = record.Id }, record));
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "ID,Name,Email,Course,Contact")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Country,Sport,MedalWon,MatchPlayed")] Players players)
        {
            if (ModelState.IsValid)
            {
                db.players.Add(players);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(players));
        }
        public ActionResult Create([Bind(Include = "ID,fname,lname,email,mobilephone,birthdate,address,description,curuser")] Record record)
        {
            if (ModelState.IsValid)
            {
                db.Records.Add(record);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(record));
        }
        public ActionResult Create([Bind(Include = "ID,UserName,WeightGoal,HeightGoal")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Beispiel #6
0
        public ActionResult Create([Bind(Include = "Title,ISBN")] Book1 book1)
        {
            if (ModelState.IsValid)
            {
                db.Books.Add(book1);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(book1));
        }
        public ActionResult Create([Bind(Include = "RecordID,UserID,Weight,Height,InputDate")] Record record)
        {
            if (ModelState.IsValid)
            {
                db.Records.Add(record);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserID = new SelectList(db.Users, "ID", "UserName", record.UserID);
            return(View(record));
        }
Beispiel #8
0
        public async Task <IActionResult> CreateRecords()
        {
            using var reader = new StreamReader(HttpContext.Request.Body);
            var body = await reader.ReadToEndAsync();

            var records = JsonConvert.DeserializeObject <List <Dictionary <int, string> > >(body)
                          .Select(d => new Record {
                Code = d.Keys.FirstOrDefault(), Value = d.Values.FirstOrDefault()
            }).OrderBy(i => i.Code)
                          .ToList();

            for (var i = 1; i <= records.Count(); i++)
            {
                records[i - 1].Id = i;
            }

            var oldRecords = _context.Records;

            _context.Records.RemoveRange(oldRecords);
            _logger.LogInformation("Old records was deleted");

            _context.Records.AddRange(records);
            _context.SaveChanges();

            return(Created(nameof(RecordController), new { response = "Records was uploaded" }));
        }
Beispiel #9
0
        public void AutomaticUpdateRecords(object o)
        {
            DbContextOptionsBuilder optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.UseSqlite(_configuration["ConnectionString_RecordDb"]);

            RecordContext newRecordContext = new RecordContext(optionsBuilder.Options);

            newRecordContext.Database.EnsureCreated();

            var index = 1;

            var dbRecords = newRecordContext.Records.Where(r => r.Status == Status.InPending).ToList();

            foreach (var record in dbRecords)
            {
                record.Status = Status.InWork;
                var textArr = record.Text.Split(' ');
                Array.Reverse(textArr);
                record.Text        = string.Join(" ", textArr);
                record.IndexNumber = index++;
            }
            newRecordContext.SaveChanges();

            if (dbRecords.Count() > 0)
            {
                Task sendUpdateRecords = _hub.Clients.All.SendAsync("transferdata", GetRecords(newRecordContext));
            }
        }
Beispiel #10
0
 public Test GetTestConnectathon(int id)
 {
     using (var db = new RecordContext())
     {
         Test test = new Test(Connectathon.FromId(id));
         db.Tests.Add(test);
         db.SaveChanges();
         return(test);
     }
 }
Beispiel #11
0
 public Test GetTestConnectathon(int id, int certificateNumber, string state)
 {
     using (var db = new RecordContext())
     {
         Test test = new Test(Connectathon.FromId(id, certificateNumber, state));
         db.Tests.Add(test);
         db.SaveChanges();
         return(test);
     }
 }
Beispiel #12
0
 public Test NewTest()
 {
     using (var db = new RecordContext())
     {
         Test test = new Test();
         db.Tests.Add(test);
         db.SaveChanges();
         return(test);
     }
 }
Beispiel #13
0
        public async Task <List <DTORecord> > UpdateRecords(List <DTORecord> records)
        {
            foreach (var record in records)
            {
                var dbRecord = _recordContext.Records.Where(r => r.Id == record.RecordId).FirstOrDefault();
                dbRecord.Status = Status.InPending;
                _recordContext.SaveChanges();
            }

            return(await GetRecords());
        }
        public ActionResult Index([Bind(Include = "Id, Description")] Record record)
        {
            if (ModelState.IsValid)
            {
                db.Records.Add(record);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(record));
        }
Beispiel #15
0
 public static void Initialize(RecordContext context)
 {
     if (context.Records.Any())
     {
         return;
     }
     context.Records.AddRange(
         new Record(100, 1000),
         new Record(100, 1060),
         new Record(100, 1111)
         );
     context.SaveChanges();
 }
Beispiel #16
0
        public RecordController(RecordContext context)
        {
            _context = context;

            if (_context.Records.Count() == 0)
            {
                // Create a new TodoItem if collection is empty,
                // which means you can't delete all TodoItems.
                _context.Records.Add(new Models.Record {
                    F1 = "Record1-Field1", F2 = "Record1-Field2", F3 = "Record1-Field3"
                });
                _context.SaveChanges();
            }
        }
        public User Create(User user, string password)
        {
            // validation
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("Password is required");
            }

            if (_context.Users.Any(x => x.Username == user.Username))
            {
                throw new AppException("Username " + user.Username + " is already taken");
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            _context.Users.Add(user);
            _context.SaveChanges();

            return(user);
        }
Beispiel #18
0
 public async Task <Test> RunRoundtripProducingTest(int id) // TODO: These test routes can probably be combined.
 {
     using (var db = new RecordContext())
     {
         Test   test  = db.Tests.Where(t => t.TestId == id).FirstOrDefault();
         string input = await new StreamReader(Request.Body, Encoding.UTF8).ReadToEndAsync();
         if (!String.IsNullOrEmpty(input))
         {
             test.Type = "RoundtripProducing";
             test.Run(input);
         }
         db.Tests.Remove(test);
         db.SaveChanges();
         return(test);
     }
 }
Beispiel #19
0
 public async Task <Test> RunTest(int id, string type)
 {
     using (var db = new RecordContext())
     {
         Test   test  = db.Tests.Where(t => t.TestId == id).FirstOrDefault();
         string input = await new StreamReader(Request.Body, Encoding.UTF8).ReadToEndAsync();
         if (!String.IsNullOrEmpty(input))
         {
             test.Type = type;
             test.Run(input);
         }
         db.Tests.Remove(test);
         db.SaveChanges();
         return(test);
     }
 }
 public int New()
 {
     // Find the record in the database and return it
     using (var db = new RecordContext())
     {
         if (db.Endpoints.Count() > 100)
         {
             // Too many endpoints in existance, delete the oldest to prevent someone from abusing this.
             // TODO: Probably a smoother way to accomplish this. Investigate.
             db.Endpoints.Remove(db.Endpoints.FirstOrDefault());
         }
         Endpoint endpoint = new Endpoint();
         db.Endpoints.Add(endpoint);
         db.SaveChanges();
         return(endpoint.EndpointId);
     }
 }
Beispiel #21
0
        public Record Create(string state, string type)
        {
            using (var db = new RecordContext())
            {
                // Create new record from scratch
                Record record = new Record();

                // Populate the record with fake data
                record.Populate();

                // Save the record to the database
                db.Records.Add(record);
                db.SaveChanges();

                // Return the record
                return(record);
            }
        }
Beispiel #22
0
 public Test RunProduceTest(int id) // TODO: These test routes can probably be combined.
 {
     using (var db = new RecordContext())
     {
         Test   test = db.Tests.Where(t => t.TestId == id).FirstOrDefault();
         string input;
         using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
         {
             input = reader.ReadToEnd();
         }
         if (!String.IsNullOrEmpty(input))
         {
             test.Run(input);
             test.Type = "Produce";
         }
         db.SaveChanges();
         return(test);
     }
 }
Beispiel #23
0
        public JsonResult DeleteUser(int Id)
        {
            string result = string.Empty;
            var    dbh    = new RecordContext();

            FileFormat user = dbh.FileFormats.Find(Id);

            dbh.FileFormats.Remove(user);

            int value = dbh.SaveChanges();

            if (value > 0)
            {
                result = "The row has been successfully deleted.";
            }
            else
            {
                result = "The row was not deleted.";
            }
            return(Json(result));
        }
Beispiel #24
0
 public void Save()
 {
     context.SaveChanges();
 }
Beispiel #25
0
 public override void AddData(int value)
 {
     _db.Records.Add(new Record(value));
     _db.SaveChanges();
 }
        public async Task <int> RecordPost(int id)
        {
            (Record record, List <Dictionary <string, string> > issues) = (null, null);
            string input;

            using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
            {
                input = await reader.ReadToEndAsync();
            }
            if (!String.IsNullOrEmpty(input))
            {
                if (input.Trim().StartsWith("<") || input.Trim().StartsWith("{")) // XML or JSON?
                {
                    (record, issues) = Record.CheckGet(input, false);
                }
                else
                {
                    try // IJE?
                    {
                        if (input.Length != 5000)
                        {
                            (record, issues) = (null, new List <Dictionary <string, string> > {
                                new Dictionary <string, string> {
                                    { "severity", "error" }, { "message", "The given input does not appear to be a valid record." }
                                }
                            });
                        }
                        IJEMortality ije         = new IJEMortality(input);
                        DeathRecord  deathRecord = ije.ToDeathRecord();
                        (record, issues) = (new Record(deathRecord), new List <Dictionary <string, string> > {
                        });
                    }
                    catch (Exception e)
                    {
                        (record, issues) = (null, new List <Dictionary <string, string> > {
                            new Dictionary <string, string> {
                                { "severity", "error" }, { "message", e.Message }
                            }
                        });
                    }
                }
                if (record != null)
                {
                    using (var db = new RecordContext())
                    {
                        Endpoint endpoint = db.Endpoints.Where(e => e.EndpointId == id).FirstOrDefault();
                        endpoint.Record   = record;
                        endpoint.Issues   = issues;
                        endpoint.Finished = true;
                        db.SaveChanges();
                        return(endpoint.EndpointId);
                    }
                }
            }
            else
            {
                issues = new List <Dictionary <string, string> > {
                    new Dictionary <string, string> {
                        { "severity", "error" }, { "message", "The given input appears to be empty." }
                    }
                };
            }

            if (record == null && issues != null)
            {
                using (var db = new RecordContext())
                {
                    Endpoint endpoint = db.Endpoints.Where(e => e.EndpointId == id).FirstOrDefault();
                    endpoint.Issues   = issues;
                    endpoint.Finished = true;
                    db.SaveChanges();
                    return(endpoint.EndpointId);
                }
            }

            return(0);
        }
Beispiel #27
0
 public bool SaveChanges()
 {
     return(_context.SaveChanges() >= 0);
 }
Beispiel #28
0
 public void AddRecord(Record record)
 {
     db.Records.Add(record);
     db.SaveChanges();
 }
 public Record Create(Record item)
 {
     _context.Add(item);
     _context.SaveChanges();
     return(item);
 }