Пример #1
0
        public Author Save(Author author)
        {
            using (var context = new DataContext())
            {
                if (author.Id == 0)
                {
                    context.Authors.Add(author);
                }
                else
                {
                    context.Entry(author).State = EntityState.Modified;
                    context.Authors.AddOrUpdate(author);
                }
                context.SaveChanges();

            }
            return author;
        }
        public ActionResult Create(AuthorViewModel model)
        {
            try
            {
                // TODO: Add insert logic here

                Author author = new Author();
                author.Id = model.Id;
                author.FirstName = model.FirstName;
                author.LastName = model.LastName;

                AuthorBusinessService service = new AuthorBusinessService();
                service.SaveAuthor(author);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
 public Author SaveAuthor(Author author)
 {
     AuthorData data = new AuthorData();
     return data.Save(author);
 }