public ActionResult addNewContacts(Contact model) { if (ModelState.IsValid) { Random random = new Random(); int num = random.Next(1000000); var currentUserId = User.Identity.GetUserId(); var user = dbapp.Users.FirstOrDefault(p => p.Id == currentUserId); var pOne = db.Persons.FirstOrDefault(p => p.Email == user.Email); var personId = pOne.id; var contact = new Contact { Id = num, ContactId = num, FirstName = model.FirstName, LastName = model.LastName, DateMet = model.DateMet, PersonId = personId, Mobile = model.Mobile, Email = model.Email, DistanceKept = model.DistanceKept, TimeSpent = model.TimeSpent }; var contactEntity = db.Contacts.Add(contact); db.SaveChanges(); return(RedirectToAction("MyContacts")); } return(View()); }
public IHttpActionResult PutPerson(int id, Person person) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != person.Id) { return(BadRequest()); } db.Entry(person).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PersonExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
private void btnDel_Click(object sender, RoutedEventArgs e) { context.People.Remove(view.CurrentItem as Person); ObservableCollection <Person> people = this.DataContext as ObservableCollection <Person>; people.Remove(view.CurrentItem as Person); context.SaveChanges(); //MessageBox.Show(people.Count.ToString()); //view.MoveCurrentToNext(); }
public ActionResult Create([Bind(Include = "ID,Nama,Email,Nope")] PersonDB personDB) { if (ModelState.IsValid) { db.Persons.Add(personDB); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(personDB)); }
public ActionResult Create([Bind(Include = "ID,firstName,surname,DOB")] PersonInfo personInfo) { if (ModelState.IsValid) { db.PersonInfo.Add(personInfo); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(personInfo)); }
public ActionResult Create([Bind(Include = "ID,Name,SubName,Email,ReleaseDate")] Person person) { if (ModelState.IsValid) { db.Persons.Add(person); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(person)); }
public ActionResult Post([FromBody] Employees employee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Add(employee); _context.SaveChanges(); return(Ok()); }
public ActionResult Post(Person model) { try { _context.Person.Add(model); _context.SaveChanges(); return(Ok("Bazinga!")); } catch (Exception ex) { return(BadRequest($"Error : {ex}")); } }
public ActionResult Register(string username, string first_name, string last_name, string email, string password, string confirmpassword) { if (password != confirmpassword) { return(View()); } if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(username, password, email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(username, false /* createPersistentCookie */); PersonDB stu = new PersonDB(); stu.student_id = username; stu.first_name = first_name; stu.last_name = last_name; stu.email = email; person.Persons.Add(stu); person.SaveChanges(); return(RedirectToAction("Init", "Home")); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return(View()); }
private void btnadd_Click(object sender, RoutedEventArgs e) { context.People.Add(p); context.SaveChanges(); people.Add(p); this.Close(); }
static void Main(string[] args) { try { ManageDatabase(); using (var ctx = new PersonDBContext()) { var person = new Person() { PersonName = "Rajneesh", Gender = "Male", Age = 30 }; ctx.Persons.Add(person); ctx.SaveChanges(); Console.WriteLine("Added person"); foreach (var p in ctx.Persons.ToList()) { // Use interpolation in C# 6.0 // This is equavalent to String builter. Mutable string object Console.WriteLine($"{p.PersonId} {p.PersonName} {p.Age} {p.Gender}"); } } } catch (Exception ex) { Console.WriteLine($"{ex.Message}"); } Console.ReadLine(); }
public void DeleteRelatedPerson(PersonModel person, PersonModel relatedPerson) { using (var db = new PersonDBContext()) { var dbModel = db.PersonToPerson.Single(a => a.PersonId == person.Id && a.RelatedPersonId == relatedPerson.Id); db.PersonToPerson.Remove(dbModel); db.SaveChanges(); } }
// PUT api/Person/5 public HttpResponseMessage PutPerson(int id, Person person) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != person.Id) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } db.Entry(person).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
private void Seed() { var context = new PersonDBContext(ContextOptions); context.Database.EnsureDeleted(); context.AddRange( new Person(111, "FirstName1", "LastName1"), new Person(112, "FirstName1", "LastName2") ); context.SaveChanges(); }
public void AddRelatedPerson(PersonModel person, PersonModel relatedPerson, int relationTypeId) { using (var db = new PersonDBContext()) { var model = new PersonToPerson(); model.PersonId = person.Id; model.RelatedPersonId = relatedPerson.Id; model.RelationTypeId = relationTypeId; db.Add(model); db.SaveChanges(); } }
public ActionResult Create(Person person, HttpPostedFileBase file) { if (ModelState.IsValid) { string filename = ""; byte[] bytes; int bytesToRead; int numBytesRead; if (file != null) { filename = Path.GetFileName(file.FileName); bytes = new byte[file.ContentLength]; bytesToRead = (int)file.ContentLength; numBytesRead = 0; while (bytesToRead > 0) { int n = file.InputStream.Read(bytes, numBytesRead, bytesToRead); if (n == 0) { break; } numBytesRead += n; bytesToRead -= n; } person.Image = bytes; } db.People.Add(person); db.SaveChanges(); return(RedirectToAction("Index")); } return(View("Create", person)); }
/// <summary> /// The perform database operations. /// </summary> public static void PerformDatabaseOperations() { using (var db = new PersonDBContext()) { var person = new Person { FirstName = "Biju", LastName = "Joseph", BirthDate = DateTime.Now }; db.Persons.Add(person); db.SaveChanges(); } }
public void AddPerson(Person person) { using var db = new PersonDBContext(); var newPerson = new Person() { FirstName = person.FirstName, LastName = person.LastName, Position = person.Position, StartDate = person.StartDate, DateEnd = person.DateEnd }; db.People.Add(newPerson); db.SaveChanges(); }
public ActionResult Accept(int id) { PersonDB stu1, stu2; string tmp = ""; stu1 = person.Persons.Find(User.Identity.Name); foreach (var p in person.Persons.ToList()) { if (p.item_now == id) { tmp = p.student_id; break; } } stu2 = person.Persons.Find(tmp); DealDB t1 = new DealDB(); DealDB t2 = new DealDB(); t1.from = stu1.student_id; t1.to = stu2.student_id; t1.item = stu1.item_now; t1.deal_time = DateTime.Now; deal.Deals.Add(t1); t2.from = stu2.student_id; t2.to = stu1.student_id; t2.item = stu2.item_now; t2.deal_time = DateTime.Now; deal.Deals.Add(t2); deal.SaveChanges(); int k; k = stu1.item_now; stu1.item_now = stu2.item_now; stu2.item_now = k; person.SaveChanges(); foreach (var r in request.Requests.ToList()) { if (r.from == stu1.student_id || r.from == stu2.student_id) { request.Requests.Remove(r); } } request.SaveChanges(); return(RedirectToAction("Detail", "Item", new { id = id })); }
public void UpdatePerson(PersonModel person) { using (var db = new PersonDBContext()) { var dbModel = db.Person.Single(a => a.Id == person.Id); dbModel.FirstName = person.FirstName; dbModel.LastName = person.LastName; dbModel.PersonalNumber = person.PersonalNumber; dbModel.GenderiD = person.GenderiD; dbModel.CityId = person.CityId; dbModel.BirthDate = person.BirthDate; dbModel.ImagePath = person.ImagePath ?? dbModel.ImagePath; db.Update(dbModel); db.SaveChanges(); } }
public ActionResult Init(string item_name, string item_description) { ItemDB it = new ItemDB(); it.name = item_name; it.description = item_description; item.Items.Add(it); item.SaveChanges(); PersonDB stu = person.Persons.Find(User.Identity.Name); stu.item_now = it.id; stu.item_original = it.id; person.SaveChanges(); return(RedirectToAction("Index")); }
public Contact AddContact(Contact contact) { var newcontact = new Contact { Id = contact.Id, ContactId = contact.ContactId, FirstName = contact.FirstName, LastName = contact.LastName, DateMet = contact.DateMet, PersonId = contact.PersonId, Mobile = contact.Mobile, Email = contact.Email, DistanceKept = contact.DistanceKept, TimeSpent = contact.TimeSpent }; var contactEntity = db.Contacts.Add(newcontact); db.SaveChanges(); return(newcontact); }
public int CreatePerson(PersonModel person) { using (var db = new PersonDBContext()) { var model = new Person { FirstName = person.FirstName, LastName = person.LastName, PersonalNumber = person.PersonalNumber, GenderiD = person.GenderiD, CityId = person.CityId, BirthDate = person.BirthDate, ImagePath = person.ImagePath }; db.Add(model); db.SaveChanges(); return(model.Id); } }
public static void Main(string[] args) { //JSON configuration var options = new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true, AllowTrailingCommas = true }; //KAFKA configuration var conf = new ConsumerConfig { GroupId = "test-consumer-group", BootstrapServers = "127.0.0.1:9092", AutoOffsetReset = AutoOffsetReset.Earliest }; var cts = new CancellationTokenSource(); Console.CancelKeyPress += (_, e) => { e.Cancel = true; cts.Cancel(); }; try { using var c = new ConsumerBuilder <Ignore, string>(conf).Build(); { c.Subscribe("test-topic"); try { while (true) { try { var cr = c.Consume(cts.Token); //Deserializing JSON message string jsonString = cr.Message.Value; var resultA = JsonSerializer.Deserialize <FundoInvest>(jsonString, options); //Creating NEW object into database using (var db = new PersonDBContext()) { var person = new Person { Agencia = resultA.opr_rec_inf.agencia, Conta = resultA.opr_rec_inf.conta, Cotista = new List <Cotista> { new Cotista { CodFundo = resultA.opr_rec_inf.codFundo, ComunicEletr = resultA.opr_rec_inf.comunicEletr }, } }; db.Person.Add(person); db.SaveChanges(); Console.WriteLine($"'{person.Agencia}','{person.Conta}','{person.Cotista}'"); }; } catch (ConsumeException e) { Console.WriteLine($"Error occured: {e.Error.Reason}"); } } } catch (OperationCanceledException) { c.Close(); } } } catch (ConsumeException e) { Console.WriteLine($"Error occured: {e.Error.Reason}"); } }
public void Add(Person newperson) { context.Add(newperson); context.SaveChanges(); }