Пример #1
0
 public static string GetAllPeopleHasAccess(int BookID)
 {
     string returnString = string.Empty;
     var context = new ClanographyContext();
     string myemail = HttpContext.Current.User.Identity.Name;
     var emails = from bp in context.BookPermissions
                  where bp.BookID == BookID &
                  bp.EmailAddress != HttpContext.Current.User.Identity.Name
                  select bp.EmailAddress;
     foreach (var item in emails)
     {
         returnString += item + Environment.NewLine;
     }
     return returnString;
 }
Пример #2
0
        public static Book AddBook(AddBookViewModel form)
        {
            try
            {
                var context = new ClanographyContext();
                var book = new Book();
                book.Name = form.BookName;
                book.Description = form.Description;
                book.OwnerEmail = HttpContext.Current.User.Identity.Name;
                book.CreationDate = DateTime.Now;
                book.ModifiedDate = DateTime.Now;
                context.Books.Add(book);
                context.SaveChanges();
                BookPermission bp = new BookPermission();

                //Add Self Permission
                bp.BookID = book.ID;
                bp.EmailAddress = HttpContext.Current.User.Identity.Name;
                bp.PermissionFlag = 1;
                context.BookPermissions.Add(bp);
                context.SaveChanges();
                //Add Permissions For Others
                if (!string.IsNullOrWhiteSpace(form.PeopleWithAccess))
                {
                    string[] emails = form.PeopleWithAccess.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

                    foreach (var email in emails)
                    {
                        if (Helpers.Common.IsValidEmail(email))
                        {
                            //Sends An Email
                            bp = new BookPermission();
                            bp.BookID = book.ID;
                            bp.EmailAddress = email;
                            bp.PermissionFlag = 1;
                            context.BookPermissions.Add(bp);
                        }
                    }
                    context.SaveChanges();
                }
                return book;
            }
            catch (Exception)
            {
                return null;
            }
        }
Пример #3
0
 public static List<string> GetAllPeopleListHasAccess(int BookID)
 {
     List<string> returnList = new List<string>();
     var context = new ClanographyContext();
     string myemail = HttpContext.Current.User.Identity.Name;
     var emails = from bp in context.BookPermissions
                  where bp.BookID == BookID &
                  bp.EmailAddress != HttpContext.Current.User.Identity.Name
                  select bp.EmailAddress;
     foreach (var item in emails)
     {
         returnList.Add(item);
     }
     return returnList;
 }
Пример #4
0
        public List<Book> GetAllBooks()
        {
            List<Book> books = new List<Book>();
            var context = new ClanographyContext();
            var myEmail = HttpContext.Current.User.Identity.Name;
            books = (from b in context.Books
                     join p in context.BookPermissions
                     on b.ID equals p.BookID
                     where p.EmailAddress == myEmail
                     select b).ToList();

            return books;
        }
Пример #5
0
 public static void UpdatePage(EditPageViewModel form)
 {
     try
     {
         var context = new ClanographyContext();
         var page = context.Pages.SingleOrDefault(i => i.ID == form.ID);
         page.ModifiedDate = DateTime.Now;
         page.ModifierEmail = HttpContext.Current.User.Identity.Name;
         page.Name = form.Name;
         page.PageNumber = form.PageNumber;
     }
     catch { }
 }
Пример #6
0
        public static bool UpdateBook(EditBookViewModel form)
        {
            try
            {
                var context = new ClanographyContext();
                Book newbook = context.Books.FirstOrDefault(i => i.ID == form.ID);
                newbook.ModifiedDate = DateTime.Now;
                newbook.ModifierEmail = HttpContext.Current.User.Identity.Name;
                newbook.Description = form.Description;
                context.SaveChanges();
                //Add Permissions For Others
                if (!string.IsNullOrWhiteSpace(form.PeopleWithAccess))
                {
                    //Clear Permissions
                    BookPermission bp = new BookPermission();
                    var bplist = context.BookPermissions.Where(i => i.BookID == form.ID);
                    foreach (var item in bplist)
                    {
                        context.BookPermissions.Remove(item);
                    }
                    //self Permission
                    bp.BookID = form.ID;
                    bp.EmailAddress = HttpContext.Current.User.Identity.Name;
                    bp.PermissionFlag = 1;
                    context.BookPermissions.Add(bp);

                    string[] emails = form.PeopleWithAccess.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

                    foreach (var email in emails)
                    {
                        if (Helpers.Common.IsValidEmail(email))
                        {
                            //Sends An Email
                            bp = new BookPermission();
                            bp.BookID = form.ID;
                            bp.EmailAddress = email;
                            bp.PermissionFlag = 1;
                            context.BookPermissions.Add(bp);
                        }
                    }
                    context.SaveChanges();
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
Пример #7
0
 public static int GetTotalPage(int BookID)
 {
     var context = new ClanographyContext();
     var pages = context.Pages.Where(b => b.BookID == BookID).Count();
     return pages;
 }
Пример #8
0
 public static Page GetCurrentPage(int PageNumber, int BookID)
 {
     try
     {
         var context = new ClanographyContext();
         var page = context.Pages.Where(b => b.BookID == BookID && b.PageNumber == PageNumber).FirstOrDefault();
         return page;
     }
     catch (Exception)
     {
         return null;
     }
 }
Пример #9
0
 public static Book GetBook(int id)
 {
     var context = new ClanographyContext();
     Book book = context.Books.FirstOrDefault(i => i.ID == id);
     return book;
 }