/// <summary>
        /// Posts a new author.
        /// </summary>
        /// <param name="item">New author</param>
        /// <returns>Status message</returns>
        public async Task<Author> Post(Author item)
        {
            if (item == null)
            {
                throw new HttpResponseException(
                    Request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid parameter"));
            }

            var author = await repository.InsertAsync(item);
            return author;
        }
        /// <summary>
        /// Updates an existing author.
        /// </summary>
        /// <param name="key">Author ID</param>
        /// <param name="item">Updated author</param>
        /// <returns>Status message</returns>
        public async Task<Author> Put([FromODataUri] Guid key, Author item)
        {
            if (key == Guid.Empty || item == null)
            {
                throw new HttpResponseException(
                    Request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid parameter"));
            }

            item.ID = key;
            var author = await repository.UpdateAsync(item);
            return author;
        }
Beispiel #3
0
        /// <summary>
        /// Login view.
        /// </summary>
        public ActionResult Login(string userName)
        {
            if (userName != null && userName.Length > 0)
            {
                var repository = DependencyResolver.Current.GetService<IAuthorRepository>();
                var author = repository.GetByName(userName);

                if (author == null)
                {
                    author = new Author();
                    author.Name = userName;
                    author.Age = 0;
                    author.City = "Unknown";
                    author.State = "Unknown";

                    author = repository.Insert(author);
                }

                TempData["userID"] = author.ID;
                TempData["userName"] = author.Name;

                return RedirectToAction("Index", "Home");
            }

            return View(new BaseViewModel());
        }