示例#1
0
 public void DeleteChannel(List <int> ids)
 {
     using (var dbContext = new CmsDbContext())
     {
         dbContext.Channels.Where(u => ids.Contains(u.ID)).Delete();
     }
 }
示例#2
0
        public ActionResult LogIn(string userName, string password)
        {
            try {
                using (var context = new CmsDbContext()) {
                    var getUser = (from s in context.ObjUsers where s.UserName == userName || s.EmailId == userName select s).FirstOrDefault();
                    if (getUser != null)
                    {
                        var hashCode = getUser.VCode;
                        //Password Hasing Process Call Helper Class Method
                        var encodingPasswordString = Helper.EncodePassword(password, hashCode);
                        //Check Login Detail User Name Or Password
                        var query = (from s in context.ObjUsers where (s.UserName == userName || s.EmailId == userName) && s.Password.Equals(encodingPasswordString) select s).FirstOrDefault();
                        if (query != null)
                        {
                            Session["UserName"] = userName;

                            return(RedirectToAction("Index", "Places", new { area = "Places" }));
                        }
                        ViewBag.ErrorMessage = "Invalid User Name or Password";
                        return(View());
                    }
                    ViewBag.ErrorMessage = "Invalid User Name or Password";
                    return(View());
                }
            } catch (Exception e) {
                ViewBag.ErrorMessage = e.Message;
                return(View());
            }
        }
示例#3
0
        public static bool CheckUser(string emailId, int[] roles)
        {
            using (var context = new CmsDbContext()) {
                try {
                    var userFromDB = context.ObjUsers.Where(x => x.EmailId == emailId).SingleOrDefault();
                    if (userFromDB != null)
                    {
                        int userId = userFromDB.UserId;

                        //check if user has one of the given rights
                        // source: https://stackoverflow.com/questions/10505595/linq-many-to-many-relationship-how-to-write-a-correct-where-clause
                        var checkRole = context.ObjUsers.Where(user => user.Roles.All(x => roles.Contains(x.RoleId))).Where(y => y.UserId == userId).SingleOrDefault();
                        if (checkRole != null)
                        {
                            return(true);
                        }
                        return(false);
                    }
                    else
                    {
                        return(false);
                    }
                } catch (Exception e) {
                    throw e;
                }
            }
        }
示例#4
0
 public Channel GetChannel(int id)
 {
     using (var dbContext = new CmsDbContext())
     {
         return(dbContext.Find <Channel>(id));
     }
 }
示例#5
0
        public IEnumerable <Article> GetArticleList(ArticleRequest request = null)
        {
            request = request ?? new ArticleRequest();
            using (var dbContext = new CmsDbContext())
            {
                IQueryable <Article> articles = dbContext.Articles.Include("Channel");

                if (!string.IsNullOrEmpty(request.Title))
                {
                    articles = articles.Where(u => u.Title.Contains(request.Title));
                }

                if (request.ChannelId > 0)
                {
                    articles = articles.Where(u => u.ChannelId == request.ChannelId);
                }

                if (request.IsActive != null)
                {
                    articles = articles.Where(u => u.IsActive == request.IsActive);
                }

                return(articles.OrderByDescending(u => u.ID).ToPagedList(request.PageIndex, request.PageSize));
            }
        }
示例#6
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var service = scope.ServiceProvider;
                try
                {
                    RoleManager <IdentityRole> roleManager = service.GetRequiredService <RoleManager <IdentityRole> >();
                    UserManager <User>         userManager = service.GetRequiredService <UserManager <User> >();

                    CmsDbContext context = service.GetRequiredService <CmsDbContext>();

                    DbInitializer.Initialize(context, roleManager, userManager);
                }
                catch (Exception ex)
                {
                    var logger = service.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }

            host.Run();
        }
示例#7
0
        public IEnumerable <Channel> GetChannelList(ChannelRequest request = null)
        {
            request = request ?? new ChannelRequest();
            using (var dbContext = new CmsDbContext())
            {
                IQueryable <Channel> channels = dbContext.Channels;
                //频道名称
                if (!string.IsNullOrWhiteSpace(request.Name))
                {
                    channels = channels.Where(u => u.Name.Contains(request.Name));
                }
                //频道ID
                if (request.ID > 0)
                {
                    channels = channels.Where(t => t.ID == request.ID);
                }
                //父类ID
                if (request.ParentId >= 0)
                {
                    channels = channels.Where(t => t.ParentId == request.ParentId);
                }
                //状态
                if (request.IsActive != null)
                {
                    channels = channels.Where(u => u.IsActive == request.IsActive);
                }

                return(channels.OrderBy(u => u.Flag).ToList());
            }
        }
示例#8
0
 public FormsController(ApplicationDbContext dbContext, CmsDbContext cmsDbContext)
 {
     _dbContext  = dbContext;
     _cmsContext = cmsDbContext;
     _oForms     = GetForms();
     LoadDropDowns();
 }
示例#9
0
        public void SaveArticle(Article article)
        {
            using (var dbContext = new CmsDbContext())
            {
                var tags = new List <Tag>();

                if (article.Tags != null)
                {
                    foreach (var tag in article.Tags)
                    {
                        var existTag = dbContext.Tags.FirstOrDefault(t => t.Name == tag.Name);
                        if (existTag != null)
                        {
                            existTag.Hits++;
                        }
                        tags.Add(existTag ?? tag);
                    }
                }

                if (article.ID > 0)
                {
                    article.TagString = string.Empty;
                    dbContext.Update <Article>(article);
                    dbContext.Entry(article).Collection(m => m.Tags).Load();
                    article.Tags = tags;
                    dbContext.SaveChanges();
                }
                else
                {
                    article.Tags = tags;
                    dbContext.Insert <Article>(article);
                }
            }
        }
示例#10
0
 public Article GetArticle(int id)
 {
     using (var dbContext = new CmsDbContext())
     {
         return(dbContext.Articles.Include("Tags").FirstOrDefault(a => a.ID == id));
     }
 }
 public TopicsController(CmsDbContext dbContext, ILoggerFactory loggerFactory) : base(dbContext, loggerFactory)
 {
     _topicManager     = new TopicManager(dbContext);
     _topicPermissions = new TopicPermissions(dbContext);
     TopicsAttachmentsController();
     TopicsDocumentController();
     TopicsAnalyticsController();
 }
示例#12
0
 private void CreateData()
 {
     Database.SetInitializer(new CmsDbInitializer());
     using (var ctx = new CmsDbContext())
     {
         ctx.Database.Initialize(true);
     }
 }
示例#13
0
 public void DeleteArticle(List <int> ids)
 {
     using (var dbContext = new CmsDbContext())
     {
         dbContext.Articles.Include("Tags").Where(u => ids.Contains(u.ID)).ToList().ForEach(a => { a.Tags.Clear(); dbContext.Articles.Remove(a); });
         dbContext.SaveChanges();
     }
 }
示例#14
0
 private void LoadCustomers()
 {
     using (var ctx = new CmsDbContext())
     {
         foreach (var c in ctx.Customers.AsNoTracking())
         {
             _customers.Add(c);
         }
     }
 }
示例#15
0
 public TeacherRepository(CmsDbContext dbContext)
 {
     _dbContext = dbContext;
     if (_dbContext.Teachers.Count() <= 0)
     {
         _dbContext.Teachers.Add(new Teacher {
             Name = "Indrani", DepartmentId = 1
         });
         _dbContext.SaveChanges();
     }
 }
示例#16
0
        public ActionResult Index()
        {
            List <PageVm> pages;

            using (CmsDbContext db = new CmsDbContext())
            {
                pages = db.Pages.ToArray().OrderBy(x => x.Sorting).Select(x => new PageVm(x)).ToList();
            }

            return(View(pages));
        }
示例#17
0
        public static void SeedHostDb(CmsDbContext context)
        {
            context.SuppressAutoSetTenantId = true;

            // Host seed
            new InitialHostDbBuilder(context).Create();

            // Default tenant seed (in host database).
            new DefaultTenantBuilder(context).Create();
            new TenantRoleAndUserBuilder(context, 1).Create();
        }
示例#18
0
 public NotificationProcessor(
     CmsDbContext dbContext,
     Topic currentTopic,
     int currentUser
     ) : base(dbContext)
 {
     topic            = currentTopic;
     this.currentUser = currentUser;
     emailSender      = (EmailSender)Startup.ServiceProvider.GetService(typeof(IEmailSender)); // TODO: This is probably not such a good idea...
     // Do not notify yourself
     notifiedUsers.Add(currentUser);
 }
示例#19
0
        public IEnumerable <Article> GetArticleList(ArticleRequest request = null)
        {
            request = request ?? new ArticleRequest();
            using (var dbContext = new CmsDbContext())
            {
                IQueryable <Article> articles = dbContext.Articles.Include("Channel");
                if (request.ID > 0)
                {
                    articles = articles.Where(u => u.ID == request.ID);
                }

                if (!string.IsNullOrWhiteSpace(request.Title))
                {
                    if (request.Title.IndexOf('|') > 0)
                    {
                        string[]       words        = request.Title.Split('|');
                        List <Article> articleFlags = new List <Article>();
                        foreach (string w in words)
                        {
                            articleFlags.AddRange(articles.Where(u => u.Title.Contains(w)));
                        }
                        articles = articleFlags.Distinct().AsQueryable();
                    }
                    else
                    {
                        articles = articles.Where(u => u.Title.Contains(request.Title));
                    }
                }

                if (request.ChannelId > 0)
                {
                    articles = articles.Where(u => u.ChannelId == request.ChannelId);
                }

                if (request.IsActive != null)
                {
                    articles = articles.Where(u => u.IsActive == request.IsActive);
                }

                if (request.IsProposed)
                {
                    articles = articles.Where(u => u.IsProposed == true);
                }

                if (request.ChannelIds != null && request.ChannelIds.Count > 0)
                {
                    articles = articles.Where(u => request.ChannelIds.Contains(u.ChannelId));
                }

                return(articles.OrderByDescending(u => u.ID).ToPagedList(request.PageIndex, request.PageSize));
            }
        }
示例#20
0
 public void SaveChannel(Channel channel)
 {
     using (var dbContext = new CmsDbContext())
     {
         if (channel.ID > 0)
         {
             dbContext.Update <Channel>(channel);
         }
         else
         {
             dbContext.Insert <Channel>(channel);
         }
     }
 }
示例#21
0
 private void Backup()
 {
     using (var ctx = new CmsDbContext())
     {
         string dbFileName     = ctx.Database.Connection.DataSource;
         string backupFileName =
             string.Format(
                 "{0}_{1:yyyyMMddHHmmss}.sdf",
                 Path.ChangeExtension(dbFileName, null),
                 DateTime.Now
                 );
         File.Copy(dbFileName, backupFileName);
     }
     MessageBox.Show("完了しました。");
 }
示例#22
0
 private void LoadCars()
 {
     _cars.Clear();
     using (var ctx = new CmsDbContext())
     {
         var cars =
             ctx.Customers
             .Where(x => x.Id == SelectedCustomer.Id)
             .Include(x => x.Cars)
             .Single().Cars;
         foreach (var car in cars)
         {
             _cars.Add(car);
         }
     }
 }
示例#23
0
        public ActionResult EditPage(PageVm model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            using (CmsDbContext db = new CmsDbContext())
            {
                var slug = "Home";
                int id   = model.Id;

                PageDto dto = db.Pages.Find(id);
                dto.Title = model.Title;

                if (model.Slug != "Home")
                {
                    if (string.IsNullOrWhiteSpace(model.Slug))
                    {
                        slug = model.Title.Replace(" ", "-").ToLower();
                    }
                    else
                    {
                        slug = model.Slug.Replace(" ", "-").ToLower();
                    }
                }

                if (db.Pages.Where(x => x.Id != id).Any(x => x.Title == model.Title) ||
                    db.Pages.Where(x => x.Id != id).Any(x => x.Slug == slug))
                {
                    ModelState.AddModelError("", "This slug or title already exist.");
                    return(View(model));
                }

                dto.Slug       = slug;
                dto.Body       = model.Body;
                dto.HasSideBar = model.HasSideBar;
                dto.Sorting    = 100;

                if (db.SaveChanges() > 0)
                {
                    TempData["SuccessMessage"] = "You have Edited this page!";
                    return(RedirectToAction("EditPage"));
                }
            }
            TempData["SuccessMessage"] = "There is an error while updating this page";
            return(View(model));
        }
示例#24
0
        private static SqliteConnection CreateDatabaseAndGetConnection()
        {
            var connection = new SqliteConnection("Data Source=:memory:");

            connection.Open();

            var options = new DbContextOptionsBuilder <CmsDbContext>()
                          .UseSqlite(connection)
                          .Options;

            using (var context = new CmsDbContext(options))
            {
                context.GetService <IRelationalDatabaseCreator>().CreateTables();
            }

            return(connection);
        }
示例#25
0
 private void LoadCars()
 {
     _cars.Clear();
     using (var ctx = new CmsDbContext())
     {
         var customer =
             ctx.Customers
             .Where(c => c.Id == SelectedCustomer.Id)
             .Include(c => c.Cars)
             .AsNoTracking()
             .First();
         foreach (var c in customer.Cars)
         {
             _cars.Add(c);
         }
     }
 }
示例#26
0
 private void LoadWorkHistories()
 {
     _workHistories.Clear();
     using (var ctx = new CmsDbContext())
     {
         var car =
             ctx.Cars
             .Where(c => c.CustomerId == SelectedCustomer.Id)
             .Include(c => c.WorkHistories)
             .AsNoTracking()
             .First();
         foreach (var wh in car.WorkHistories)
         {
             _workHistories.Add(wh);
         }
     }
 }
示例#27
0
        public IEnumerable <Tag> GetTagList(TagRequest request = null)
        {
            request = request ?? new TagRequest();
            using (var dbContext = new CmsDbContext())
            {
                IQueryable <Tag> tags = dbContext.Tags;

                if (request.Orderby == Orderby.Hits)
                {
                    return(tags.OrderByDescending(u => u.Hits).ToPagedList(request.PageIndex, request.PageSize));
                }
                else
                {
                    return(tags.OrderByDescending(u => u.ID).ToPagedList(request.PageIndex, request.PageSize));
                }
            }
        }
示例#28
0
        public IEnumerable <Channel> GetChannelList(ChannelRequest request = null)
        {
            request = request ?? new ChannelRequest();
            using (var dbContext = new CmsDbContext())
            {
                IQueryable <Channel> channels = dbContext.Channels;

                if (!string.IsNullOrEmpty(request.Name))
                {
                    channels = channels.Where(u => u.Name.Contains(request.Name));
                }

                if (request.IsActive != null)
                {
                    channels = channels.Where(u => u.IsActive == request.IsActive);
                }

                return(channels.OrderByDescending(u => u.ID).ToPagedList(request.PageIndex, request.PageSize));
            }
        }
示例#29
0
        public ActionResult AddPage(PageVm pageVm)
        {
            using (CmsDbContext db = new CmsDbContext())
            {
                string  slug;
                PageDto pageDto = new PageDto();

                pageDto.Title = pageVm.Title;

                if (!ModelState.IsValid)
                {
                    return(View());
                }

                if (string.IsNullOrWhiteSpace(pageVm.Slug))
                {
                    slug = pageVm.Title.Replace(" ", "-").ToLower();
                }
                else
                {
                    slug = pageVm.Slug.Replace(" ", "-").ToLower();
                }

                if (db.Pages.Any(x => x.Title == pageVm.Title) || db.Pages.Any(x => x.Slug == slug))
                {
                    ModelState.AddModelError("", "The title already exist");
                    return(View());
                }

                pageDto.Slug       = slug;
                pageDto.Body       = pageVm.Body;
                pageDto.HasSideBar = pageVm.HasSideBar;
                pageDto.Sorting    = 100;

                db.Pages.Add(pageDto);
                db.SaveChanges();

                TempData["SuccessMessage"] = "You have added a new Page";
                return(RedirectToAction("AddPage"));
            }
        }
示例#30
0
        private void DeleteCustomer(Customer customer)
        {
            if (customer == null)
            {
                return;
            }
            var result =
                MessageBox.Show("削除すると元に戻せなくなりますが、宜しいですか?", "警告", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result != MessageBoxResult.Yes)
            {
                return;
            }
            using (var ctx = new CmsDbContext())
            {
                var c = ctx.Customers.Find(customer.Id);
                ctx.Customers.Remove(c);
                ctx.SaveChanges();
            }
            this.Customers.Remove(customer);
        }