public ActionResult ForgottenPassword(string email)
        {
            using (_securityService.BeginSystemContext())
            {
                var q = new EntityQuery2("User");
                q.WhereIs("Email", email);
                q.WhereIs("IsActive", true);
                Entity user = _entityService.Query(q).SingleOrDefault();
                if (user == null)
                {
                    ModelState.AddModelError("email", string.Format("В системата няма активен потребител с имейл \"{0}\". За помощ: тел. 02 8110296.", email));
                    return(View());
                }
                else
                {
                    var recoveryCode = Guid.NewGuid().ToString();

                    var update = new EntityUpdate(user.Name, user.Id);
                    update.Set("RecoveryCode", recoveryCode);
                    var result = _entityService.Update(update);
                    if (result.Success)
                    {
                        return(View("ForgottenPassword_Success", (object)email));
                    }
                    else
                    {
                        ModelState.AddModelError("email", "Възникна грешка при стартиране на процеса по възстановяване на забравена парола. За помощ: тел. 02 8110296.");
                        return(View());
                    }
                }
            }
        }
Beispiel #2
0
        public EntityUpdate ToEntityUpdate()
        {
            var update = new EntityUpdate(this.Entity);

            update.Id = this.Id;
            if (PropertyUpdates != null)
            {
                foreach (var pu in PropertyUpdates)
                {
                    update.Set(pu.Name, pu.Value);
                }
            }
            if (RelationUpdates != null)
            {
                foreach (var ru in RelationUpdates)
                {
                    var r = new RelationUpdate(ru.Entity, ru.Role, ru.Operation, ru.Id);
                    if (ru.PropertyUpdates != null)
                    {
                        foreach (var pu in ru.PropertyUpdates)
                        {
                            r.Set(pu.Name, pu.Value);
                        }
                    }
                    update.RelationUpdates.Add(r);
                }
            }

            return(update);
        }
        public ActionResult RecoverPassword(PasswordRecoveryModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (_securityService.BeginSystemContext())
            {
                var q = new EntityQuery2("User");
                q.WhereIs("Email", model.Email);
                q.WhereIs("RecoveryCode", model.RecoveryCode);
                q.WhereIs("IsActive", true);
                Entity user = _entityService.Query(q).SingleOrDefault();
                if (user == null)
                {
                    ModelState.AddModelError("", "Грешен имейл или код за възстановяване. Започнете процеса по възстановяване (през забравена парола) отново или позвънете на тел. 02 8110296.");
                    return(View(model));
                }
                else
                {
                    var update = new EntityUpdate(user.Name, user.Id);
                    update.Set("Password", model.Password);
                    var result = _entityService.Update(update);
                    if (result.Success)
                    {
                        return(View("RecoverPassword_Success"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Възникна грешка при смяна на паролата. Започнете процеса по възстановяване (през забравена парола) отново или позвънете на тел. 02 8110296.");
                        return(View(model));
                    }
                }
            }
        }
Beispiel #4
0
        public EntityUpdate ToEntityUpdate()
        {
            var update = new EntityUpdate(this.Entity);
            update.Id = this.Id;
            if (PropertyUpdates != null)
                foreach (var pu in PropertyUpdates)
                    update.Set(pu.Name, pu.Value);
            if (RelationUpdates != null)
                foreach (var ru in RelationUpdates)
                {
                    var r = new RelationUpdate(ru.Entity, ru.Role, ru.Operation, ru.Id);
                    if (ru.PropertyUpdates != null)
                        foreach (var pu in ru.PropertyUpdates)
                            r.Set(pu.Name, pu.Value);
                    update.RelationUpdates.Add(r);
                }

            return update;
        }
Beispiel #5
0
        public void Test_EntityOperation_Update()
        {
            var dbService = new TestDatabaseService();
            var repo = new EntityRepository(dms, dbService, new SequenceProvider(dbService));
            IEntityOperationService svc = new EntityOperationService(repo, dbService, new IEntityOperationInspector[] { new Inspector() }, new IEntityQueryInspector[] { new Inspector() }, new IEntityOperationLogic[] { new Logic() });
            EntityUpdate update = new EntityUpdate("Author");
            update.Set("FirstName", "John");
            update.Set("LastName", "Tolkin");
            update.Set("Numberofawards", 2);
            update.Set("IsAlive", false);

            EntityUpdate book = new EntityUpdate("book");
            book.Set("Title", "The Eye of the World");
            book.Set("genre", Genre.Fantasy);

            svc.Update(book);
            update.Attach("Book", "author", book.Id.Value);

            var result = svc.Update(update);
            Assert.AreEqual(true, result.Success);

            EntityQuery2 query = new EntityQuery2("Author");
            query.AddProperties("FirstName", "LastName", "IsAlive", "CreatedOn");
            query.Include("book", "author");
            var res = repo.Search(query);
            Assert.AreEqual(1, res.Count());
            var a = res.Single();
            Assert.AreEqual("John", a.GetData<string>("Firstname"));
            Assert.AreEqual("Tolkin", a.GetData<string>("LastName"));
            var created = a.GetData<DateTime>("createdon");
            Assert.AreEqual(DateTime.Now.Date, created.Date);
            var books = a.GetManyRelations("book", "author");
            Assert.AreEqual(1, books.Count());
            var b = books.Single().Entity;
            Assert.AreEqual("The Eye of the World", b.GetData<string>("title"));
            Assert.AreEqual(Genre.Fantasy, b.GetData<Genre>("genre"));
            created = b.GetData<DateTime>("createdon");
            Assert.AreEqual(DateTime.Now.Date, created.Date);

            repo.Delete(a, true);
            repo.Delete(b);
        }
Beispiel #6
0
        //[TestMethod]
        public void Test_EntityRepo_Perf()
        {
            var r = new Random();
            var dbService = new TestDatabaseService();
            var repository = new EntityRepository(dms, dbService, new SequenceProvider(dbService));
            using (var ctx = dbService.GetDatabaseContext(true))
            {
                for (int i = 0; i < 1000; i++)
                {
                    EntityUpdate update = new EntityUpdate("author");
                    update.Set("firstname", "Robert" + i);
                    update.Set("lastname", "Jordan");
                    update.Set("isalive", false);
                    update.Set("Born", new DateTime(1948, 10, 17));
                    update.Set("Rating", 5.5m + r.Next(4));
                    var id = repository.Create(update.ToEntity());
                    Assert.IsTrue(id > 0);

                    EntityQuery2 q = new EntityQuery2("author", id);
                    q.AddProperties("FirstName", "lastname", "isalive", "born", "rating");
                    var e = repository.Read(q);
                    foreach (var pu in update.PropertyUpdates)
                    {
                        Assert.AreEqual(pu.Value, e.Data[pu.Key]);
                    }

                    EntityUpdate update2 = new EntityUpdate(e.Name, e.Id);
                    update2.Set("rating", 5.5m + r.Next(4));
                    update2.Set("lastname", e.Data["lastname"] + "_EDIT");

                    repository.Update(update2.ToEntity());
                    e = repository.Read(q);
                    foreach (var pu in update2.PropertyUpdates)
                    {
                        Assert.AreEqual(pu.Value, e.Data[pu.Key]);
                    }
                    foreach (var pu in update.PropertyUpdates)
                    {
                        if (!pu.Key.Equals("rating", StringComparison.InvariantCultureIgnoreCase) && !pu.Key.Equals("lastname", StringComparison.InvariantCultureIgnoreCase))
                            Assert.AreEqual(pu.Value, e.Data[pu.Key]);
                    }

                }

                ctx.Complete();
            }

            using (var ctx = dbService.GetDatabaseContext(true))
            {
                var qAll = new EntityQuery2("Author");
                var all = repository.Search(qAll);
                Assert.AreEqual(1000, all.Count());
                foreach (var a in all)
                    repository.Delete(a);
                Assert.AreEqual(0, repository.Search(qAll).Count());
            }
        }
Beispiel #7
0
        public ActionResult RecoverPassword(PasswordRecoveryModel model)
        {
            if (!ModelState.IsValid)
                return View(model);

            using (_securityService.BeginSystemContext())
            {
                var q = new EntityQuery2("User");
                q.WhereIs("Email", model.Email);
                q.WhereIs("RecoveryCode", model.RecoveryCode);
                q.WhereIs("IsActive", true);
                Entity user = _entityService.Query(q).SingleOrDefault();
                if (user == null)
                {
                    ModelState.AddModelError("", "Грешен имейл или код за възстановяване. Започнете процеса по възстановяване (през забравена парола) отново или позвънете на тел. 02 8110296.");
                    return View(model);
                }
                else
                {
                    var update = new EntityUpdate(user.Name, user.Id);
                    update.Set("Password", model.Password);
                    var result = _entityService.Update(update);
                    if(result.Success)
                    {
                        return View("RecoverPassword_Success");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Възникна грешка при смяна на паролата. Започнете процеса по възстановяване (през забравена парола) отново или позвънете на тел. 02 8110296.");
                        return View(model);
                    }
                }
            }
        }
Beispiel #8
0
        public ActionResult ForgottenPassword(string email)
        {
            using (_securityService.BeginSystemContext())
            {
                var q = new EntityQuery2("User");
                q.WhereIs("Email", email);
                q.WhereIs("IsActive", true);
                Entity user = _entityService.Query(q).SingleOrDefault();
                if (user == null)
                {
                    ModelState.AddModelError("email", string.Format("В системата няма активен потребител с имейл \"{0}\". За помощ: тел. 02 8110296.", email));
                    return View();
                }
                else
                {
                    var recoveryCode = Guid.NewGuid().ToString();

                    var update = new EntityUpdate(user.Name, user.Id);
                    update.Set("RecoveryCode", recoveryCode);
                    var result = _entityService.Update(update);
                    if(result.Success)
                        return View("ForgottenPassword_Success", (object)email);
                    else
                    {
                        ModelState.AddModelError("email", "Възникна грешка при стартиране на процеса по възстановяване на забравена парола. За помощ: тел. 02 8110296.");
                        return View();
                    }
                }

            }
        }