Пример #1
0
        public static void Update(AuthorViewModel target)
        {
            AuthorDao dao = new AuthorDao();

            dao.Update(target.ToEntity());
            s_logger.Debug($"UPDATE Author:{target}");
        }
Пример #2
0
        public static void Create(AuthorViewModel target)
        {
            AuthorDao dao = new AuthorDao();

            dao.Insert(target.ToEntity());
            s_logger.Debug($"INSERT Author:{target}");
        }
Пример #3
0
 public IAuthorDao Create(string authorName)
 {
     var dao = new AuthorDao { Name = authorName };
     Context.Authors.Add(dao);
     Context.SaveChanges();
     return dao;
 }
        public JsonResult Edit(Author author)
        {
            // result return true  if update successfully, else return false
            var result = AuthorDao.CreateOrEdit(author) > 0;

            return(Json(result));
        }
Пример #5
0
        public void Find()
        {
            ResetDatabase();

            AuthorDao dao = (AuthorDao)Container[typeof(AuthorDao)];

            Author author1 = new Author("hamilton verissimo", "hammett", "mypass");
            Author author2 = new Author("john turturro", "turturro", "mypass");

            dao.Create(author1);
            dao.Create(author2);

            Author found = dao.Find("hammett");

            Assert.IsNotNull(found);
            Assert.AreEqual(author1.Name, found.Name);
            Assert.AreEqual(author1.Login, found.Login);
            Assert.AreEqual(author1.Password, found.Password);

            found = dao.Find("turturro");
            Assert.IsNotNull(found);
            Assert.AreEqual(author2.Name, found.Name);
            Assert.AreEqual(author2.Login, found.Login);
            Assert.AreEqual(author2.Password, found.Password);
        }
        public JsonResult Delete(int id)
        {
            // result return true  if delete successfully, else return false
            var result = AuthorDao.Delete(id) > 0;

            return(Json(result));
        }
        public JsonResult Create(Author author)
        {
            author.IsActive = true;
            var result = AuthorDao.CreateOrEdit(author) > 0;

            return(Json(result));
        }
Пример #8
0
        public static void Delete(Guid id)
        {
            AuthorDao dao = new AuthorDao();

            dao.DeleteWhereIDIs(id);
            s_logger.Debug($"DELETE Author:{id}");
        }
Пример #9
0
        public void Create()
        {
            ResetDatabase();

            AuthorDao authorDao = (AuthorDao)Container[typeof(AuthorDao)];
            BlogDao   blogDao   = (BlogDao)Container[typeof(BlogDao)];
            PostDao   postDao   = (PostDao)Container[typeof(PostDao)];

            Author author = new Author("hamilton verissimo", "hammett", "mypass");
            Blog   blog   = new Blog("hammett's blog", "my thoughts.. ugh!", "default", author);

            Post post = new Post("My first entry", "This is my first entry", DateTime.Now);

            post.Blog = blog;

            authorDao.Create(author);
            blogDao.Create(blog);
            postDao.Create(post);

            IList posts = postDao.Find();

            Assert.AreEqual(1, posts.Count);

            Post comparisson = (Post)posts[0];

            Assert.AreEqual(post.Title, comparisson.Title);
            Assert.AreEqual(post.Contents, comparisson.Contents);
        }
        public ActionResult Author(string id)
        {
            var TacGia     = new AuthorDao().GetTacgiaByTenTacGia(id);
            var listAuthor = new ProductDao().GetLoaiSachByIDTacGia(TacGia.MaTacGia);

            return(View(listAuthor));
        }
Пример #11
0
        public ActionResult ListAllProductByAuthor(long id, int page = 1, int pageSize = 6)
        {
            Session[Constants.CURRENT_URL]     = HttpContext.Request.RawUrl;
            Session[Constants.CATEGORY_ACTIVE] = null;
            Session[Constants.CATE_ID]         = Convert.ToInt64(0);
            Session[Constants.AUTHOR_ID]       = id;
            var product = new ProductDao().ListProductbyAuthor(id);
            var author  = new AuthorDao().GetDetail(id);

            Session[Constants.LISTPRODUCT]            = product;
            Session[Constants.LISTPRODUCT_VIEWNAME]   = "Index";
            Session[Constants.LISTPRODUCT_ACTIONNAME] = "ListAllProductByAuthor";

            Session[Constants.MINPRICE]          = Convert.ToDecimal(0);
            Session[Constants.MAXPRICE]          = decimal.MaxValue;
            Session[Constants.SORT_ACTIVE]       = 1;
            Session[Constants.SORTSTATUS_ACTIVE] = 1;

            Session[Constants.STATUSNAME_PRODUCT] = "Tìm theo tác giả : " + author.Name;

            int    totalRecord = product.Count();
            string link        = "/san-pham-theo-tac-gia-" + id + "?";
            var    listproduct = product.Skip((page - 1) * pageSize).Take(pageSize).ToList();

            SetPagination(totalRecord, pageSize, page, link);

            if (Session[Constants.USER_INFO] != null)
            {
                new LogDao().SetLog("ListAllProductByAuthor", "Tác giả : " + author.Name.ToString() + ", Trang : " + page.ToString(), ((User)Session[Constants.USER_INFO]).ID);
            }

            return(View((string)Session[Constants.LISTPRODUCT_VIEWNAME], listproduct));
        }
Пример #12
0
        private void ImportAuthor(ILibrary libManager, AuthorViewModel add)
        {
            AuthorDao authorDao = new AuthorDao();

            authorDao.Insert(add.ToEntity(), _dataOpUnit.CurrentConnection);
            libManager.AuthorManager.Authors.Add(add);
        }
Пример #13
0
 public ActionResult Delete(Author author)
 {
     if (((User)Session[Constants.USER_INFO]).GroupID == Constants.GROUP_ADMIM)
     {
         var setnull = new ProductDao().SetNullAuthor(author.ID);
         if (setnull)
         {
             var result = new AuthorDao().Remove(author);
             if (result)
             {
                 SetAlert("Xoá Author thành công", Constants.ALERTTYPE_SUCCESS);
                 new LogDao().SetLog("Admin_Author_Delete", "Xoá Author thành công", ((User)Session[Constants.USER_INFO]).ID);
                 return(RedirectToAction("Index", "Author"));
             }
             else
             {
                 SetAlert("Xoá Author không thành công", Constants.ALERTTYPE_ERROR);
                 new LogDao().SetLog("Admin_Author_Delete", "Xoá Author không thành công", ((User)Session[Constants.USER_INFO]).ID);
                 return(RedirectToAction("Index", "Author"));
             }
         }
     }
     SetAlert("Tài khoản của bạn không có quyền", Constants.ALERTTYPE_ERROR);
     new LogDao().SetLog("Admin_Author_Delete", "Tài khoản của bạn không có quyền", ((User)Session[Constants.USER_INFO]).ID);
     return(RedirectToAction("Index", "Author"));
 }
Пример #14
0
        public void FindBlogPosts()
        {
            ResetDatabase();

            AuthorDao authorDao = (AuthorDao)Container[typeof(AuthorDao)];
            BlogDao   blogDao   = (BlogDao)Container[typeof(BlogDao)];

            Author author = new Author("hamilton verissimo", "hammett", "mypass");
            Blog   blog   = new Blog("hammett's blog", "my thoughts.. ugh!", "default", author);

            authorDao.Create(author);
            blogDao.Create(blog);

            Post post1 = new Post("My first entry", "This is my first entry", DateTime.Now);

            post1.Blog = blog;
            Post post2 = new Post("My second entry", "This is my second entry", DateTime.Now);

            post2.Blog = blog;

            PostDao postDao = (PostDao)Container[typeof(PostDao)];

            postDao.Create(post1);
            postDao.Create(post2);

            IList posts = postDao.Find(blog);

            Assert.AreEqual(2, posts.Count);
        }
Пример #15
0
        private void SetAuthorTo(IAuthorManager authorManager, BookViewModel add)
        {
            IDConversionDao idcDao    = new IDConversionDao();
            AuthorDao       authorDao = new AuthorDao();
            var             idc       = idcDao.FindBy(new Dictionary <string, object>()
            {
                { "TableName", "Author" }, { "ForeignID", add.AuthorID }
            }, _dataOpUnit.CurrentConnection);

            if (idc.Count() == 1)
            {
                add.Author = authorDao.FindBy(new Dictionary <string, object>()
                {
                    { "ID", idc.Single().DomesticID }
                }, _dataOpUnit.CurrentConnection).SingleOrDefault().ToViewModel();
            }
            else
            {
                add.Author = authorDao.FindBy(new Dictionary <string, object>()
                {
                    { "ID", add.AuthorID }
                }, _dataOpUnit.CurrentConnection).SingleOrDefault().ToViewModel();
            }
            authorManager.ObserveAuthorCount();
        }
Пример #16
0
        public ActionResult Index(int page = 1, int pageSize = 5)
        {
            var dao   = new AuthorDao();
            var model = dao.ListAllPaging(page, pageSize);

            return(View(model));
        }
Пример #17
0
 public static List <AuthorDto> GetAllNotDeletedAuthors()
 {
     if (allNotDeletedAuthors == null || allNotDeletedAuthors.Count == 0)
     {
         allNotDeletedAuthors = AuthorDao.Where(n => n.IsDeleted == false).ToList();
     }
     return(allNotDeletedAuthors);
 }
        public override void DropTable(IConnection connection)
        {
            AuthorDao dao = new AuthorDao(typeof(VersionOrigin));

            dao.CurrentConnection = connection;
            dao.DropTable();
            ++ModifiedCount;
        }
Пример #19
0
        public ActionResult Detail(long id)
        {
            SetActiveSlideBar(Constants.SLIDEBAR_AD_AUTHOR);
            var AuthorModel = new AuthorDao().GetDetail(id);

            new LogDao().SetLog("Admin_Author_Detail", null, ((User)Session[Constants.USER_INFO]).ID);
            return(View(AuthorModel));
        }
Пример #20
0
        // GET: Admin/Author
        public ActionResult Index()
        {
            SetActiveSlideBar(Constants.SLIDEBAR_AD_AUTHOR);
            var AuthorModel = new AuthorDao().ListAllAuthor();

            new LogDao().SetLog("Admin_Author_Index", null, ((User)Session[Constants.USER_INFO]).ID);
            return(View(AuthorModel));
        }
Пример #21
0
 public static List <string> GetAuthorNameList()
 {
     if (authorList == null || authorList.Count == 0)
     {
         authorList = AuthorDao.Where(n => n.IsDeleted == false).ToList();
     }
     return(authorList.Select(n => n.Name).ToList());
 }
Пример #22
0
 public static List <AuthorDto> GetAllAuthors()
 {
     if (authorList == null || authorList.Count == 0)
     {
         authorList = AuthorDao.GetAll();
     }
     return(authorList);
 }
        //
        // GET: /Admin/Author/
        public ActionResult Index(string searchString, int page = 1, int pageSize = 10)
        {
            var dao   = new AuthorDao();
            var model = dao.ListAllpaging(searchString, page, pageSize);

            ViewBag.searchString = searchString;
            return(View(model));
        }
Пример #24
0
        public ActionResult Create(Author author, HttpPostedFileBase postedFile)
        {
            if (((User)Session[Constants.USER_INFO]).GroupID == Constants.GROUP_ADMIM)
            {
                if (ModelState.IsValid)
                {
                    var    userinfo = (User)Session[Constants.USER_INFO];
                    string path;
                    string filename     = "";
                    string fullfilename = "";
                    if (postedFile == null)
                    {
                        fullfilename = "computer-icons-user-profile-login-my-account-icon-png-clip-art.png";
                        path         = Path.Combine(Server.MapPath("~/Data/ImgAuthor"), fullfilename);
                        //postedFile.SaveAs(path);
                    }
                    else
                    {
                        //Luu ten fie, luu y bo sung thu vien using System.IO;
                        filename     = Path.GetFileName(postedFile.FileName);
                        fullfilename = filename.Split('.')[0] + "(" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + ")." + filename.Split('.')[1];
                        //Luu duong dan cua file
                        path = Path.Combine(Server.MapPath("~/Data/ImgAuthor"), fullfilename);
                        postedFile.SaveAs(path);
                    }

                    author.Image     = fullfilename;
                    author.Status    = true;
                    author.CreatedBy = userinfo.UserName;
                    author.MetaTitle = Unicode.RemoveUnicode(author.Name).Replace(" ", "-").ToLower().ToString();
                    author.Tag       = Unicode.RemoveUnicode(author.Name).ToLower().ToString();
                    //author.CreatedBy = Session[Constants.USER_USERNAME].ToString();

                    long id = new AuthorDao().Insert(author);
                    if (id > 0)
                    {
                        SetAlert("Tạo Author thành công", Constants.ALERTTYPE_SUCCESS);
                        new LogDao().SetLog("Admin_Author_Create", "Tạo Author thành công", ((User)Session[Constants.USER_INFO]).ID);
                        return(RedirectToAction("Index", "Author"));
                    }
                    else
                    {
                        SetAlert("Tạo Author không thành công", Constants.ALERTTYPE_ERROR);
                        new LogDao().SetLog("Admin_Author_Create", "Tạo Author không thành công", ((User)Session[Constants.USER_INFO]).ID);
                        return(RedirectToAction("Index", "Author"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Dữ liệu không lệ");
                    new LogDao().SetLog("Admin_Author_Create", "Dữ liệu không hợp lệ", ((User)Session[Constants.USER_INFO]).ID);
                    return(View("Create", author));
                }
            }
            SetAlert("Tài khoản của bạn không có quyền", Constants.ALERTTYPE_ERROR);
            new LogDao().SetLog("Admin_Author_Create", "Tài khoản của bạn không có quyền", ((User)Session[Constants.USER_INFO]).ID);
            return(RedirectToAction("Index", "Author"));
        }
Пример #25
0
        public ActionResult Author(long Au_id)
        {
            var author = new AuthorDao().ViewDetail(Au_id);

            ViewBag.Author = author;
            var model = new BookDao().ListByAuthor(Au_id);

            return(View(model));
        }
Пример #26
0
        public static bool Exists(Guid authorID, DataOperationUnit dataOpUnit = null)
        {
            AuthorDao dao = new AuthorDao();

            return(dao.CountBy(new Dictionary <string, object>()
            {
                { "ID", authorID }
            }, dataOpUnit?.CurrentConnection) > 0);
        }
Пример #27
0
        public static bool Exists(string name, DataOperationUnit dataOpUnit = null)
        {
            AuthorDao dao = new AuthorDao();

            return(dao.CountBy(new Dictionary <string, object>()
            {
                { "Name", name }
            }, dataOpUnit?.CurrentConnection) > 0);
        }
Пример #28
0
        public static AuthorViewModel FindBy(Guid id, DataOperationUnit dataOpUnit = null)
        {
            AuthorDao dao = new AuthorDao();

            return(dao.FindBy(new Dictionary <string, object>()
            {
                { "ID", id }
            }, dataOpUnit?.CurrentConnection).SingleOrDefault().ToViewModel());
        }
Пример #29
0
        public static IEnumerable <Author> FindBy(string name, DataOperationUnit dataOpUnit = null)
        {
            AuthorDao dao = new AuthorDao();

            return(dao.FindBy(new Dictionary <string, object>()
            {
                { "Name", name }
            }, dataOpUnit?.CurrentConnection));
        }
Пример #30
0
        public ActionResult Partial_Menu()
        {
            var cate = new ProductCategoryDao().ListAllProductCategoryActive().OrderBy(x => x.Name).ToList();
            var aut  = new AuthorDao().ListAllAuthorActive().OrderBy(x => x.Name).ToList();

            ViewBag.Category = cate;
            ViewBag.Author   = aut;
            return(PartialView());
        }
Пример #31
0
        public JsonResult ChangeStatus(long id)
        {
            var result = new AuthorDao().ChangeStatus(id);

            return(Json(new
            {
                status = result
            }));
        }
Пример #32
0
 //endregion
 //region service
 //todo 暂时只接受分页参数,不接受查询参数
 public ActionResult JAuthorList(int draw, int start, int length, AuthorCondnition c)
 {
     PagingArgument page = new PagingArgument();
     page.start = start;
     page.size = length;
     List<Author> data = null;
     using (AuthorDao dao = new AuthorDao())
         data = dao.Find(c, page);
     DataResponse r = new DataResponse();
     r.draw = draw;
     r.data = data;
     r.recordsFiltered = page.count;
     return Json(r, JsonRequestBehavior.AllowGet);
 }
 public static void downloadAllAvatarAvatar()
 {
     List<string> temp;
     PagingArgument page = new PagingArgument();
     page.index = 0;
     page.size = 10;
     using (AuthorDao dao = new AuthorDao())
     {
         do
         {
             temp = dao.Find(null, page).Select(t => t.Image).ToList();
             page.index++;
             foreach (string a in temp)
             {
                 if (!string.IsNullOrEmpty(a))
                     downloadAvatar(a, "d:\\avatar");
             }
         } while (temp.Count > 0);
     }
 }
 //所有作者写到数据库中
 public static void WriteAllAuthor(int begin)
 {
     for (int i = begin; i <= 978; i++)
     {
         Author a = GetAuthor(i);
         int result = 0;
         using (AuthorDao dao = new AuthorDao())
             result = dao.add(a);
         if (result < 0)
             throw new ApplicationException("插入错误");
     }
     Console.WriteLine("数据下载完毕");
 }
Пример #35
0
        public ActionResult Import()
        {
            object results = "Pouet";
            ElementDao dao = new ElementDao(cvDb);
            AuthorDao authDao = new AuthorDao(cvDb);

            List<Author> authors = authDao.GetAuthors();
            List<Element> newWsElementsId = dao.GetAllElements(true).ToList();

            // Appel à l'ancien WS
            OldWSRetriever retriever = new OldWSRetriever();
            bool mergeComplete = false;
            int page = 1;
            int count = 0;

            while (mergeComplete == false)
            {
                List<Element> elements = retriever.GetElements(page);

                if (elements == null || elements.Count == 0)
                {
                    mergeComplete = true;
                }
                else
                {
                    foreach (Element oldE in elements)
                    {
                        if (newWsElementsId.Where(newE => newE.Title.ToLowerInvariant() == oldE.Title.ToLowerInvariant()).Count() == 0)
                        {
                            // Auteur
                            Author aut = authors.Where(a => a.Name.ToLower() == oldE.Author.Name.ToLowerInvariant()).FirstOrDefault();

                            if (aut != null)
                            {
                                oldE.Author = aut;

                                count++;

                                // Ajout
                                if (dao.Create(oldE) == false)
                                {
                                    throw dao.LastException;
                                }
                            }
                        }
                        else
                        {
                            mergeComplete = true;
                            break;
                        }
                    }

                    if (mergeComplete == false)
                    {
                        page++;
                    }
                }
            }

            results = count + " élements ajoutés sur " + page + " pages.";

            return View(results);
        }
Пример #36
0
        public Element ToElement()
        {
            AuthorDao autdao = new AuthorDao(cvDb);
            var authors = autdao.GetAuthors();

            Element e = null;

            if (Type == "word")
            {
                Word w = new Word();

                if (string.IsNullOrEmpty(Details1) == false && string.IsNullOrEmpty(Content1) == false)
                {
                    w.Definitions.Add(new Definition()
                    {
                        Id = IdDef1,
                        Content = Content1,
                        Details = Details1,
                        WordId = w.Id
                    });
                }
                if (string.IsNullOrEmpty(Details2) == false && string.IsNullOrEmpty(Content2) == false)
                {
                    w.Definitions.Add(new Definition()
                    {
                        Id = IdDef2,
                        Content = Content2,
                        Details = Details2,
                        WordId = w.Id
                    });
                }
                if (string.IsNullOrEmpty(Details3) == false && string.IsNullOrEmpty(Content3) == false)
                {
                    w.Definitions.Add(new Definition()
                    {
                        Id = IdDef3,
                        Content = Content3,
                        Details = Details3,
                        WordId = w.Id
                    });
                }

                e = w;
            }
            else
            {
                Contrepeterie ctp = new Contrepeterie();

                ctp.Content = Content;
                ctp.Solution = Solution;

                e = ctp;
            }

            e.Author = authors.Where(a => a.Id == AuthorId).FirstOrDefault();
            e.Id = ElementId;
            e.Title = Title;
            e.Date = Date;
            e.FavoriteCount = VoteCount;

            return e;
        }
Пример #37
0
 public ElementViewModel()
 {
     AuthorDao autdao = new AuthorDao(cvDb);
     Authors = autdao.GetAuthors();
 }
 //向数据库写一个作者
 public static void WriteAuthor(int id)
 {
     Author a = GetAuthor(id);
     int result = 0;
     using (AuthorDao dao = new AuthorDao())
         result = dao.add(a);
     Console.WriteLine("已经写入" + result + "个作者");
 }