public void DeleteAuthor(int id)
        {
            AUTHOR author = dataAccess.AUTHORs.Single(aut => aut.AUTHORID == id);

            dataAccess.AUTHORs.DeleteOnSubmit(author);
            dataAccess.SaveChanges();
        }
Ejemplo n.º 2
0
 public void DeleteAuthor(AuthorModel Author)
 {
     if (Author == null)
     {
         throw new ArgumentNullException();
     }
     using (AppTourEntities data = new AppTourEntities())
     {
         AUTHOR current = data.AUTHOR.Where(p => p.ID == Author.Id).SingleOrDefault();
         if (current != null)
         {
             try
             {
                 data.DeleteObject(current);
                 data.SaveChanges();
             }
             catch (Exception e)
             {
                 if (e.InnerException != null)
                 {
                     throw new Exception(e.InnerException.Message);
                 }
                 throw;
             }
         }
     }
 }
Ejemplo n.º 3
0
 public void Delete(AUTHOR author)
 {
     using (var db = new LibDb())
     {
         using (DbContextTransaction transaction = db.Database.BeginTransaction())
         {
             db.AUTHORs.Attach(author);
             foreach (var bo in author.BOOKs)
             {
                 db.BOOKs.Attach(bo);
             }
             try
             {
                 author.BOOKs.Clear();
                 db.AUTHORs.Remove(author);
                 db.SaveChanges();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 transaction.Rollback();
             }
         }
     }
 }
        public Tuple <Author, AuthorValidation> CreateAuthor(Author author)
        {
            AuthorValidation validation = new AuthorValidation(author);

            if (validation.IsValid)
            {
                string authorFirstName = author.FirstName;
                if (author.FirstName != null)
                {
                    author.FirstName = authorFirstName.Substring(0, 1).ToUpper() + authorFirstName.Substring(1);
                }
                string authorLastName = author.LastName;
                author.LastName = authorLastName.Substring(0, 1).ToUpper() + authorLastName.Substring(1);
                AUTHOR repoAUTHOR = _Repo.CreateAuthor(Mapper.Map <Author, AUTHOR>(author));
                if (repoAUTHOR == null)
                {
                    validation.FailedToCreateAuthor(nameof(author.FirstName));
                }
                else
                {
                    Author newAuthor = Mapper.Map <Author>(repoAUTHOR);
                    if (newAuthor != null)
                    {
                        return(new Tuple <Author, AuthorValidation>(newAuthor, validation));
                    }
                    validation.FailedToCreateAuthor(nameof(author.LastName));
                }
            }
            return(new Tuple <Author, AuthorValidation>(null, validation));
        }
Ejemplo n.º 5
0
        public IHttpActionResult PutAUTHOR(int id, AUTHOR aUTHOR)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != aUTHOR.ID)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AUTHORExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 6
0
        public void Update(AUTHOR authorObj)
        {
            using (var db = new LibDb())
            {
                var b = db.AUTHORs.Include(x => x.BOOKs).ToList().Find(d => d.Aid ==
                                                                       authorObj.Aid);
                b.BOOKs.Clear();

                db.SaveChanges();
            }

            var newBooks = authorObj.BOOKs;

            authorObj.BOOKs = new List <BOOK>();

            using (var db = new LibDb())
            {
                db.AUTHORs.Attach(authorObj);
                db.Entry(authorObj).State = EntityState.Modified;

                foreach (var book in newBooks)
                {
                    db.BOOKs.Attach(book);
                    authorObj.BOOKs.Add(book);
                }

                db.SaveChanges();
            }
        }
        public Tuple <Author, AuthorValidation> EditAuthor(Author author)
        {
            AuthorValidation validation = new AuthorValidation(author);

            if (validation.IsValid)
            {
                string authorFirstName = author.FirstName;
                if (author.FirstName != null)
                {
                    author.FirstName = authorFirstName.Substring(0, 1).ToUpper() + authorFirstName.Substring(1);
                }
                string authorLastName = author.LastName;
                author.LastName = authorLastName.Substring(0, 1).ToUpper() + authorLastName.Substring(1);
                AUTHOR repoAUTHOR = _Repo.EditAuthor(Mapper.Map <Author, AUTHOR>(author));
                if (repoAUTHOR != null)
                {
                    Author editedAuthor = Mapper.Map <AUTHOR, Author>(repoAUTHOR);
                    if (editedAuthor != null)
                    {
                        return(new Tuple <Author, AuthorValidation>(editedAuthor, validation));
                    }
                }
                else
                {
                    validation.DoesNotExistOnServer(nameof(author.LastName));
                }
            }
            return(new Tuple <Author, AuthorValidation>(null, validation));
        }
        public ActionResult Create(AUTHOR author, HttpPostedFileBase thumbnail)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (thumbnail != null && !String.IsNullOrEmpty(thumbnail.FileName))
                    {
                        String fname = Generator.RandomString(10) + "." + thumbnail.FileName.Split('.')[thumbnail.FileName.Split('.').Length - 1];
                        string path  = Server.MapPath("~/UserImages/") + fname;
                        author.THUMBNAIL_PATH = "/UserImages/" + fname;
                        thumbnail.SaveAs(path);
                    }
                    else
                    {
                        author.THUMBNAIL_PATH = "/UserImages/avatar.png";
                    }
                    AuthorModel.Create(author);
                    ViewBag.Message = SuccessMessage.AUTHOR_ADDED;
                }
                else
                {
                    ViewBag.ErrorMessage = ErrorMessage.REQUIRED_ASTERIC_FIELDS;
                }

                return(View());
            }
            catch
            {
                ViewBag.ErrorMessage = ErrorMessage.INTERNAL_ERROR;
                return(View());
            }
        }
Ejemplo n.º 9
0
        public void UpdateAuthor(AuthorModel Author)
        {
            using (AppTourEntities data = new AppTourEntities())
            {
                AUTHOR current = data.AUTHOR.Where(x => Author.Id == x.ID).SingleOrDefault();
                if (current != null)
                {
                    try
                    {
                        current.ENTERPRISE    = data.ENTERPRISE.Where(f => f.ID == Author.Id).FirstOrDefault();
                        current.NAME          = Author.Name;
                        current.REALNAME      = Author.RealName;
                        current.EMAIL         = Author.Email;
                        current.CREATION_DATE = Author.CreationDate;
                        current.UPDATE_DATE   = DateTime.Now;

                        data.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        if (e.InnerException != null)
                        {
                            throw new Exception(e.InnerException.Message);
                        }
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public Guid InsertAuthor(AuthorModel Author)
        {
            Guid id = Guid.NewGuid();

            if (Author == null)
            {
                throw new NullReferenceException();
            }

            using (AppTourEntities data = new AppTourEntities())
            {
                AUTHOR _new = new AUTHOR
                {
                    ID            = id,
                    ENTERPRISE    = data.ENTERPRISE.Where(f => f.ID == Author.Enterprise.Id).FirstOrDefault(),
                    NAME          = Author.Name,
                    REALNAME      = Author.RealName,
                    EMAIL         = Author.Email,
                    CREATION_DATE = DateTime.Now,
                    UPDATE_DATE   = DateTime.Now
                };

                data.AUTHOR.AddObject(_new);
                data.SaveChanges();
            }

            return(id);
        }
Ejemplo n.º 11
0
        public ActionResult DeleteConfirmed(int id)
        {
            AUTHOR aUTHOR = db.AUTHORs.Find(id);

            db.AUTHORs.Remove(aUTHOR);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 12
0
 public void CreateNew(AUTHOR author)
 {
     using (var db = new LibDB())
     {
         db.AUTHOR.Add(author);
         db.SaveChanges();
     }
 }
Ejemplo n.º 13
0
 public void Add(AUTHOR authorObj)
 {
     using (var db = new swagbaseEntities1())
     {
         db.AUTHORs.Add(authorObj);
         db.SaveChanges();
     }
 }
Ejemplo n.º 14
0
 public void Update(AUTHOR authorObj)
 {
     using (var db = new LibraryDBEntities1())
     {
         db.AUTHORs.Attach(authorObj);
         db.Entry(authorObj).State = EntityState.Modified;
         Shared.save(db);
     }
 }
        public ActionResult ThemTacGia(String tenTG)
        {
            AUTHOR tg = new AUTHOR();

            tg.NAME = tenTG;
            db.AUTHOR.Add(tg);
            db.SaveChanges();
            return(RedirectToAction("ThemSach"));
        }
Ejemplo n.º 16
0
 public void Add(AUTHOR authobj)
 {
     using (var db = new Libdb())
     {
         db.AUTHOR.Add(authobj);
         db.Entry(authobj).State = EntityState.Added;
         db.SaveChanges();
     }
 }
Ejemplo n.º 17
0
 public void Update(AUTHOR authobj)
 {
     using (var db = new Libdb())
     {
         db.AUTHOR.Attach(authobj);
         db.Entry(authobj).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Ejemplo n.º 18
0
 public void Delete(AUTHOR authorObj)
 {
     using (var db = new swagbaseEntities1())
     {
         AUTHOR athID = db.AUTHORs.Find(authorObj.Aid);
         db.AUTHORs.Remove(athID);
         db.SaveChanges();
     }
 }
        // GET: Author/Details/5
        public ActionResult Details(int id)
        {
            AUTHOR author = AuthorModel.Filter(id);

            if (author == null)
            {
                return(HttpNotFound());
            }
            return(View(author));
        }
 public ActionResult Edit([Bind(Include = "ID,FIRST_NAME,LAST_NAME,ADDRESS,EMAIL,CONTACT_NO,EDUCATION,SPECIALIZATION,REMARKS")] AUTHOR aUTHOR)
 {
     if (ModelState.IsValid)
     {
         db.Entry(aUTHOR).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(aUTHOR));
 }
Ejemplo n.º 21
0
 public ActionResult Edit([Bind(Include = "Aid,FirstName,LastName,BirthYear")] AUTHOR aUTHOR)
 {
     if (ModelState.IsValid)
     {
         db.Entry(aUTHOR).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(aUTHOR));
 }
Ejemplo n.º 22
0
        public void createAuthor(string firstName, string lastName, string birthYear)
        {
            AuthorRepository authorManagerObj = new AuthorRepository();
            AUTHOR           author           = new AUTHOR();

            author.FirstName = firstName;
            author.LastName  = lastName;
            author.BirthYear = birthYear;
            authorManagerObj.CreateNew(author);
        }
Ejemplo n.º 23
0
        public ActionResult Create([Bind(Include = "Aid,FirstName,LastName,BirthYear")] AUTHOR aUTHOR)
        {
            if (ModelState.IsValid)
            {
                db.AUTHORs.Add(aUTHOR);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(aUTHOR));
        }
Ejemplo n.º 24
0
        public void editAuthor(string firstName, string lastName, string birthYear, int Aid)
        {
            AuthorRepository authorManagerObj = new AuthorRepository();
            AUTHOR           author           = new AUTHOR();

            author.FirstName = firstName;
            author.LastName  = lastName;
            author.BirthYear = birthYear;
            author.Aid       = Aid;
            authorManagerObj.Edit(author);
        }
Ejemplo n.º 25
0
        //Hämtar en specifik författare
        static public Author getAuthor(int id)
        {
            AUTHOR aauthor   = _eAuthorObj.Read(id);
            Author authorObj = Mapper.Map <Author>(aauthor);

            authorObj.FirstName = authorObj.FirstName;
            authorObj.LastName  = authorObj.LastName;
            authorObj.BirthYear = authorObj.BirthYear;
            authorObj.BooksList = Mapper.Map <List <BOOK>, List <Book> >(aauthor.BOOKs.ToList());
            return(authorObj);
        }
Ejemplo n.º 26
0
        public IHttpActionResult GetAUTHOR(int id)
        {
            AUTHOR aUTHOR = db.AUTHORs.Find(id);

            if (aUTHOR == null)
            {
                return(NotFound());
            }

            return(Ok(aUTHOR));
        }
        public ActionResult Create([Bind(Include = "ID,FIRST_NAME,LAST_NAME,ADDRESS,EMAIL,CONTACT_NO,EDUCATION,SPECIALIZATION,REMARKS")] AUTHOR aUTHOR)
        {
            if (ModelState.IsValid)
            {
                db.AUTHORs.Add(aUTHOR);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(aUTHOR));
        }
Ejemplo n.º 28
0
        public IHttpActionResult PostAUTHOR(AUTHOR aUTHOR)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.AUTHORs.Add(aUTHOR);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = aUTHOR.ID }, aUTHOR));
        }
Ejemplo n.º 29
0
        public void Remove(AUTHOR auth)
        {
            using (var db = new Libdb())
            {
                var au = db.AUTHOR.FirstOrDefault(a => a.Aid == auth.Aid);

                au.BOOK.Clear();

                db.AUTHOR.Remove(au);
                db.SaveChanges();
            }
        }
Ejemplo n.º 30
0
 /*
  * public void RemoveProjectReference(int depid, int projid)
  * {
  *   using (var db = new dbprojectEntities())
  *   {
  *       _departmentObj = db.departments.ToList().Find(d => d.depid == depid);
  *       if(_departmentObj.projects1.ToList().Exists(x => x.projid == projid)) //Check that there is a row in the intermediate table
  *       {
  *           project projectObject = db.projects.ToList().Find(p => p.projid == projid);
  *           _departmentObj.projects1.Remove(projectObject);
  *           db.SaveChanges();
  *       }
  *   }
  * }*/
 public void removeBookReference(int aId, string removeISBN)
 {
     using (var db = new LibraryDBEntities1())
     {
         _authorObj = db.AUTHORs.Include(x => x.BOOKs).ToList().Find(a => a.Aid == aId);
         if (_authorObj.BOOKs.ToList().Exists(b => b.ISBN == removeISBN))
         {
             BOOK bookObj = db.BOOKs.ToList().Find(b => b.ISBN == removeISBN);
             _authorObj.BOOKs.Remove(bookObj);
             Shared.save(db);
         }
     }
 }