예제 #1
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                category.Id = Guid.NewGuid();
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Email,Phone,Description,Address,Zip,CityId,Site")] Investor investor)
        {
            if (ModelState.IsValid)
            {
                investor.Id = Guid.NewGuid();
                _context.Add(investor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CityId"] = new SelectList(_context.City, "Id", "PrettyName", investor.CityId);
            return(View(investor));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Address,State,Zip,Description,Site,Phone,Email,CityId,CategoryId")] Business business)
        {
            if (ModelState.IsValid)
            {
                business.Id = Guid.NewGuid();
                _context.Add(business);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Name", business.CategoryId);
            ViewData["CityId"]     = new SelectList(_context.City, "Id", "PrettyName", business.CityId);
            return(View(business));
        }
예제 #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            //BusinessDbContext dbContext;

            var optionsBuilder = new DbContextOptionsBuilder <BusinessDbContext>();

            optionsBuilder.UseMySql("Server=localhost;database=test;uid=root;pwd=P@ssword;charset=utf8;port=3306;SslMode=None");



            TenantId tenantId = new TenantId();

            tenantId.Id = "abc";

            Guid siteId = Guid.NewGuid();


            var site = new Site();

            site.Id       = siteId;
            site.TenantId = tenantId;


            //Branding branding = new Branding();
            //branding.Id = Guid.NewGuid();
            //branding.TenantId = tenantId;
            //branding.SiteId = siteId;
            //branding.Site = site;


            using (var dbContext = new BusinessDbContext(optionsBuilder.Options))
            {
                //dbContext.Entry(site).State = EntityState.Added;
                //dbContext.Entry(site.Branding).State = EntityState.Added;

                /* not worked
                 * site.CreateBranding();
                 * dbContext.Add(site);
                 * dbContext.Entry(site.Branding).State = EntityState.Added;
                 */

                /* worked
                 * dbContext.Add(site);
                 * site.CreateBranding();
                 *
                 */

                //dbContext.Entry(site).State = EntityState.Detached;
                site.CreateBranding();
                dbContext.Add(site);
                dbContext.Entry(site).State          = EntityState.Added;
                dbContext.Entry(site.Branding).State = EntityState.Added;
                //dbContext.Entry(site.Branding.TenantId).State = EntityState.Added;
                //dbContext.Entry(site.TenantId).State = EntityState.Added;

                //site.CreateBranding();
                //dbContext

                //dbContext.Entry(site.TenantId).State = EntityState.Added;
                //site.Branding = branding; // error
                //dbContext.Entry(site).State = EntityState.Unchanged;
                //dbContext.Entry(branding).State = EntityState.Added;
                dbContext.SaveChanges();

                //var site2 = dbContext.Set<Site>().Find(siteId);

                //site2.Branding = new Branding();
                //site2.Branding.Id = Guid.NewGuid();
                //site2.Branding.TenantId = site2.TenantId;
                //site2.Branding.SiteId = site2.Id;

                //dbContext.Set<Site>().Update(site2);
                //dbContext.SaveChanges();
            }
        }