public async Task <IActionResult> Post([FromBody] Author value)
        {
            if (value == null)
            {
                return(BadRequest("Author is empty"));
            }
            await authorsRepository.Add(value);

            return(Ok("Author created"));
        }
Exemple #2
0
        public IActionResult Create([FromBody] Author newAuthor)
        {
            if (newAuthor == null)
            {
                return(BadRequest());
            }

            _authorsRepository.Add(newAuthor);

            return(CreatedAtRoute("GetAuthorById", new { authorId = newAuthor.Id }, newAuthor));
        }
Exemple #3
0
        public async Task <AuthorsRequestClass> AddAuthor(Authors p)
        {
            var returnVal = new AuthorsRequestClass();
            var actType   = await repoAuthors.Get(l => l.surname == p.surname);

            if (actType != null)
            {
                returnVal.ErrorCode = -2;
                returnVal.ErrorText = "Author already Exists!!";

                return(returnVal);
            }

            p.datecreated = DateTime.Now;
            p.userid      = p.userid;
            repoAuthors.Add(p);
            try
            {
                var retV = await unitOfWork.Commit(Convert.ToUInt16(p.userid)) > 0 ? true : false;

                if (retV)
                {
                    returnVal.ErrorCode = 0;
                    returnVal.ErrorText = "Record Added Succesfully";
                    return(returnVal);
                }
            }
            catch (Exception ex)
            {
                sLogUtility.SaveLog(ex.Message == null ? ex.InnerException.Message : ex.Message);
                returnVal.ErrorCode = -1;
                returnVal.ErrorText = ex.Message == null ? ex.InnerException.Message : ex.Message;

                return(returnVal);
            }

            return(returnVal);
        }
Exemple #4
0
 public async Task AddAndSave(FinalProject.Models.Authors author)
 {
     _authorRepo.Add(author);
     await _authorRepo.Save();
 }
 // POST: api/Authors
 public int Post([FromBody] Author value)
 {
     return(authorsRepository.Add(value));
 }
        // POST: api/authors
        public HttpResponseMessage Post([FromBody] Author value)
        {
            int id = _authorsRepository.Add(value);

            return(Request.CreateResponse <int>(HttpStatusCode.Created, id));
        }