コード例 #1
0
ファイル: BugController.cs プロジェクト: Itslet/BugBase
        public ActionResult Create(Bug bug)
        {
            var BugSession = new MongoSession<Bug>();
            var UserSession = new MongoSession<User>();
            var ProjectSession = new MongoSession<BugProject>();

            var gebr = UserSession.Queryable.AsEnumerable();
            var bugpr = ProjectSession.Queryable.AsEnumerable();
            string id = "51495c0264489c9010010000";
            var bp = bugpr.Where(ps => ps.Id == (Norm.ObjectId)id).FirstOrDefault();

            var thisuser = UserSession.Queryable.AsEnumerable().Where(u => u.Email == User.Identity.Name).FirstOrDefault();

            bug.BugSubmitter = thisuser;
            bug.BugProject = bp;

            BugSession.Save(bug);

            if (Request.IsAjaxRequest())
            {
                return Json(bug);
            }

            return new RedirectResult("Create");
        }
コード例 #2
0
ファイル: Utils.cs プロジェクト: nakedslavin/slovo
        public static string MediaUrlEncode(string url, string mime)
        {
            if (!url.Contains("&"))
            {
                return(url);
            }
            var hash   = MD5Hash(url);
            var client = new MongoSession <EnclosureLink>();
            var stored = client.Get(_ => _.ShortUrl == hash).FirstOrDefault();

            if (stored == null)
            {
                var linkObject = new EnclosureLink {
                    RealUrl = url, ShortUrl = hash
                };
                client.Save(linkObject);
                stored = linkObject;
            }
            string ext = ".mp3";

            if (mime == "audio/aac")
            {
                ext = ".aac";
            }
            if (mime == "audio/ogg")
            {
                ext = ".ogg";
            }

            var link = "http://slovo.io/a/" + stored.ShortUrl + ext;

            return(link);
        }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: nakedslavin/slovo
        public IActionResult Radio([FromBody] Podcast podcast)
        {
            var session = new MongoSession <Podcast>();
            var name    = podcast.Name.ToLower().Trim();

            var pod = new Podcast();

            pod.Host     = "slovo.io";
            pod.Title    = podcast.Title;
            pod.Name     = CleanName(name);
            pod.Link     = "http://" + pod.Host + "/l/" + pod.Name;
            pod.Category = "Radio (NEW)";
            pod.Keywords = new List <string> {
                "radio"
            };
            pod.Podcasts = podcast.Podcasts;
            pod.Image    = podcast.Image;
            pod.PubDate  = Utils.ConvertToPubDate(DateTime.UtcNow);
            //pod.HumanId = podcast.HumanId;
            pod.HumanFullName     = podcast.HumanFullName;
            pod.HumanName         = podcast.HumanName;
            pod.HumanId           = podcast.HumanId;
            pod.CreationTimestamp = DateTime.UtcNow;
            //pod.BuildTimestamp = DateTime.UtcNow;
            pod.Author    = podcast.HumanName;
            pod.Copyright = podcast.HumanName;
            pod.Items     = new List <Item>();

            session.Save(pod);

            return(Json(pod));
        }
コード例 #4
0
        public void Demonstrate_ComplexPersistance()
        {
            var patient = new Patient {
                FirstName = "John",
                LastName = "Doe",
                DateOfBirth = new DateTime(1980, 1, 1),
                Prescriptions = new List<Prescription> {
                    new Prescription {
                        DatePrescribed = DateTime.Now,
                        Medication = "Asprin",
                        Dosage = "200mg",
                        NumberOfRefils = 1000
                    }
                },
                Visits = new List<ProviderVisit> {
                    new ProviderVisit {
                        DateOfVisit = DateTime.Now,
                        ProviderName = "Townsville Healthcare",
                        ProviderNotes = "Patient is a pain in the arse."
                    }
                }
            };

            var session = new MongoSession();
            session.Save(patient);

            var fetched = session.Query<Patient>()
                .Where(x => x.LastName == "Doe");

            Assert.IsNotNull(fetched.First());
        }
コード例 #5
0
ファイル: HomeController.cs プロジェクト: nakedslavin/slovo
        private Podcast UpdatePodcastItems(Podcast podcast, MongoSession <Podcast> session)
        {
            if (DateTime.UtcNow.Subtract(podcast.BuildTimestamp).TotalMinutes > 30)
            {
                var items = new List <Item>();
                if (podcast.Podcasts != null && podcast.Podcasts.Count > 0)
                {
                    var podcasts = new List <Podcast>();
                    var pods     = podcast.Podcasts.Select(pod => session.Get(_ => _.Id == pod).FirstOrDefault());
                    foreach (var pod in pods)
                    {
                        if (pod == null)
                        {
                            continue;
                        }
                        var p = UpdatePodcastItems(pod, session);
                        podcasts.Add(p);
                    }
                    // HACK
                    items = podcasts.SelectMany(p => p.Items).OrderByDescending(p => Utils.ConvertFromPubDate(p.PubDate)).ToList();
                }
                else
                {
                    items = Parsers.GetParser(podcast.Host).Parse(podcast.Link).Items;
                }

                podcast.Items          = items;
                podcast.BuildTimestamp = DateTime.UtcNow;
                session.Save(podcast);
            }

            return(podcast);
        }
コード例 #6
0
        public ActionResult AgregarVoto(int id2)
        {
            var category = new Category {IdDestino = id2, Nickname = Session["data"] as string, Voto = "1"};

            using (var session = new MongoSession<Category>())
            {
                session.Save(category);
                return RedirectToAction("Index", "Destino", new { idViaje = Session["idViaje"] });
            }
        }
コード例 #7
0
        public ActionResult ProjectPost(Project project)
        {
            if (project.Id == null)
            {
                project.UserName  = User.Identity.Name;
                project.Timestamp = DateTime.UtcNow;
            }
            projSession.Save(project);

            var currentProjects = projSession.Get(_ => _.UserName == User.Identity.Name).OrderByDescending(x => x.Id).ToList();

            return(Json(currentProjects, JsonRequestBehavior.AllowGet));
        }
コード例 #8
0
        public ActionResult Post(Message message)
        {
            var msg = message;

            msg.FromUserName = User.Identity.Name;
            if (!string.IsNullOrWhiteSpace(msg.Body) && !string.IsNullOrWhiteSpace(msg.ToUserName))
            {
                // check if user exists
                msg.ToUserName = msg.ToUserName.Trim();
                msg.Timestamp  = DateTime.UtcNow;
                session.Save(msg);
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
コード例 #9
0
        public void Demonstrate_DbReference()
        {
            var session = new MongoSession();

            var supplier = new Supplier { Name = "Acme" };
            session.Save(supplier);

            var product = new Product {
                Name = "Shovel",
                Price = "17.50",
                Sku = "a3k4j22je9",
                Weight = "11",
                Supplier = new DbReference<Supplier>(supplier.Id)
            };
            session.Save(product);

            var fetched = session.Query<Product>().Where(x => x.Sku == product.Sku);

            Assert.AreEqual(fetched.First().Supplier.Id, supplier.Id);

            var fetchedSupplier = fetched.First().Supplier.Fetch(() => session.GetDb());

            Assert.AreEqual(fetchedSupplier.Name, supplier.Name);
        }
コード例 #10
0
        public static void InitializePermissions(Type p, string connectionString)
        {
            var session = new MongoSession(connectionString);
            List<MembershipPermission> permissions = new List<MembershipPermission>();
            List<string> dbPermission = session.Permissions.Select(x => x.Name).ToList();

            foreach (FieldInfo field in p.GetFields(BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.Public))
            {
                string value = field.GetRawConstantValue().ToString();
                if (!dbPermission.Contains(value))
                {
                    session.Save(new MembershipPermission { Name = value });
                }
            }
        }
コード例 #11
0
ファイル: HomeController.cs プロジェクト: nakedslavin/slovo
        public IActionResult Send()
        {
            string note = null;

            using (var sr = new StreamReader(Request.Body))
                note = sr.ReadToEnd();
            if (!string.IsNullOrWhiteSpace(note) && note.Length > 5)
            {
                var msg = new Message();
                msg.Text = note;
                var session = new MongoSession <Message>();
                session.Save(msg);
            }
            return(new StatusCodeResult(200));
        }
コード例 #12
0
        public ActionResult Edit(int id, EditUser model)
        {
            if (ModelState.IsValid)
            {
                var user = _session.Users.SingleOrDefault(x => x.UserId == id);
                if (user == null)
                {
                    return(HttpNotFound());
                }
                user.UserName = model.EmailAddress;
                if (user.CatchAll == null)
                {
                    user.CatchAll = new BsonDocument();
                }
                user.CatchAll["Name"] = (BsonString)model.Name;

                _session.Save(user);

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
コード例 #13
0
ファイル: HomeController.cs プロジェクト: nakedslavin/slovo
        public IActionResult Index([FromBody] JObject obj)
        {
            var session = new MongoSession <Podcast>();

            var address  = obj["address"].ToString().Trim().TrimEnd('/');
            var name     = obj["name"].ToString().ToLower().Trim();
            var category = obj["category"].ToString();

            if (Uri.TryCreate(address, UriKind.Absolute, out Uri uri))
            {
                var     storedCasts = session.Get(p => p.Link == address || p.Name == name);
                Podcast podcast;
                if (storedCasts.Count != 0)
                {
                    podcast = storedCasts.First();
                }
                else
                {
                    string host = uri.Host;
                    if (uri.Host == "youtu.be" || uri.Host == "youtube.com")
                    {
                        host = "www.youtube.com";
                    }

                    podcast          = Parsers.GetParser(host).Parse(address);
                    podcast.Category = category;
                    podcast.Name     = CleanName(name);

                    session.Save(podcast);
                }

                //string xmlPodcast = XmlParser.Parse(podcast);
                return(Json(podcast));
            }
            else
            {
                return(Json(null));
            }
        }
コード例 #14
0
ファイル: HomeController.cs プロジェクト: nakedslavin/slovo
 public IActionResult Update([FromBody] Podcast podcast)
 {
     if (!string.IsNullOrWhiteSpace(podcast.Id))
     {
         var session = new MongoSession <Podcast>();
         var stored  = session.Get(_ => _.Id == podcast.Id).FirstOrDefault();
         if (stored != null)
         {
             stored.Name        = CleanName(podcast.Name);
             stored.Title       = podcast.Title;
             stored.Description = podcast.Description;
             stored.Copyright   = podcast.Copyright;
             stored.Author      = podcast.Author;
             stored.Link        = podcast.Link;
             stored.Image       = podcast.Image;
             stored.Language    = podcast.Language;
             stored.Category    = podcast.Category;
             session.Save(stored);
             return(new StatusCodeResult(200));
         }
     }
     return(new StatusCodeResult(400));
 }
コード例 #15
0
ファイル: Program.cs プロジェクト: Itslet/BugBase
 public static void newUser(string username, string mail, string passwd)
 {
     var UserSession = new MongoSession<User>();
     User b = new User();
     b.UserName = username;
     b.Email = mail;
     b.Password = passwd;
     UserSession.Save(b);
 }
コード例 #16
0
        public void Demonstrate_MongoIdentifierAttribute()
        {
            var product = new Product {
                Name = "Hammer",
                Price = "11.50",
                Sku = "a3k4j22je9",
                Weight = "4"
            };

            var session = new MongoSession();
            session.Save(product);

            var fetched = session.Query<Product>().Where(x => x.Sku == product.Sku);

            Assert.IsNotNull(fetched.First());
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: Itslet/BugBase
        public static BugProject newBugProject(User user, string projectname, string projectdescription)
        {
            var UserSession = new MongoSession<User>();
            var ProjectSession = new MongoSession<BugProject>();

            var test = Mapper.CreateMap<BugProject,User>();

            BugProject p = new BugProject();
            p.ProjectDescription = projectdescription;
            p.ProjectName = projectname;
            p.ProjectOwner = user;

            ProjectSession.Save(p);
            return p;
        }
コード例 #18
0
        public void AddUsersToRoles(string[] usernames, params Guid[] roleIds)
        {
            SecUtility.CheckArrayParameter(ref usernames, true, true, true, 256, "usernames");
            var session = new MongoSession(MongoMembershipProvider.ConnectionString);

            try
            {
                List<string> _usernames = usernames.ToList();
                List<Guid> _roleNames = roleIds.ToList();

                var users = (from u in session.Users
                             where _usernames.Contains(u.UserName)
                             select u).ToList();

                var roles = (from r in session.Roles
                             where _roleNames.Contains(r.RoleId)
                             select r).ToList();

                foreach (var userEntity in users)
                {
                    if (userEntity.Roles.Any())
                    {
                        var newRoles = roles.Except(userEntity.Roles);
                        userEntity.Roles.AddRange(newRoles);
                    }
                    else
                    {
                        userEntity.Roles.AddRange(roles);
                    }

                    session.Save(userEntity);
                }
            }
            catch
            {
                throw;
            }
        }
コード例 #19
0
 public ActionResult Post(Client client)
 {
     session.Save(client);
     return(Json(client));
 }
コード例 #20
0
        public void RemoveUsersFromRoles(string[] usernames, params Guid[] roleIds)
        {
            SecUtility.CheckArrayParameter(ref usernames, true, true, true, 256, "usernames");
            var session = new MongoSession(MongoMembershipProvider.ConnectionString);

            try
            {
                List<string> _usernames = usernames.ToList();
                List<Guid> _roleIds = roleIds.ToList();

                var users = (from u in session.Users
                             where _usernames.Contains(u.UserName)
                             select u).ToList();

                var roles = (from r in session.Roles
                             where _roleIds.Contains(r.RoleId)
                             select r).ToList();

                foreach (var userEntity in users)
                {
                    if (userEntity.Roles.Any())
                    {
                        int oldCount = userEntity.Roles.Count;
                        var matchedRoles = roles.Intersect(userEntity.Roles, new RoleComparer());

                        foreach (var matchedRole in matchedRoles)
                            userEntity.Roles.Remove(matchedRole);

                        if (oldCount != userEntity.Roles.Count)
                            session.Save(userEntity);
                    }
                }

            }
            catch
            {
                throw;
            }
        }
コード例 #21
0
        public static void InitializeRoles(Type r, string connectionString)
        {
            var session = new MongoSession(connectionString);
            List<MembershipRole> roles = new List<MembershipRole>();
            List<MembershipPermission> permissions = session.Permissions.ToList();
            List<string> dbRoles = session.Roles.Select(x => x.RoleName).ToList();

            foreach (FieldInfo field in r.GetFields(BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.Public))
            {
                string value = field.GetRawConstantValue().ToString();
                if (!dbRoles.Contains(value))
                {
                    MembershipRole role = new MembershipRole { RoleName = value };

                    if (value == DefaultRoles.Admin)
                    {
                        foreach (var p in permissions)
                        {
                            role.Permissions.Add(p.Name);
                        }
                    }

                    session.Save(role);
                }

            }
        }
コード例 #22
0
        public void Demonstrate_PropertyAliasing()
        {
            MongoConfiguration.Initialize(x => x.AddMap<ArticleMap>());

            var article = new Article {
                Author = "Mark Twain",
                Body = "Once upon a time...",
                DatePosted = DateTime.Now,
                Title = "A Conneticuit Yankee in King Arthur's Court",
                Comments = new List<Comment> {
                    new Comment { CommentersName = "Me", Body = "Some Message..." }
                }
            };

            var session = new MongoSession();
            session.Save(article);

            var fetched = session.Query<Article>()
                .Where(x => x.Id == article.Id).SingleOrDefault();

            Assert.AreEqual(fetched.Title, article.Title);
        }
コード例 #23
0
        public void Demonstrate_TypeDiscrimination()
        {
            var orderA = new Order {
                Quantity = 12,
                Item = new Book {
                    Supplier = "Acme",
                    Author = "James Patterson",
                    Sku = "d9e9fje",
                    Title = "A Tree Grows in Brooklyn"
                }
            };

            var orderB = new Order {
                Quantity = 4,
                Item = new Chair {
                    Supplier = "Acme",
                    Maker = "Target",
                    NumberOfLegs = 3,
                    Sku = "39ejr9r"
                }
            };

            var session = new MongoSession();
            session.Save(orderA);
            session.Save(orderB);

            var fetched = session.Query<Order>().SingleOrDefault(x => x.Id == orderA.Id);

            Assert.IsTrue(fetched.Item is Book);
        }
コード例 #24
0
ファイル: Program.cs プロジェクト: Itslet/BugBase
        public static void initializeBugBase()
        {
            newUser("Jacqueline", "*****@*****.**", "12345");
            // User jp = findUser("*****@*****.**");

            //NIEUW BUGPROJECT
             User u = findUser("*****@*****.**");
             BugProject bp = newBugProject(u, "Example Project", "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam");

            //nieuwe bug

             Bug bug = new Bug();
             bug.BugProject = bp;
             bug.BugSubmitter = u;
             bug.Description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
             bug.Name = "Example name";

             var BugSession = new MongoSession<Bug>();
             BugSession.Save(bug);
        }
コード例 #25
0
 public ActionResult Post(Contractor contractor)
 {
     session.Save(contractor);
     return(Json(contractor));
 }
コード例 #26
0
        private bool CheckPassword(MongoSession session, int userId, string password)
        {
            string hashedPassword = GetHashedPassword(session, userId);
            var user = session.Users.FirstOrDefault(x => x.UserId == userId);
            bool verificationSucceeded = (hashedPassword != null && Crypto.VerifyHashedPassword(hashedPassword, password));
            if (verificationSucceeded)
            {
                // Reset password failure count on successful credential check
                user.PasswordFailuresSinceLastSuccess = 0;
            }
            else
            {
                int failures = GetPasswordFailuresSinceLastSuccess(session, userId);
                if (failures != -1)
                {
                    user.PasswordFailuresSinceLastSuccess = failures + 1;
                    user.LastPasswordFailureDate = DateTime.UtcNow;
                }
            }

            session.Save(user);
            return verificationSucceeded;
        }