public void Save(Person entity) { if (entity.PersonId != 0) { _context.Entry(entity).State = System.Data.Entity.EntityState.Modified; } else { _context.People.Add(entity); } _context.SaveChanges(); }
public Person CreatePerson(string name, string email, string bio, Location location, ICollection<CategoryField> categories = null, ICollection<LinkField> links = null) { var person = new Person { Bio = bio, Email = email, Joined = SystemClock.UtcNow, Location = location, Name = name, Slug = name.ToSlug(), }; if (categories != null && categories.Count > 0) { person.AddCategories(categories); } if (links != null && links.Count > 0) { person.AddLinks(links); } return person; }
public Person GetOrCreatePerson(string name, string imdbId, int tmdbId) { var person = DbEntities.People.FirstOrDefault(el => el.Name == name); if (person == null) { person = new Person() { Name = name, ImdbId = imdbId, TmdbId = tmdbId }; DbEntities.AddToPeople(person); Save(); } if (!string.IsNullOrEmpty(imdbId) && !string.IsNullOrEmpty(person.ImdbId)) if (imdbId != person.ImdbId) _log.Error("GetOrCreatePerson: IMDB ID Mismatch. Name: {0} Stored ID: {1} Wanted ID: {2}", person.Name, person.ImdbId, imdbId); return person; }
// POST: api/Persons public bool Post(Person person) { _personRepository.Add(person); return _unitOfWork.Save() > 0; }
public ActionResult Edit(Person entity) { _service.Save(entity); return RedirectToAction("Index"); }
private void ScriptInString() { Console.WriteLine("Running script from string..."); var code = @" class script2class: def Goodbye(self): message = 'Goodbye via the script!' return message def GoodbyeWithName(self, name): message = 'Goodbye ' + name return message def GoodbyeWithPerson(self, person): message = 'Goodbye ' + person.Name return message"; var compiled = new Script(); compiled.InitializeFromString(code); Console.WriteLine(compiled.Execute<string>("script2class", "Goodbye")); // single param call Console.WriteLine(compiled.Execute<string>("script2class", "GoodbyeWithName", "Paulo")); // pass instance of complex type var person = new Person { Name = "Paulo Mouat", Address = "Boston" }; Console.WriteLine(compiled.Execute<string>("script2class", "GoodbyeWithPerson", person)); // duck typing var hasNameLikePerson = new HasNameLikePerson { Name = "HAL", Model = 9000 }; Console.WriteLine(compiled.Execute<string>("script2class", "GoodbyeWithPerson", hasNameLikePerson)); Console.WriteLine(); }
private void ScriptInFile() { Console.WriteLine("Running script from file..."); var script = new Script(); script.InitializeFromFile(@"..\..\..\Scripts\script1.py"); // no params call Console.WriteLine(script.Execute<string>("script1class", "Hello")); // single param call Console.WriteLine(script.Execute<string>("script1class", "HelloWithName", "Paulo")); // pass instance of complex type var person = new Person { Name = "Paulo Mouat", Address = "Boston" }; Console.WriteLine(script.Execute<string>("script1class", "HelloWithPerson", person)); // duck typing var hasNameLikePerson = new HasNameLikePerson { Name = "HAL", Model = 9000 }; Console.WriteLine(script.Execute<string>("script1class", "HelloWithPerson", hasNameLikePerson)); // change field in passed type var changeState = new Person { Name = "Paulo Mouat", Address = "Boston" }; Console.WriteLine("Original state: " + changeState); script.Execute<string>("script1class", "ChangeAddress", changeState); Console.WriteLine("New state: " + changeState); Console.WriteLine(); }