예제 #1
0
        public string UpdateAuthor(Authors author)
        {
            string message = string.Empty;

            try
            {
                using (var ctx = new BooksContext())
                {
                    ctx.Entry(author).State = EntityState.Modified;
                    ctx.SaveChanges();
                    message = "Author was updated.";
                }
            }
            catch (Exception ex)
            {
                message = "Couldn't update author";
                throw ex;
            }

            return(message);
        }
예제 #2
0
        public string InsertAuthor(string name, string lastName, int age, string telNr, PaymentMethods paymentMethod)
        {
            var author = new Authors()
            {
                FirstName = name, LastName = lastName, Age = age, HomeTel = telNr, PaymetMethod = paymentMethod
            };
            string message = string.Empty;

            try
            {
                using (var ctx = new BooksContext())
                {
                    ctx.Authors.Add(author);
                    ctx.SaveChanges();
                    message = "Author was added";
                }
            }
            catch (Exception e)
            {
                message = "Couldn't add author";
                throw e;
            }
            return(message);
        }
예제 #3
0
        public string DisplayAuthor(Authors author)
        {
            var authorInfo = $"ID: {author.AuthorID} Name: {author.FirstName} {author.LastName} Age: {author.Age} \ntel: {author.HomeTel} Payment Method: {author.PaymetMethod}\n---------------------------------------";

            return(authorInfo);
        }