public IActionResult AddNewPerson(Person personIn) { ViewData["Message"] = "You Have added :"; context.Add(personIn); context.SaveChanges(); return(View(personIn)); }
public async Task <CustomerDetailItem> CreateCustomerAsync([FromBody] CustomerPayloadItem payload) { var dbItem = new Customer { Id = Guid.NewGuid(), City = payload.City, CountryId = payload.Country.Id, FirstName = payload.FirstName, LastName = payload.LastName, Phone = payload.Phone, Street = payload.Street, ZipCode = payload.ZipCode, Created = DateTime.UtcNow, }; _db.Add(dbItem); var entry = _db.Entry(dbItem); entry.UpdateAdditionalProperties(payload); await _db.SaveChangesAsync(); return(await GetCustomerDetailItemAsync(dbItem.Id)); }
public async Task <IActionResult> Create([Bind("FullName,Phone,Email,Company,Status,Id,DateCreated,CreatedBy")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("Description,IsBinary,Id,DateCreated,CreatedBy")] Question question) { if (ModelState.IsValid) { _context.Add(question); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(question)); }
public async Task <CountryInfo> CreateCountryAsync([FromBody] CountryPayload payload) { var dbItem = new Country { Id = Guid.NewGuid(), Name = payload.Name, Iso3 = payload.Iso3, }; _db.Add(dbItem); await _db.SaveChangesAsync(); return(await GetCountryInfoByIdAsync(dbItem.Id)); }
public async Task AddPropertyAsync(string entityName, [FromQuery] string propertyName, [FromQuery] PropertyType propertyType, [FromQuery] bool isNullable) { var dbEntiy = _db.Model.FindEntityType(entityName); MetadataModel model = null; var customization = await _db.Customizations.OrderByDescending(p => p.Id).FirstOrDefaultAsync(); if (customization != null) { var entities = JsonSerializer.Deserialize <IEnumerable <EntityMetadata> >(customization.Metadata); model = new MetadataModel(customization.Id, entities); } else { model = new MetadataModel(0, new EntityMetadata[] { }); } EntityMetadata entity = model.Entities.FirstOrDefault(p => p.EntityName == entityName); if (entity == null) { entity = new EntityMetadata(entityName, new PropertyMetadata[] { }); model.Entities.Add(entity); } var prop = new PropertyMetadata(propertyName, isNullable, propertyType); entity.Properties.Add(prop); var addColumn = new AddColumnOperation { Name = propertyName, ClrType = CrmContext.GetClrType(prop), IsNullable = prop.IsNullable, Table = dbEntiy.GetTableName(), Schema = dbEntiy.GetSchema(), }; var generator = ((IInfrastructure <IServiceProvider>)_db).Instance.GetRequiredService <IMigrationsSqlGenerator>(); var scripts = generator.Generate(new[] { addColumn }); await using (var transaction = await _db.Database.BeginTransactionAsync()) { foreach (var script in scripts) { await _db.Database.ExecuteSqlRawAsync(script.CommandText); } var dbCustomization = new Customization { Created = DateTime.UtcNow, Metadata = JsonSerializer.Serialize(model.Entities) }; _db.Add(dbCustomization); await _db.SaveChangesAsync(); var newId = dbCustomization.Id; var newModel = new MetadataModel(newId, model.Entities); await transaction.CommitAsync(); _setter.SetModel(newModel); } }