コード例 #1
0
        public async Task <Models.Author> DeleteAuthor(int id)
        {
            var result = await _authorRepository.DeleteAuthor(id);

            Models.Author authorModel = _mapper.Map <Models.Author>(result);
            return(authorModel);
        }
コード例 #2
0
        public async Task <Models.Author> PutAuthor(int id, Models.Author author)
        {
            Data.Entities.Author authorEnt    = _mapper.Map <Data.Entities.Author>(author);
            Data.Entities.Author authorReturn = await _authorRepository.PutAuthor(id, authorEnt);

            return(_mapper.Map <Models.Author>(authorReturn));
        }
コード例 #3
0
        public ActionResult Register(Models.Register reg)
        {
            //post action receives a Register object

            //1. check to see if the username is already in use
            if (Membership.GetUser(reg.Username) == null)
            {
                //username is valid, so add the user to the database
                Membership.CreateUser(reg.Username, reg.Password);
                //add the user to our myBlog authors table
                Models.Author author = new Models.Author();
                //set the properties of our author object
                author.Username = reg.Username;
                author.Name     = reg.Name;
                author.ImageURL = reg.ImageURL;
                //add the author to the database.
                db.Authors.Add(author);
                db.SaveChanges();
                //Log the user in
                FormsAuthentication.SetAuthCookie(reg.Username, false);
                //kick the user back to the landing page.
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                //username is already in use, send a message
                //to the view to let the user know
                ViewBag.Error = "Username is already in use, good sir.  Please choose another.";
                //return the view, with the reg object
                return(View(reg));
            }
        }
コード例 #4
0
        public async Task <IActionResult> FindOrCreate()
        {
            var id   = User.Claims.FirstOrDefault(c => c.Type == JwtRegisteredClaimNames.Sub)?.Value;
            var name = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value;

            if (id == null || name == null)
            {
                return(BadRequest());
            }

            var author = await RRRepo.GetAuthorByGoogleId(id);

            if (author != null)
            {
                return(Ok(new {
                    Success = true,
                    Id = author.Id
                }));
            }

            author = new Models.Author()
            {
                GoogleId = id,
                Name     = name
            };

            await RRRepo.AddAuthorAsync(author);

            return(Ok(new
            {
                Success = true,
                Id = author.Id
            }));
        }
コード例 #5
0
        public ActionResult Register(Models.Registration register, HttpPostedFileBase Image)
        {
            if (Image != null)
            {
                //save the image to the website
                //Guid characters used to make sure the file name is not repeated so that the file  is not overwritten
                string fileName = Guid.NewGuid().ToString().Substring(0, 6) + Image.FileName;
                //specify the path to save the file to
                string path = Path.Combine(Server.MapPath("~/content/"), fileName);
                //Save the file
                Image.SaveAs(path);
                //update our registration object with the image
                register.Image = "/content/" + fileName;
            }
            //create our Membership user
            Membership.CreateUser(register.UserName, register.Password);
            //create our Author object
            Models.Author author = new Models.Author();

            author.Name     = register.Name;
            author.ImageUrl = register.Image;
            author.UserName = register.UserName;

            //add the author to the database
            db.Authors.Add(author);
            db.SaveChanges();

            //registration complete Log in the user
            FormsAuthentication.SetAuthCookie(register.UserName, false);

            return(RedirectToAction("Index", "Posts"));
        }
コード例 #6
0
        public ActionResult Register(Models.Registration registration, HttpPostedFileBase ImageURL)
        {
            if (ImageURL != null)
            {
                //save the image to our website
                string filename = Guid.NewGuid().ToString().Substring(0, 6) + ImageURL.FileName;
                //specify the path to save the file to
                string path = Path.Combine(Server.MapPath("~/content/"), filename);
                //save the file
                ImageURL.SaveAs(path);
                //update our regisration object, with the Image
                registration.ImageURL = "/content/" + filename;
            }
            //create our Membership user
            Membership.CreateUser(registration.UserName, registration.Password);
            //create our author object
            Models.Author author = new Models.Author();
            author.Name     = registration.Name;
            author.ImageURL = registration.ImageURL;
            author.UserName = registration.UserName;
            //add the author to the database
            db.Authors.Add(author);
            db.SaveChanges();

            //registration complete, log in the user
            FormsAuthentication.SetAuthCookie(registration.UserName, false);

            //kick the user to the create post section
            return(RedirectToAction("Index", "Post"));
        }
コード例 #7
0
        public async Task <IActionResult> PutAuthor(int id, Models.Author author)
        {
            if (id == null)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Could not found the ID: " + id));
            }

            if (id != author.AuthorId)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Could not found the ID: " + id));
            }

            try
            {
                await _authorService.PutAuthor(id, author);

                return(StatusCode(StatusCodes.Status200OK, "Author succesfully updated! "));
            }
            catch (DbUpdateConcurrencyException)
            {
                Models.Author authorModel = await _authorService.GetAuthor(id);

                if (authorModel == null)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
コード例 #8
0
        public ActionResult Register(Models.Registration registration, HttpPostedFileBase Image)
        {
            if (Image != null)
            {
                //save the image to our website
                //GUID generates random characters, that we
                // can use to make sure the file name is not
                // repeated
                string filename = Guid.NewGuid().ToString().Substring(0, 6) + Image.FileName;
                //specify the path to save the file to.
                // Server.MapPath actually gets the physical
                //  location of the website on the server
                string path = Path.Combine(Server.MapPath("~/content/"), filename);
                // SAVE the file
                Image.SaveAs(path);
                //update our registration object, with the Image
                registration.Image = "/content/" + filename;
            }
            //create our Membership user
            Membership.CreateUser(registration.Username, registration.Password);
            //create and populate our Author object
            Models.Author author = new Models.Author();
            author.Name     = registration.Name;
            author.ImageUrl = registration.Image;
            author.UserName = registration.Username;
            //add the author to the database
            db.Authors.Add(author);
            db.SaveChanges();

            //registration complete!  Log in the user
            FormsAuthentication.SetAuthCookie(registration.Username, false);

            //kick the user to the create post section
            return(RedirectToAction("Index", "Post"));
        }
コード例 #9
0
ファイル: AccountController.cs プロジェクト: kpbarry/MyBlog
        public ActionResult Register(Models.Registration reg, HttpPostedFileBase Image)
        {
            if (Image != null)
            {
                // Save the image to our site
                string filename = Guid.NewGuid().ToString().Substring(0, 6) + Image.FileName;
                // Specify the path to save the file to
                string path = Path.Combine(Server.MapPath("~/content/"), filename);
                // Save the file
                Image.SaveAs(path);
                // Update registration object with the Image
                reg.Image = "/content/" + filename;
            }
            // Create our Membership user
            Membership.CreateUser(reg.Username, reg.Password);
            // Create our author object
            Models.Author author = new Models.Author();
            author.Name     = reg.Name;
            author.ImageUrl = reg.Image;
            author.Username = reg.Username;

            // Add author to db
            db.Authors.Add(author);
            db.SaveChanges();

            // Log in the user
            FormsAuthentication.SetAuthCookie(reg.Username, false);
            return(RedirectToAction("Index", "Post"));
        }
コード例 #10
0
        public async Task <Models.Author> GetAuthor(int?id)
        {
            var result = await _authorRepository.GetAuthor(id);

            Models.Author author = _mapper.Map <Models.Author>(result);
            return(author);
        }
コード例 #11
0
        public async Task <bool> CreateAsync(Models.Author author, HttpRequest request)
        {
            await _authors.InsertOneAsync(author);

            var query = _authors.Find(author => true).SortByDescending(x => x.CreateAt);

            return(true);
        }
コード例 #12
0
        public ActionResult Update(Models.Author author)
        {
            Data.Author persistentAuthor = Mapper.Map <Models.Author, Data.Author>(author);
            Authoring.UpdateAuthor(persistentAuthor);

            Caching.UpdateAuthor(persistentAuthor);

            return(Content(JsonConvert.SerializeObject(Mapper.Map <Data.Author, Models.Author>(persistentAuthor))));
        }
コード例 #13
0
        public async Task <Models.Author> PostAuthor(Models.Author author)
        {
            _logger.LogInformation($" ***** Inicia.");
            Data.Entities.Author authorEnt = _mapper.Map <Data.Entities.Author>(author);
            var result = await _authorRepository.PostAuthor(authorEnt);

            Models.Author authorModel = _mapper.Map <Models.Author>(result);
            return(authorModel);
        }
コード例 #14
0
        public async Task <ActionResult <Models.Author> > PostAuthor(Models.Author author)
        {
            if (author == null)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "Bad request, verify the Author's Information "));
            }

            return(await _authorService.PostAuthor(author));
        }
コード例 #15
0
        public async Task <bool> EditAuthorAsync(Models.Author author)
        {
            HttpClient          client   = HttpClients.GetInstance();
            HttpResponseMessage response = await client.PutAsJsonAsync("authors/update/", author);

            if (!response.IsSuccessStatusCode)
            {
                return(false);;
            }
            return(true);
        }
コード例 #16
0
        public IActionResult Featured()
        {
            // we would normally get this from a database
            var featuredAuthor = new Models.Author()
            {
                AuthorID = 1,
                Name     = "J.K. Rowling"
            };

            return(View(featuredAuthor));
        }
コード例 #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RenderBlogPostAuthorViewModel" /> class.
 /// </summary>
 /// <param name="author">The author.</param>
 public RenderBlogPostAuthorViewModel(Models.Author author = null)
 {
     if (author != null)
     {
         Id      = author.Id;
         Version = author.Version;
         Name    = author.Name;
         if (author.Image != null)
         {
             Image = new RenderPageImageViewModel(author.Image);
         }
     }
 }
コード例 #18
0
        public async Task <Models.Author> GetAuthorAsync(int authorId)
        {
            HttpClient client = HttpClients.GetInstance();

            Models.Author       author   = null;
            HttpResponseMessage response = await client.GetAsync("authors/getbyid/" + authorId);

            if (response.IsSuccessStatusCode)
            {
                author = await response.Content.ReadAsAsync <Models.Author>();
            }
            return(author);
        }
コード例 #19
0
        /// <summary>
        /// Gets the list of author lookup values.
        /// </summary>
        /// <returns>
        /// List of author lookup values.
        /// </returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public IEnumerable <LookupKeyValue> GetAuthors()
        {
            Models.Author  alias       = null;
            LookupKeyValue lookupAlias = null;

            return(unitOfWork.Session
                   .QueryOver(() => alias)
                   .SelectList(select => select
                               .Select(Projections.Cast(NHibernateUtil.String, Projections.Property <Models.Author>(c => c.Id))).WithAlias(() => lookupAlias.Key)
                               .Select(() => alias.Name).WithAlias(() => lookupAlias.Value)).Where(c => !c.IsDeleted)
                   .OrderBy(o => o.Name).Asc()
                   .TransformUsing(Transformers.AliasToBean <LookupKeyValue>())
                   .List <LookupKeyValue>());
        }
コード例 #20
0
        // GET: Init
        public ActionResult Index()
        {
            Author a = new Models.Author("Adam", "Mickiewicz");

            db.Authors.Add(a);
            a.Id = 0;       // nie trzeba dopisywac Id bo db robi to za nas
            Author b = new Models.Author("Eliza", "Orzeszkowa");

            db.Authors.Add(b);
            b.Id = 1;
            db.SaveChanges();

            return(View());
        }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Author = await _context.Authors.FirstOrDefaultAsync(m => m.Id == id);

            if (Author == null)
            {
                return(NotFound());
            }
            return(Page());
        }
コード例 #22
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Author = await _context.Authors.FindAsync(id);

            if (Author != null)
            {
                _context.Authors.Remove(Author);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
コード例 #23
0
        /// <summary>
        /// Test the author repository.
        /// </summary>
        protected void Run()
        {
            using (var api = new Api()) {
                // Add new model
                var model = new Models.Author()
                {
                    Name  = "John Doe",
                    Email = "*****@*****.**"
                };
                api.Authors.Add(model);
                api.SaveChanges();
            }

            using (var api = new Api()) {
                // Get model
                var model = api.Authors.GetSingle(where : a => a.Name == "John Doe");

                Assert.IsNotNull(model);
                Assert.AreEqual("*****@*****.**", model.Email);

                // Update model
                model.Name = "Sir John Doe";
                api.SaveChanges();
            }

            using (var api = new Api()) {
                // Verify update
                var model = api.Authors.GetSingle(where : a => a.Email == "*****@*****.**");

                Assert.IsNotNull(model);
                Assert.AreEqual("Sir John Doe", model.Name);

                // Remove model
                api.Authors.Remove(model);
                api.SaveChanges();
            }

            using (var api = new Api()) {
                // Verify remove
                var model = api.Authors.GetSingle(where : a => a.Email == "*****@*****.**");
                Assert.IsNull(model);
            }
        }
コード例 #24
0
        public bool AddAuthor(string authorName)
        {
            Models.Author author = new Models.Author();
            author.AuthorName = authorName;

            try
            {
                using (BookLibraryContext db = new BookLibraryContext())
                {
                    db.Authors.Add(author);
                    db.SaveChanges();
                }
            }
            catch (Exception exc)
            {
                return(false);
            }

            return(true);
        }
コード例 #25
0
ファイル: AuthorTests.cs プロジェクト: cdie/Piranha.vNext
		/// <summary>
		/// Test the author repository.
		/// </summary>
		protected void Run() {
			using (var api = new Api()) {
				// Add new model
				var model = new Models.Author() {
					Name = "John Doe",
					Email = "*****@*****.**"
				};
				api.Authors.Add(model);
				api.SaveChanges();
			}

			using (var api = new Api()) {
				// Get model
				var model = api.Authors.GetSingle(where: a => a.Name == "John Doe");

				Assert.IsNotNull(model);
				Assert.AreEqual("*****@*****.**", model.Email);

				// Update model
				model.Name = "Sir John Doe";
				api.SaveChanges();
			}

			using (var api = new Api()) {
				// Verify update
				var model = api.Authors.GetSingle(where: a => a.Email == "*****@*****.**");

				Assert.IsNotNull(model);
				Assert.AreEqual("Sir John Doe", model.Name);

				// Remove model
				api.Authors.Remove(model);
				api.SaveChanges();
			}

			using (var api = new Api()) {
				// Verify remove
				var model = api.Authors.GetSingle(where: a => a.Email == "*****@*****.**");
				Assert.IsNull(model);
			}
		}
コード例 #26
0
        public CreateBlogModel()
        {
            Models.Author A1 = new Models.Author()
            {
                Fname = "Enid",
                Lname = "Blyton",
                Email = "*****@*****.**"
            };
            Models.Author A2 = new Models.Author()
            {
                Fname = "Roald",
                Lname = "Dahl",
                Email = "*****@*****.**"
            };
            Models.Author A3 = new Models.Author()
            {
                Fname = "Robert",
                Lname = "Stine",
                Email = "*****@*****.**"
            };
            Models.Author A4 = new Models.Author()
            {
                Fname = "Charles",
                Lname = "Dickens",
                Email = "*****@*****.**"
            };
            Models.Author A5 = new Models.Author()
            {
                Fname = "Ruskin",
                Lname = "Bond",
                Email = "*****@*****.**"
            };

            Authors.Add(A1);
            Authors.Add(A2);
            Authors.Add(A3);
            Authors.Add(A4);
            Authors.Add(A5);
        }
コード例 #27
0
        public ActionResult Register(Models.Register reg)
        {
            //post action receives a Register object

            //1. check to see if the username is already in use
            if (Membership.GetUser(reg.Username) == null)
            {
                //username is valid, so add the user to the database
                Membership.CreateUser(reg.Username, reg.Password);
                //add the user to our myBlog authors table
                Models.Author author = new Models.Author();
                //set the properties of our author object
                author.Username = reg.Username;
                author.Name = reg.Name;
                author.ImageURL = reg.ImageURL;
                //add the author to the database.
                db.Authors.Add(author);
                db.SaveChanges();
                //Log the user in
                FormsAuthentication.SetAuthCookie(reg.Username, false);
                //kick the user back to the landing page.
                return RedirectToAction("Index", "Home");
            }
            else
            {
                //username is already in use, send a message
                //to the view to let the user know
                ViewBag.Error = "Username is already in use, good sir.  Please choose another.";
                //return the view, with the reg object
                return View(reg);
            }
        }
コード例 #28
0
ファイル: TitlesService.cs プロジェクト: gbhl/bhl-legacy
        public Models.Title GetTitle(int id)
        {
            Api2 apiProvider = new Api2();

            BHLApiData.Title bhlTitle = apiProvider.GetTitleMetadata(id.ToString(), "f");

            Models.Title title = null;
            if (bhlTitle != null)
            {
                title                      = new Models.Title();
                title.TitleId              = bhlTitle.TitleID;
                title.FullTitle            = bhlTitle.FullTitle;
                title.PartNumber           = bhlTitle.PartNumber;
                title.PartName             = bhlTitle.PartName;
                title.CallNumber           = bhlTitle.CallNumber;
                title.Edition              = bhlTitle.Edition;
                title.PublisherPlace       = bhlTitle.PublisherPlace;
                title.PublisherName        = bhlTitle.PublisherName;
                title.PublicationDate      = bhlTitle.PublicationDate;
                title.PublicationFrequency = bhlTitle.PublicationFrequency;
                title.BibliographicLevel   = bhlTitle.BibliographicLevel;

                List <Models.Subject> subjects = null;
                foreach (BHLApiData.Subject keyword in bhlTitle.Subjects)
                {
                    subjects = (subjects ?? new List <Models.Subject>());
                    Models.Subject subject = new Models.Subject();
                    subject.SubjectText = keyword.SubjectText;
                    subjects.Add(subject);
                }
                title.Subjects = subjects;

                List <Models.Author> authors = null;
                foreach (BHLApiData.Creator bhlAuthor in bhlTitle.Authors)
                {
                    authors = (authors ?? new List <Models.Author>());
                    Models.Author author = new Models.Author();
                    author.CreatorID  = bhlAuthor.CreatorID;
                    author.Type       = bhlAuthor.Role;
                    author.Name       = bhlAuthor.Name;
                    author.Dates      = bhlAuthor.Dates;
                    author.Numeration = bhlAuthor.Numeration;
                    author.Unit       = bhlAuthor.Unit;
                    author.Title      = bhlAuthor.Title;
                    author.Location   = bhlAuthor.Location;
                    author.FullerForm = bhlAuthor.FullerForm;
                    authors.Add(author);
                }
                title.Authors = authors;

                List <Models.Identifier> identifiers = null;
                foreach (BHLApiData.TitleIdentifier bhlIdentifier in bhlTitle.Identifiers)
                {
                    identifiers = (identifiers ?? new List <Models.Identifier>());
                    Models.Identifier identifier = new Models.Identifier();
                    identifier.IdentifierName   = bhlIdentifier.IdentifierName;
                    identifier.IdentifierValue  = bhlIdentifier.IdentifierValue;
                    identifier.RelationshipType = "same as";
                    identifiers.Add(identifier);
                }
                title.Identifiers = identifiers;
            }

            return(title);
        }
コード例 #29
0
ファイル: RatingTests.cs プロジェクト: cdie/Piranha.vNext
		/// <summary>
		/// Test the rating repository.
		/// </summary>
		protected void Run() {
			var userId = Guid.NewGuid().ToString();
			Models.PostType type = null;
			Models.Author author = null;
			Models.Post post = null;

			using (var api = new Api()) {
				// Add new post type
				type = new Models.PostType() {
					Name = "Rating post",
					Route = "post"
				};
				api.PostTypes.Add(type);
				api.SaveChanges();

				// Add new author
				author = new Models.Author() {
					Name = "Jim Doe",
					Email = "*****@*****.**"
				};
				api.Authors.Add(author);
				api.SaveChanges();

				// Add new post
				post = new Models.Post() {
					TypeId = type.Id,
					AuthorId = author.Id,
					Title = "My rated post",
					Excerpt = "Read my first post.",
					Body = "<p>Lorem ipsum</p>",
					Published = DateTime.Now
				};
				api.Posts.Add(post);
				api.SaveChanges();
			}
			
			using (var api = new Api()) {
				// Add ratings
				api.Ratings.AddRating(Models.RatingType.Star, post.Id, userId);
				api.Ratings.AddRating(Models.RatingType.Like, post.Id, userId);

				api.SaveChanges();
			}

			using (var api = new Api()) {
				// Verify save
				var model = Client.Models.PostModel.GetById(post.Id).WithRatings();

				Assert.AreEqual(1, model.Ratings.Stars.Count);
				Assert.AreEqual(1, model.Ratings.Likes.Count);

				// Remove ratings
				api.Ratings.RemoveRating(Models.RatingType.Star, post.Id, userId);
				api.Ratings.RemoveRating(Models.RatingType.Like, post.Id, userId);

				api.SaveChanges();
			}

			using (var api = new Api()) {
				// Verify remove
				var model = Client.Models.PostModel.GetById(post.Id).WithRatings();

				Assert.AreEqual(0, model.Ratings.Stars.Count);
				Assert.AreEqual(0, model.Ratings.Likes.Count);

				// Remove
				api.Posts.Remove(post.Id);
				api.PostTypes.Remove(type.Id);
				api.Authors.Remove(author.Id);
				api.SaveChanges();
			}
			
			using (var api = new Api()) {
				// Verify remove
				post = api.Posts.GetSingle(where: p => p.Slug == "my-rated-post");
				type = api.PostTypes.GetSingle(type.Id);
				author = api.Authors.GetSingle(author.Id);

				Assert.IsNull(post);
				Assert.IsNull(type);
				Assert.IsNull(author);
			}
		}
コード例 #30
0
		public async Task AuthorRepository() {
			var id = Guid.Empty;

			// Insert author
			using (var api = new Api()) {
				var author = new Models.Author() {
					Name = "John Doe",
					Email = "*****@*****.**"
				};
				api.Authors.Add(author);

				Assert.AreEqual(author.Id.HasValue, true);
				Assert.IsTrue(api.SaveChanges() > 0);

				id = author.Id.Value;
			}

			// Get by id
			using (var api = new Api()) {
				var author = await api.Authors.GetByIdAsync(id);

				Assert.IsNotNull(author);
				Assert.AreEqual(author.Name, "John Doe");
			}

			// Update param
			using (var api = new Api()) {
				var author = await api.Authors.GetByIdAsync(id);

				Assert.IsNotNull(author);

				author.Name = "John Moe";
				api.Authors.Add(author);

				Assert.IsTrue(api.SaveChanges() > 0);
			}

			// Get by id
			using (var api = new Api()) {
				var author = await api.Authors.GetByIdAsync(id);

				Assert.IsNotNull(author);
				Assert.AreEqual(author.Name, "John Moe");
			}

			// Remove author
			using (var api = new Api()) {
				api.Authors.Remove(id);

				Assert.IsTrue(api.SaveChanges() > 0);
			}

			// Remove system param
			using (var api = new Api()) {
				var param = api.Params.GetByInternalId("ARCHIVE_PAGE_SIZE");

				try {
					api.Params.Remove(param);

					// The above statement should throw an exception and this
					// this assertion should not be reached.
					Assert.IsTrue(false);
				} catch (Exception ex) {
					Assert.IsTrue(ex is UnauthorizedAccessException);
				}
			}
		}
コード例 #31
0
 async void Handle_AuthorAdded(object sender, Models.Author author)
 {
     await Navigation.PopAsync(true);
 }
コード例 #32
0
 public Models.Author AddAuthor(Models.Author author)
 {
     db.Authors.Add(author);
     db.SaveChanges();
     return(author);
 }
コード例 #33
0
ファイル: PostTests.cs プロジェクト: cdie/Piranha.vNext
		/// <summary>
		/// Test the post repository.
		/// </summary>
		protected void Run() {
			Models.PostType type = null;
			Models.Author author = null;
			Models.Post post = null;

			using (var api = new Api()) {
				// Add new post type
				type = new Models.PostType() {
					Name = "Test post",
					Route = "post"
				};
				api.PostTypes.Add(type);
				api.SaveChanges();

				// Add new author
				author = new Models.Author() {
					Name = "Jane Doe",
					Email = "*****@*****.**"
				};
				api.Authors.Add(author);
				api.SaveChanges();

				// Add new post
				post = new Models.Post() {
					TypeId = type.Id,
					AuthorId = author.Id,
					Title = "My test post",
					Excerpt = "Read my first post.",
					Body = "<p>Lorem ipsum</p>",
					Published = DateTime.Now
				};
				api.Posts.Add(post);
				api.SaveChanges();
			}
			
			using (var api = new Api()) {
				// Get model
				var model = api.Posts.GetSingle(where: p => p.Slug == "my-test-post");

				Assert.IsNotNull(model);
				Assert.AreEqual("Read my first post.", model.Excerpt);
				Assert.AreEqual("<p>Lorem ipsum</p>", model.Body);

				// Update model
				model.Excerpt = "Updated post";
				api.SaveChanges();
			}
			
			using (var api = new Api()) {
				// Verify update
				var model = api.Posts.GetSingle(where: p => p.Slug == "my-test-post");

				Assert.IsNotNull(model);
				Assert.AreEqual("Updated post", model.Excerpt);
				Assert.AreEqual("<p>Lorem ipsum</p>", model.Body);

				// Remove
				api.Posts.Remove(model);
				api.PostTypes.Remove(type.Id);
				api.Authors.Remove(author.Id);
				api.SaveChanges();
			}

			using (var api = new Api()) {
				// Verify remove
				post = api.Posts.GetSingle(where: p => p.Slug == "my-test-post");
				type = api.PostTypes.GetSingle(type.Id);
				author = api.Authors.GetSingle(author.Id);

				Assert.IsNull(post);
				Assert.IsNull(type);
				Assert.IsNull(author);
			}
		}
コード例 #34
0
        public ActionResult Register(Models.Register reg)
        {
            //post action receives a Register object
            //check to see if the user name is already in use
            if (Membership.GetUser(reg.UserName) == null)
            {
                //user name is valid, add the user to our database
                Membership.CreateUser(reg.UserName, reg.Password);
                //add the user to myBlog author table
                Models.Author author = new Models.Author();
                //set our property to our author
                author.Username = reg.UserName;
                author.Name = reg.Name;
                author.ImageURL = reg.ImageURL;
                //add the author to the database
                db.Authors.Add(author);
                //save
                db.SaveChanges();
                //Log the user in
                FormsAuthentication.SetAuthCookie(reg.UserName, true);
                return RedirectToAction("Index", "Home");

            }
            else
            {
                //username is already in use
                ViewBag.Error = "The user name has been used. Please choose another user name";
                //return the view with the reg object
                return View(reg);
            }
        }
コード例 #35
0
        public async Task <IActionResult> Create([FromForm] Models.Author author)
        {
            var createdAuthor = await _authorService.CreateAsync(author, Request);

            return(Ok(createdAuthor));
        }
コード例 #36
0
ファイル: RatingTests.cs プロジェクト: rkmr/Piranha.vNext
        /// <summary>
        /// Test the rating repository.
        /// </summary>
        protected void Run()
        {
            var userId = Guid.NewGuid().ToString();

            Models.PostType type   = null;
            Models.Author   author = null;
            Models.Post     post   = null;

            using (var api = new Api()) {
                // Add new post type
                type = new Models.PostType()
                {
                    Name  = "Rating post",
                    Route = "post"
                };
                api.PostTypes.Add(type);
                api.SaveChanges();

                // Add new author
                author = new Models.Author()
                {
                    Name  = "Jim Doe",
                    Email = "*****@*****.**"
                };
                api.Authors.Add(author);
                api.SaveChanges();

                // Add new post
                post = new Models.Post()
                {
                    TypeId    = type.Id,
                    AuthorId  = author.Id,
                    Title     = "My rated post",
                    Excerpt   = "Read my first post.",
                    Body      = "<p>Lorem ipsum</p>",
                    Published = DateTime.Now
                };
                api.Posts.Add(post);
                api.SaveChanges();
            }

            using (var api = new Api()) {
                // Add ratings
                api.Ratings.AddRating(Models.RatingType.Star, post.Id, userId);
                api.Ratings.AddRating(Models.RatingType.Like, post.Id, userId);

                api.SaveChanges();
            }

            using (var api = new Api()) {
                // Verify save
                var model = Client.Models.PostModel.GetById(post.Id).WithRatings();

                Assert.AreEqual(1, model.Ratings.Stars.Count);
                Assert.AreEqual(1, model.Ratings.Likes.Count);

                // Remove ratings
                api.Ratings.RemoveRating(Models.RatingType.Star, post.Id, userId);
                api.Ratings.RemoveRating(Models.RatingType.Like, post.Id, userId);

                api.SaveChanges();
            }

            using (var api = new Api()) {
                // Verify remove
                var model = Client.Models.PostModel.GetById(post.Id).WithRatings();

                Assert.AreEqual(0, model.Ratings.Stars.Count);
                Assert.AreEqual(0, model.Ratings.Likes.Count);

                // Remove
                api.Posts.Remove(post.Id);
                api.PostTypes.Remove(type.Id);
                api.Authors.Remove(author.Id);
                api.SaveChanges();
            }

            using (var api = new Api()) {
                // Verify remove
                post   = api.Posts.GetSingle(where : p => p.Slug == "my-rated-post");
                type   = api.PostTypes.GetSingle(type.Id);
                author = api.Authors.GetSingle(author.Id);

                Assert.IsNull(post);
                Assert.IsNull(type);
                Assert.IsNull(author);
            }
        }
コード例 #37
0
        public ActionResult Register(Models.Register reg)
        {
            // post action recives a Register object
            // 1. check to see if the username is already in use
            if (Membership.GetUser(reg.Username) == null)
            {
                // user is valid so add the usre
                Membership.CreateUser(reg.Username, reg.Password);

            }
            else
            {
                // username is already in use
                ViewBag.Error = " That Username is already in use my friend. You should pick another one. Be Different when picking how you want to be called on the wonderful blog";
                // return the view with the reg object
                return View(reg);
            }
            // add user to myblob authors
            Models.Author author = new Models.Author();
            //set the properties of our author
            author.Username = reg.Username;
                author.Name = reg.Name;
                    author.ImageURL = reg.ImageURl;
                    if (author.ImageURL == null)
                    {
                        author.ImageURL = "";

                    }
            // add authour to the database
                    db.Authors.Add(author);
                    db.SaveChanges();
            // log the user in
                    FormsAuthentication.SetAuthCookie(reg.Username, false);
                    return RedirectToAction("Index", "Home");
        }