public ActionResult CreateUser(LoginModel model) { try { //this checks if there is valid data in the required fields On the SignUp page if (ModelState.IsValid) { MongoCRUD db = new MongoCRUD("BZBugs"); //This checks if the username is unique or not. if (db.CheckIfUsernameIsUnique<LoginModel>(model.Username) == true) { //Failure State ModelState.AddModelError("Username", "This Username already exists."); return View("SignUp", model); } GenerateSaltedHash(model, 64, model.Password); db.InsertRecord("Users", model); //I want to Redirect this action to something more relevant like a Profile page or something. //Success return View("~/Views/Home/Profile.cshtml", model); } //Failure State return View("SignUp", model); } catch { //Failure State return View("SignUp", model); } }
public IActionResult AgregarProductor(Productor2 nuevoProductor) { var productor = new Productor() { Cedula = int.Parse(nuevoProductor.cedula), Usuario = nuevoProductor.usuario, Nombre = nuevoProductor.nombre, direccion = nuevoProductor.direccion, dob = nuevoProductor.dob, telefono = int.Parse(nuevoProductor.telefono), SINPE = int.Parse(nuevoProductor.SINPE), pass = nuevoProductor.pass, aceptado = nuevoProductor.aceptado, productos = nuevoProductor.productos, pedidos = nuevoProductor.pedidos }; db.InsertRecord <Productor>("Productores", productor); return(CreatedAtAction(nameof(AgregarProductor), nuevoProductor)); }
public async Task <IActionResult> Create(TodoModel todo) { try { await MongoCRUD.InsertRecord("todos", todo); return(Ok()); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
public void UpdateSavedOffer(MongoCRUD db, FlatOffer flatOffer) { FlatOffer flatOfferSaved = db.LoadRecordsById <FlatOffer>(CollectionName, flatOffer.Link); if (flatOfferSaved == null) { db.InsertRecord <FlatOffer>(CollectionName, flatOffer); } else { if (flatOfferSaved.Link == flatOffer.Link && !flatOffer.Equals(flatOfferSaved)) { Console.WriteLine($"updated {flatOfferSaved.Link}"); flatOfferSaved.AddState(flatOffer.State); db.UpsertRecord <FlatOffer>(CollectionName, flatOfferSaved.Link, flatOfferSaved); } } }
public async Task <IActionResult> AddRecipe(RecipeViewModel recipe) { var model = new RecipesModel { RecipeName = recipe.RecipeName, RecipeDescription = recipe.RecipeDescription, RecipeDifficulty = recipe.RecipeDifficulty, RecipeIngredients = recipe.RecipeIngredients, RecipePrepareTime = recipe.RecipePrepareTime, RecipeServings = recipe.RecipeServings, RecipeSteps = recipe.RecipeSteps, Image = await _fileManager.SaveImage(recipe.Image) }; db.InsertRecord("Recipes", model); return(View("ShowRecipe", model)); }
private void submitButton_Click(object sender, System.EventArgs e) { if (string.IsNullOrWhiteSpace(phoneNumberText.Text)) { MessageBox.Show("You need to enter a phone number."); return; } currentPerson.FirstName = firstNameText.Text; currentPerson.LastName = lastNameText.Text; currentPerson.EmailAddress = emailText.Text; currentPerson.PhoneNumber = phoneNumberText.Text; MongoCRUD db = new MongoCRUD(databaseName); if (currentPerson.Id == Guid.Empty) { var foundPeople = db.FindRecordByNames <PersonModel>(personTable, currentPerson.FirstName, currentPerson.LastName); if (foundPeople.Count > 0) { foreach (var foundPerson in foundPeople) { currentPerson.Id = foundPerson.Id; db.UpsertRecord(personTable, foundPerson.Id, currentPerson); } } else { db.InsertRecord(personTable, currentPerson); } } else { db.UpsertRecord(personTable, currentPerson.Id, currentPerson); } firstNameText.Text = ""; lastNameText.Text = ""; emailText.Text = ""; phoneNumberText.Text = ""; currentPerson = new PersonModel(); LoadPersonData(); }
public ActionResult Create(BugsModel model) { try { if (ModelState.IsValid) { MongoCRUD db = new MongoCRUD("BZBugs"); db.InsertRecord("Bugs", model); return RedirectToAction(nameof(ListBugs)); } else { return View("CreateBug", model); } } catch { return View(); } }
public static void Run(string[] id) { MongoCRUD db = new MongoCRUD("SportService_Database"); channel catalog1 = default; int number_of_rss = 8; for (int i = 0; i < number_of_rss; i++) { string path = AppDomain.CurrentDomain.BaseDirectory + "\\Updates\\Update__done_" + id[i] + ".xml"; string xml = File.ReadAllText(path); catalog1 = xml.ParseXML <channel>(); for (int j = 0; j < 50; j++) { catalog1.item[j].link = ContentDownloader.DownloadContent(catalog1.item[j].link); } // DeserializationTest(catalog1); var a = db.LoadRecord <ChanelMongoDatabesPatern>("channels"); bool IsRepeatability = false; foreach (var item in a) { if (item.title == catalog1.title) { IsRepeatability = true; } } if (IsRepeatability) { db.UpsertRecord("channels", catalog1.title, catalog1); } else { db.InsertRecord("channels", catalog1); } } }
static void Main(string[] args) { TheVergeCrawler vergeCrawler = new TheVergeCrawler(); ViceCrawler viceCrawler = new ViceCrawler(); ICrawl crawler = viceCrawler; var list = crawler.Crawl(); MongoCRUD db = new MongoCRUD("NewsCrawl"); foreach (var title in list) { db.InsertRecord("News", title); Console.WriteLine("Title: " + title.Title + Environment.NewLine + "Url: " + title.Url + Environment.NewLine + "Author: " + title.Author + Environment.NewLine + "Date of publication: " + title.DateOfPublication + Environment.NewLine); } Console.WriteLine(""); }
public IHttpActionResult PostSubmission([FromBody] Submission body) { System.Diagnostics.Debug.WriteLine("inserting: ", body); db.InsertRecord("Submissions", body); return(Ok()); }
public void InsertUser(User user) { db.InsertRecord(userTableName, user); }
static void Main(string[] args) { MongoCRUD db = new MongoCRUD("Addresses"); Person person = new Person { FirstName = "Bob Arnold", LastName = "Johnson", DateOfBirth = new DateTime(1982, 10, 31, 0, 0, 0, DateTimeKind.Utc), PrimaryAddress = new AddressModel { StreetAddress = "111 2nd street", City = "New York", State = "NJ", Zip = "111111" }, SecondaryAddress = new AddressModel { StreetAddress = "1112 2nd street", City = "New York", State = "AA", Zip = "line" } }; db.InsertRecord("Users", person); person = new Person { FirstName = "Natalie", LastName = "Jones", DateOfBirth = new DateTime(1983, 10, 31, 0, 0, 0, DateTimeKind.Utc), PrimaryAddress = new AddressModel { StreetAddress = "2222 B street", City = "New York", State = "NJ", Zip = "111111" }, }; db.InsertRecord("Users", person); person = new Person { FirstName = "Seth", LastName = "Jones", DateOfBirth = new DateTime(1987, 10, 31, 0, 0, 0, DateTimeKind.Utc), PrimaryAddress = new AddressModel { StreetAddress = "3333 L street", City = "Town", State = "NJ", Zip = "111111" }, }; db.InsertRecord("Users", person); Console.WriteLine(); Console.WriteLine("Records one **"); Console.WriteLine(); var records = db.LoadRecords <Person>("Users"); foreach (var rec in records) { Console.WriteLine($"{rec.Id}: {rec.FirstName} {rec.LastName}"); if (rec.PrimaryAddress != null) { Console.WriteLine(rec.PrimaryAddress.StreetAddress); Console.WriteLine(rec.PrimaryAddress.State); Console.WriteLine(rec.PrimaryAddress.Zip); } Console.WriteLine(); if (rec.SecondaryAddress != null) { Console.WriteLine(rec.SecondaryAddress.StreetAddress); Console.WriteLine(rec.SecondaryAddress.State); Console.WriteLine(rec.SecondaryAddress.Zip); } Console.WriteLine(); } Console.WriteLine(); Console.WriteLine("Records two **"); Console.WriteLine(); var records2 = db.LoadRecordByField <Person>("Users", "LastName", "Jones"); foreach (var rec in records2) { Console.WriteLine($"{rec.Id}: {rec.FirstName} {rec.LastName}"); if (rec.PrimaryAddress != null) { Console.WriteLine(rec.PrimaryAddress.StreetAddress); Console.WriteLine(rec.PrimaryAddress.State); Console.WriteLine(rec.PrimaryAddress.Zip); } Console.WriteLine(); if (rec.SecondaryAddress != null) { Console.WriteLine(rec.SecondaryAddress.StreetAddress); Console.WriteLine(rec.SecondaryAddress.State); Console.WriteLine(rec.SecondaryAddress.Zip); } Console.WriteLine(); } Console.WriteLine(); Console.WriteLine("Records by last name **"); Console.WriteLine(); var record = db.LoadRecordByLastName <Person>("Users", "Jones"); Console.WriteLine($"{record.Id}: {record.FirstName} {record.LastName}"); Console.WriteLine(); record.FirstName = "Timothy"; db.UpsertRecord <Person>("Users", record.Id, record); Console.WriteLine(); Console.WriteLine("Records by last name after change **"); Console.WriteLine(); var record2b = db.LoadRecordByLastName <Person>("Users", "Jones"); Console.WriteLine($"{record2b.Id}: {record2b.FirstName} {record2b.LastName}"); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Records from address **"); Console.WriteLine(); // It doesn't seem to work to try pulling data from a child model: var records3 = db.LoadRecordByField <AddressModel>("Users", "Zip", "111111"); foreach (var rec in records3) { Console.WriteLine("Address: " + rec.StreetAddress); } Console.WriteLine(); Console.WriteLine("Records deletion **"); Console.WriteLine(); var records4 = db.LoadRecords <Person>("Users"); foreach (var rec in records4) { db.DeleteRecord <Person>("Users", rec.Id); } Console.ReadLine(); }
public void InsertDetail(Detail Detail) { db.InsertRecord(DetailTableName, Detail); }
public string List(int id = -1) { Output = ""; MongoCRUD _db = new MongoCRUD("AddressBook"); Output += "Deleting existing records.<br /><br />"; var _personRecs = _db.LoadRecords <PersonModel>("Users"); Guid _guid = new Guid("20A9A798-FE9D-4D00-836B-2186A01A6691"); foreach (var _rec in _personRecs) { _guid = _rec.Id; _db.DeleteRecord <PersonModel>("Users", _guid); } Output += "All are deleted.<br /><br />"; #region //commented out //_db.InsertRecord("Users" , new PersonModel { FirstName = "Doğan", LastName = "Kartaltepe" }); //_db.InsertRecord("Users", new PersonModel { FirstName = "Terrence", LastName = "Ritzman" }); //PersonModel _personNew = new PersonModel //{ // FirstName = "Justin", // LastName = "Kloetzer", // Address = new AddressModel // { // StreetAddress = "123 Main Street" , // City = "Austin" , // State = "Texas" , // ZipCode = "76055", // AddressType = "Primary" // } //}; //_db.InsertRecord("Users", _personNew); #endregion for (int i = 0; i <= 15; i++) { var _p = new PersonModel() { FirstName = Generate.RandomFirstName(), LastName = Generate.RandomLastName(), Address = new AddressModel() { StreetAddress = Generate.RandomAddress(), City = Generate.RandomCityName(), State = Generate.RandomStateName(), ZipCode = Generate.RandomZip(), AddressType = "Primary" }, // DateOfBirth = new DateTime(Generate.RandomInteger(1950, 2012), Generate.RandomInteger(1, 2), Generate.RandomInteger(1, 30), 0, 0, 0, DateTimeKind.Utc) DateOfBirth = Generate.RandomDate(1950, 2012) }; _db.InsertRecord("Users", _p); } #region //PERSONMODEL _personRecs = _db.LoadRecords <PersonModel>("Users"); foreach (var _rec in _personRecs) { _guid = _rec.Id; OutputPerson(_rec); Output += "<br />"; } var _person = _db.LoadRecordById <PersonModel>("Users", _guid); OutputPerson(_person); Output += "<br />"; _person.DateOfBirth = Generate.RandomDate(1950, 2012); // new DateTime(Generate.RandomInteger(1950,2012), 1, 1, 0, 0, 0, DateTimeKind.Utc); _db.UpsertRecord("Users", _person.Id, _person); OutputPerson(_person); #endregion //PERSONMODEL #region //NAMEMODEL //var _recsName = _db.LoadRecords<NameModel>("Users"); //foreach (var _rec in _recsName) //{ // _guid = _rec.Id; // OutputName(_rec); // Console.WriteLine("\n"); //} //var _name = _db.LoadRecordById<NameModel>("Users", _guid); #endregion //NAMEMODEL return(Output); }
static void Main(string[] args) { MongoCRUD _db = new MongoCRUD("AddressBook"); Console.WriteLine("Deleting existing records.\n\n"); var _personRecs = _db.LoadRecords <PersonModel>("Users"); Guid _guid = new Guid("20A9A798-FE9D-4D00-836B-2186A01A6691"); foreach (var _rec in _personRecs) { _guid = _rec.Id; _db.DeleteRecord <PersonModel>("Users", _guid); } Console.WriteLine("All are deleted.\n\n"); #region //commented out //_db.InsertRecord("Users" , new PersonModel { FirstName = "Doğan", LastName = "Kartaltepe" }); //_db.InsertRecord("Users", new PersonModel { FirstName = "Terrence", LastName = "Ritzman" }); //PersonModel _personNew = new PersonModel //{ // FirstName = "Justin", // LastName = "Kloetzer", // Address = new AddressModel // { // StreetAddress = "123 Main Street" , // City = "Austin" , // State = "Texas" , // ZipCode = "76055", // AddressType = "Primary" // } //}; //_db.InsertRecord("Users", _personNew); #endregion for (int i = 0; i <= 15; i++) { var _p = new PersonModel() { FirstName = Generate.RandomFirstName(), LastName = Generate.RandomLastName(), Address = new AddressModel() { StreetAddress = Generate.RandomAddress(), City = Generate.RandomCityName(), State = Generate.RandomStateName(), ZipCode = Generate.RandomZip(), AddressType = "Primary" }, DateOfBirth = Generate.RandomDate(1950, 2012) }; _db.InsertRecord("Users", _p); } #region //PERSONMODEL _personRecs = _db.LoadRecords <PersonModel>("Users"); foreach (var _rec in _personRecs) { _guid = _rec.Id; OutputPerson(_rec); Console.WriteLine("\n"); } var _person = _db.LoadRecordById <PersonModel>("Users", _guid); OutputPerson(_person); Console.WriteLine(""); _person.DateOfBirth = Generate.RandomDate(1950, 2012); _db.UpsertRecord("Users", _person.Id, _person); OutputPerson(_person); #endregion //PERSONMODEL #region //NAMEMODEL //var _recsName = _db.LoadRecords<NameModel>("Users"); //foreach (var _rec in _recsName) //{ // _guid = _rec.Id; // OutputName(_rec); // Console.WriteLine("\n"); //} //var _name = _db.LoadRecordById<NameModel>("Users", _guid); #endregion //NAMEMODEL Console.WriteLine("\n\nPress the any key"); Console.ReadLine(); }