Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("BlogId,Url")] Blog blog)
        {
            if (ModelState.IsValid)
            {
                _context.Add(blog);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(blog));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("PostId,Title,ShortDescription,Description,Meta,Url,Published,PostedOn,Modified,ImagePath")] Post post)
        {
            if (ModelState.IsValid)
            {
                _context.Add(post);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(post));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("Id,UserName,Password,UserMail,CreateDate,Active")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Esempio n. 4
0
 public void CreateBlog(string url, string author)
 {
     using (var db = new BloggingContext())
     {
         var blog = new Blog();
         blog.Url    = url;
         blog.Author = author;
         db.Add(blog);
         db.SaveChanges();
     }
 }
Esempio n. 5
0
        public async Task <IActionResult> Create([Bind("ClienteId,NomeFantasia,RazaoSocial,CNPJ,InscricaoEstadual,Endereco,Numero,Complemento,Bairro,Cidade,UF,CEP")] Cliente cliente)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cliente);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cliente));
        }
Esempio n. 6
0
        public async Task <PartialViewResult> Create([Bind("BlogId,Url")] Blog blog)
        {
            if (ModelState.IsValid)
            {
                _context.Add(blog);
                await _context.SaveChangesAsync();

                return(PartialView("Index", _context.Blogs.ToList()));
            }
            return(PartialView(blog));
        }
        public async Task <IActionResult> Create([Bind("RssUrl,BlogId,Name,Url,BlogType,Timestamp")] RssBlog rssBlog)
        {
            if (ModelState.IsValid)
            {
                _context.Add(rssBlog);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(rssBlog));
        }
Esempio n. 8
0
        public async Task <IActionResult> Create([Bind("UniversiteId,UniversiteAdi")] Universite universite)
        {
            if (ModelState.IsValid)
            {
                _context.Add(universite);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(universite));
        }
Esempio n. 9
0
        public async Task <IActionResult> Create([Bind("Id,Name,UrlSlug,Description")] Tag tag)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tag);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tag));
        }
Esempio n. 10
0
        public async Task <IActionResult> Post([FromBody] Comment Comment, string email = "*****@*****.**")
        {
            if (Comment.CommentId == 0)
            {
                _bloggingContext.Add(Comment);
            }

            _bloggingContext.SaveChanges();

            return(CreatedAtRoute("GetComment", new { id = Comment.CommentId }, Comment));
        }
        public async Task <IActionResult> Create([Bind("IndirizzoId,NomeIndirizzo,Città,Nazione,CAP,AnagraficaId")] Indirizzo indirizzo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(indirizzo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AnagraficaId"] = new SelectList(_context.Anagrafiche, "AnagraficaId", "AnagraficaId", indirizzo.AnagraficaId);
            return(View(indirizzo));
        }
Esempio n. 12
0
 public void CreatePost(int blogId, string title, string context)
 {
     using (var db = new BloggingContext())
     {
         var post = new Post();
         post.BlogId  = blogId;
         post.Title   = title;
         post.Content = context;
         db.Add(post);
         db.SaveChanges();
     }
 }
Esempio n. 13
0
        public async Task <IActionResult> Create([Bind("BolumId,BolumAdi,Aciklama,UniversiteId")] Bolum bolum)
        {
            if (ModelState.IsValid)
            {
                _context.Add(bolum);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UniversiteId"] = new SelectList(_context.Universiteler, "UniversiteId", "UniversiteId", bolum.UniversiteId);
            return(View(bolum));
        }
        public async Task <IActionResult> Create([Bind("PostId,Title,Content,BlogId")] Post post)
        {
            if (ModelState.IsValid)
            {
                _context.Add(post);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BlogId"] = new SelectList(_context.Blogs, "BlogId", "BlogId", post.BlogId);
            return(View(post));
        }
        public async Task <IActionResult> Create([Bind("EmployeeId,Name,Address,Mobile,DepartmentId")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            //ViewData["DepartmentId"] = new SelectList(_context.Department, "DepartmentId", "DepartmentId", employee.DepartmentId);
            return(View(employee));
        }
Esempio n. 16
0
        public async Task <IActionResult> Create([Bind("Id,RoleName,UserId")] Role role)
        {
            if (ModelState.IsValid)
            {
                _context.Add(role);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", role.UserId);
            return(View(role));
        }
Esempio n. 17
0
        static void AddBlog(string url = "https://myblog.com/new-blog")
        {
            var blog = new Blog
            {
                Url = url
            };

            using (var db = new BloggingContext())
            {
                db.Add(blog);
                db.SaveChanges();
            }
        }
Esempio n. 18
0
        public async Task <IActionResult> Create([Bind("PostId,TagId")] PostTag postTag)
        {
            if (ModelState.IsValid)
            {
                _context.Add(postTag);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PostId"] = new SelectList(_context.Posts, "PostId", "PostId", postTag.PostId);
            ViewData["TagId"]  = new SelectList(_context.Set <Tag>(), "Id", "Id", postTag.TagId);
            return(View(postTag));
        }
 private static void SetupDatabase()
 {
     using (var db = new BloggingContext())
     {
         db.Database.EnsureDeleted();
         db.Database.EnsureCreated();
         var blog = new Blog {
             Name = "Saikiran's Blog", Url = "http://www.saikiranpotru.blogspot.com"
         };
         db.Add(blog);
         db.SaveChanges();
     }
 }
Esempio n. 20
0
 private static void SetupDatabase()
 {
     using (var db = new BloggingContext())
     {
         db.Database.EnsureDeleted();
         db.Database.EnsureCreated();
         var blog = new Blog {
             Name = "Skimedic's Blog", Url = "http://skimedic.com"
         };
         db.Add(blog);
         db.SaveChanges();
     }
 }
Esempio n. 21
0
        static void Main(string[] args)
        {
            using (var dbContext = new BloggingContext())
            {
                dbContext.Add(new Blog {
                    Url = "www.google.com"
                });
                dbContext.SaveChanges();

                var blog = dbContext.Find <Blog>(1);
                Console.WriteLine($"Id:{blog.Id},Url={blog.Url}");
            }
        }
        public void Should_Throw_Retry_Limit_Exceeded_Exception()
        {
            BloggingContext db = SetUpContext(true);

            using (db)
            {
                var blog = new Blog {
                    Name = "Skimedic's Blog", Url = "http://skimedic.com"
                };
                db.Add(blog);
                Assert.Throws <RetryLimitExceededException>(() => db.SaveChanges());
            }
        }
Esempio n. 23
0
 public ActionResult <Blog> Create(Blog blog)
 {
     try
     {
         bloggingContext.Add(blog);
         bloggingContext.SaveChanges();
         return(Created("Blog", blog));
     }
     catch (System.Exception)
     {
         throw;
     }
 }
        public async System.Threading.Tasks.Task Generate_Insert_For_Single_Entity()
        {
            using (var testDatabase = SqlServerTestStore.Create(DatabaseName))
            {
                var loggingFactory  = new TestSqlLoggerFactory();
                var serviceProvider = new ServiceCollection()
                                      .AddEntityFrameworkSqlServer()
                                      .AddSingleton <ILoggerFactory>(loggingFactory)
                                      .BuildServiceProvider();

                var optionsBuilder = new DbContextOptionsBuilder()
                                     .EnableSensitiveDataLogging()
                                     .UseSqlServer(testDatabase.ConnectionString, b => b.ApplyConfiguration())
                                     .UseInternalServiceProvider(serviceProvider);

                using (var db = new BloggingContext(optionsBuilder.Options))
                {
                    await CreateBlogDatabaseAsync <Blog>(db);
                }

                loggingFactory.Clear();

                using (var db = new BloggingContext(optionsBuilder.Options))
                {
                    var toAdd = db.Add(new Blog
                    {
                        Name       = "Blog to Insert",
                        George     = true,
                        TheGu      = new Guid("0456AEF1-B7FC-47AA-8102-975D6BA3A9BF"),
                        NotFigTime = new DateTime(1973, 9, 3, 0, 10, 33, 777),
                        ToEat      = 64,
                        OrNothing  = 0.123456789,
                        Fuse       = 777,
                        WayRound   = 9876543210,
                        Away       = 0.12345f,
                        AndChew    = new byte[16]
                    }).Entity;

                    var statement = db.Generate();

                    var reader = new StringReader(statement);
                    IList <ParseError> errors;
                    var parser = new TSql140Parser(false);

                    var parseResult = parser.Parse(reader, out errors);

                    Assert.IsFalse(errors.Any());
                }
            }
        }
Esempio n. 25
0
        public Blog Create(Blog newBlog)
        {
            var createBlog = new Blog {
                Url = newBlog.Url
            };

            // Create
            Console.WriteLine("Inserting a new blog");
            _context.Add(createBlog);
            _context.SaveChanges();


            return(createBlog);
        }
Esempio n. 26
0
        public Post Create(Post newPost)
        {
            var createPost = new Post {
                Title = newPost.Title, Content = newPost.Content, BlogId = newPost.BlogId
            };

            // Create
            Console.WriteLine("Inserting a new Post");
            _context.Add(createPost);
            _context.SaveChanges();


            return(createPost);
        }
Esempio n. 27
0
        public IActionResult Add([FromForm] string jstr, [FromForm] string Title)
        {
            //string res = a.Content.ReadAsAsync();
            //string jstr = "";
            string t = Title.Trim();
            Post   b = JsonConvert.DeserializeObject <Post>(jstr);

            using (var db = new BloggingContext())
            {
                db.Add(b);
                var count = db.SaveChanges();
                Console.WriteLine();
            }
            return(Ok("done"));
        }
        public async Task <IActionResult> Create([Bind("DepartmentId,Name")] Department department)
        {
            if (ModelState.IsValid)
            {
                if (_context.Department.Where(v => v.Name == department.Name).ToList().Count > 0)
                {
                    return(View(department));
                }
                _context.Add(department);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(department));
        }
Esempio n. 29
0
        public IActionResult Index(string blogTitle, string blogpost)
        {
            using (var db = new BloggingContext())
            {
                db.Add(
                    new Post
                {
                    Title   = blogTitle,
                    Content = blogpost
                });
                db.SaveChanges();
            }

            return(View(GetPosts()));
        }
Esempio n. 30
0
        public void IfChangesImmediatelyAccessible()
        {
            var context      = new BloggingContext();
            var newSuperBlog = new Blog()
            {
                Url = "testUrl"
            };

            context.Add(newSuperBlog);

            //before saveChanges data is not accessible for query
            context.SaveChanges();

            var blogQueried = context.Blogs.Where(blog => blog.Url == "testUrl").FirstOrDefault();

            Assert.NotNull(blogQueried);
        }