Beispiel #1
0
        public string CreateBook(Book book)
        {
            string err = null;

            var context = new CityLibraryEntities();

            try
            {
                context.Books.Add(book);
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message, ex);
                err = ex.Message;
            }

            return err;
        }
        public ActionResult Create(BookModel book)
        {
            try
            {

                var tmp_book = new Book();
                string err = null;

                tmp_book = AutoMapper.Mapper.Map<Book>(book);
                tmp_book.AddDate = System.DateTime.Now;

                var dao = new UserService();

                err = dao.CreateBook(tmp_book);

                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Beispiel #3
0
        public string UpdateBook(Book book)
        {
            string err = null;

            var context = new CityLibraryEntities();

            try
            {
                var currentBook = context.Books.SingleOrDefault(b => b.BookId == book.BookId);
                AutoMapper.Mapper.CreateMap<Book, Book>();
                if (currentBook != null)
                {
                    currentBook = AutoMapper.Mapper.Map<Book, Book>(book);
                    context.SaveChanges();
                }

            }
            catch (Exception ex)
            {
                Log.Error(ex.Message, ex);
                err = ex.Message;
            }

            return err;
        }