Beispiel #1
0
        public async Task <int> UpdateAuthor(string authorId, Author author)
        {
            int DbResult = 0;

            if (!String.IsNullOrEmpty(authorId) && dataReqiered.IsDataNoEmpty(author))
            {
                int oldDataAuthorId             = Convert.ToInt32(authorId);
                int newDataAuthorId             = Convert.ToInt32(author.Id);
                AuthorPostgreSql updatingAuthor = null;

                updatingAuthor = await db.Authors.FindAsync(oldDataAuthorId);

                if (oldDataAuthorId == newDataAuthorId)
                {
                    updatingAuthor.Name    = author.Name;
                    updatingAuthor.Surname = author.Surname;

                    db.Entry(updatingAuthor).State = EntityState.Modified;

                    try
                    {
                        DbResult = await db.SaveChangesAsync();
                    }
                    catch
                    {
                        return(DbResult);
                    }
                }
            }

            return(DbResult);
        }
Beispiel #2
0
 public Author(AuthorPostgreSql author)
 {
     Id               = Convert.ToString(author.Id);
     Name             = author.Name;
     Surname          = author.Surname;
     authorPostgreSql = author;
 }
Beispiel #3
0
        public async Task <Author> GetAuthorById(string authorId)
        {
            Author Author = new Author();

            if (!String.IsNullOrEmpty(authorId))
            {
                int aId = Convert.ToUInt16(authorId);
                AuthorPostgreSql authorDbResult = await db.Authors.FindAsync(aId);

                if (authorDbResult != null)
                {
                    Author.Id      = authorDbResult.Id.ToString();
                    Author.Name    = authorDbResult.Name;
                    Author.Surname = authorDbResult.Surname;
                }
            }

            return(Author);
        }
Beispiel #4
0
        public async Task <int> DeleteAuthor(string authorId)
        {
            int DbResult = 0;

            if (!String.IsNullOrEmpty(authorId))
            {
                int delAuthorId = Convert.ToInt32(authorId);

                AuthorPostgreSql author = await db.Authors.FindAsync(delAuthorId);

                if (author != null)
                {
                    db.Authors.Remove(author);
                    DbResult = await db.SaveChangesAsync();
                }
            }

            return(DbResult);
        }
Beispiel #5
0
        public async Task <int> CreateAuthor(Author author)
        {
            int DbResult = 0;

            if (dataReqiered.IsDataNoEmpty(author))
            {
                AuthorPostgreSql newAuthor = new AuthorPostgreSql {
                    Name = author.Name, Surname = author.Surname
                };

                db.Authors.Add(newAuthor);
                try
                {
                    DbResult = await db.SaveChangesAsync();
                }
                catch
                {
                    return(DbResult);
                }
            }

            return(DbResult);
        }