Esempio n. 1
0
        public void Entity_StoredProcedureEntity_Delete()
        {
            var writer      = new StoredProcedureWriter <CustomerInfo>();
            var reader      = new EntityReader <CustomerInfo>();
            var dbCustomer  = new CustomerInfo();
            var lastKey     = TypeExtension.DefaultGuid;
            var originalId  = TypeExtension.DefaultInteger;
            var originalKey = TypeExtension.DefaultGuid;

            Entity_StoredProcedureEntity_Create();
            lastKey = StoredProcedureEntityTests.RecycleBin.Last();

            dbCustomer  = reader.GetByKey(lastKey);
            originalId  = dbCustomer.Id;
            originalKey = dbCustomer.Key;
            Assert.IsTrue(!dbCustomer.IsNew);
            Assert.IsTrue(dbCustomer.Id != TypeExtension.DefaultInteger);
            Assert.IsTrue(dbCustomer.Key != TypeExtension.DefaultGuid);
            Assert.IsTrue(dbCustomer.CreatedDate.Date == DateTime.UtcNow.Date);

            dbCustomer = writer.Delete(dbCustomer);
            Assert.IsTrue(dbCustomer.IsNew);

            dbCustomer = reader.GetById(originalId);
            Assert.IsTrue(dbCustomer.IsNew);
            Assert.IsTrue(dbCustomer.Id == TypeExtension.DefaultInteger);
            Assert.IsTrue(dbCustomer.Key == TypeExtension.DefaultGuid);
        }
Esempio n. 2
0
        public ActionResult Summary(CustomerModel model)
        {
            var reader   = new EntityReader <CustomerInfo>();
            var customer = reader.GetById(model.Id);

            return(View(CustomerController.EditView, customer.CastOrFill <CustomerModel>()));
        }
Esempio n. 3
0
        public async Task Core_Entity_StoredProcedureEntity_Delete()
        {
            var db          = new EntityReader <CustomerInfo>(new ConnectionStringFactory().GetDefaultConnection());
            var testItem    = new CustomerInfo();
            var testResult  = new CustomerInfo();
            var lastKey     = Guid.Empty;
            var originalID  = -1;
            var originalKey = Guid.Empty;

            await Core_Entity_StoredProcedureEntity_Create();

            lastKey = RecycleBin.Last();

            testItem    = db.GetByKey(lastKey);
            originalID  = testItem.Id;
            originalKey = testItem.Key;
            Assert.IsTrue(testItem.Id != -1);
            Assert.IsTrue(testItem.Key != Guid.Empty);
            Assert.IsTrue(testItem.CreatedDate.Date == DateTime.UtcNow.Date);

            using (var writer = new EntityWriter <CustomerInfo>(new CustomerSPConfig(new ConnectionStringFactory().GetDefaultConnection(), testItem)))
            {
                var deleteResult = await writer.DeleteAsync();

                Assert.IsTrue(deleteResult.IsNew);
            }

            testItem = db.GetById(originalID);
            Assert.IsTrue(testItem.Id != originalID);
            Assert.IsTrue(testItem.Key != originalKey);
            Assert.IsTrue(testItem.Id == -1);
            Assert.IsTrue(testItem.Key == Guid.Empty);
        }
Esempio n. 4
0
        public async Task Core_Entity_StoredProcedureEntity_Save()
        {
            var db             = new EntityReader <CustomerInfo>(new ConnectionStringFactory().GetDefaultConnection());
            var newCustomer    = new CustomerInfo();
            var resultCustomer = new CustomerInfo();
            var dbCustomer     = new CustomerInfo();

            // Create should update original object, and pass back a fresh-from-db object
            newCustomer.Fill(testEntities[Arithmetic.Random(1, testEntities.Count)]);

            using (var writer = new EntityWriter <CustomerInfo>(new CustomerSPConfig(new ConnectionStringFactory().GetDefaultConnection(), newCustomer)))
            {
                resultCustomer = await writer.SaveAsync();
            }
            Assert.IsTrue(newCustomer.Key != Guid.Empty);
            Assert.IsTrue(resultCustomer.Id != -1);
            Assert.IsTrue(resultCustomer.Key != Guid.Empty);

            // Object in db should match in-memory objects
            dbCustomer = db.GetById(resultCustomer.Id);
            Assert.IsTrue(dbCustomer.Id != -1);
            Assert.IsTrue(dbCustomer.Key != Guid.Empty);
            Assert.IsTrue(dbCustomer.Id == resultCustomer.Id);
            Assert.IsTrue(dbCustomer.Key == resultCustomer.Key);

            RecycleBin.Add(newCustomer.Key);
        }
Esempio n. 5
0
        public async Task Core_Data_EntityWriter_Update()
        {
            var testEntity   = new CustomerEntity();
            var reader       = new EntityReader <CustomerEntity>(new ConnectionStringFactory().GetDefaultConnection());
            var oldFirstName = string.Empty;
            var newFirstName = DateTime.UtcNow.Ticks.ToString();
            var entityId     = -1;
            var entityKey    = Guid.Empty;

            // Create and capture original data
            await Core_Data_EntityWriter_Insert();

            testEntity           = reader.GetAll().OrderByDescending(x => x.CreatedDate).FirstOrDefaultSafe();
            oldFirstName         = testEntity.FirstName;
            entityId             = testEntity.Id;
            entityKey            = testEntity.Key;
            testEntity.FirstName = newFirstName;
            Assert.IsTrue(testEntity.IsNew == false);
            Assert.IsTrue(testEntity.Id != -1);
            Assert.IsTrue(testEntity.Key != Guid.Empty);

            // Do Update
            using (var writer = new EntityWriter <CustomerEntity>(testEntity, new ConnectionStringFactory().GetDefaultConnection()))
            {
                testEntity = await writer.SaveAsync();
            }

            // Pull from DB and retest
            testEntity = reader.GetById(entityId);
            Assert.IsTrue(testEntity.IsNew == false);
            Assert.IsTrue(testEntity.Id == entityId);
            Assert.IsTrue(testEntity.Key == entityKey);
            Assert.IsTrue(testEntity.Id != -1);
            Assert.IsTrue(testEntity.Key != Guid.Empty);
        }
Esempio n. 6
0
        public async Task Core_Entity_StoredProcedureEntity_Update()
        {
            var reader         = new EntityReader <CustomerInfo>(new ConnectionStringFactory().GetDefaultConnection());
            var item           = new CustomerInfo();
            var resultCustomer = new CustomerInfo();
            var uniqueValue    = RandomString.Next();

            await Core_Entity_StoredProcedureEntity_Create();

            Guid lastKey = RecycleBin.Last();

            item = reader.GetByKey(lastKey);
            var  originalID  = item.Id;
            Guid originalKey = item.Key;

            Assert.IsTrue(item.Id != -1);
            Assert.IsTrue(item.Key != Guid.Empty);

            item.FirstName = uniqueValue;
            using (var writer = new EntityWriter <CustomerInfo>(new CustomerSPConfig(new ConnectionStringFactory().GetDefaultConnection(), item)))
            {
                resultCustomer = await writer.UpdateAsync();
            }
            Assert.IsTrue(resultCustomer.Id != -1);
            Assert.IsTrue(resultCustomer.Key != Guid.Empty);
            Assert.IsTrue(item.Id == resultCustomer.Id && resultCustomer.Id == originalID);
            Assert.IsTrue(item.Key == resultCustomer.Key && resultCustomer.Key == originalKey);

            item = reader.GetById(originalID);
            Assert.IsTrue(item.Id == resultCustomer.Id && resultCustomer.Id == originalID);
            Assert.IsTrue(item.Key == resultCustomer.Key && resultCustomer.Key == originalKey);

            Assert.IsTrue(item.Id != -1);
            Assert.IsTrue(item.Key != Guid.Empty);
        }
Esempio n. 7
0
        public async Task Entity_StoredProcedureEntity_Delete()
        {
            var reader = new EntityReader <CustomerInfo>();

            await Entity_StoredProcedureEntity_Create();

            var lastKey = StoredProcedureEntityTests.RecycleBin.Last();

            var testEntity = reader.GetByKey(lastKey);
            var originalId = testEntity.Id;

            Assert.IsTrue(!testEntity.IsNew);
            Assert.IsTrue(testEntity.Id != Defaults.Integer);
            Assert.IsTrue(testEntity.Key != Defaults.Guid);
            Assert.IsTrue(testEntity.CreatedDate.Date == DateTime.UtcNow.Date);

            using (var writer = new StoredProcedureWriter <CustomerInfo>(testEntity, new CustomerSPConfig(testEntity)))
            {
                testEntity = await writer.DeleteAsync();
            }
            Assert.IsTrue(testEntity.IsNew);

            testEntity = reader.GetById(originalId);
            Assert.IsTrue(testEntity.IsNew);
            Assert.IsTrue(testEntity.Id == Defaults.Integer);
            Assert.IsTrue(testEntity.Key == Defaults.Guid);
        }
Esempio n. 8
0
        public ActionResult Delete(string id)
        {
            var reader   = new EntityReader <CustomerInfo>();
            var customer = reader.GetById(id.TryParseInt32());

            if (customer.IsNew)
            {
                TempData[ResultMessage] = "No customer found";
            }

            return(View(CustomerController.DeleteView, customer.CastOrFill <CustomerModel>()));
        }
Esempio n. 9
0
        public ActionResult Summary(string id)
        {
            var reader   = new EntityReader <CustomerInfo>();
            var customer = (id.IsInteger() ?
                            reader.GetById(id.TryParseInt32()) :
                            reader.GetByKey(id.TryParseGuid()));

            if (customer.IsNew)
            {
                TempData[ResultMessage] = "Customer not found";
            }

            return(View(CustomerController.SummaryView, customer.CastOrFill <CustomerModel>()));
        }
        public virtual async Task <IHttpActionResult> GetById(int id, [FromUri] string fields)
        {
            try
            {
                var entity = await EntityReader.GetById(id, fields.Split(','));

                if (entity == null)
                {
                    return(NotFound());
                }
                return(Ok(Mapper.Map <TModel>(entity)));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public override async Task <IHttpActionResult> Delete(int id)
        {
            if (User.IsInRole(Rol.Manager, Rol.Administrator))
            {
                var issue = await EntityReader.GetById(id, nameof(Issue.Gebruiker), $"{nameof(Issue.Gebruiker)}.{nameof(Gebruiker.Verantwoordelijke)}");

                if (issue.Gebruiker.Email == User.Identity.Name || issue.Gebruiker.Verantwoordelijke.Email == User.Identity.Name)
                {
                    return(Unauthorized());
                }
            }
            else
            {
                var issue = await EntityReader.GetById(id, nameof(Issue.Gebruiker));

                if (issue.Gebruiker.Email != User.Identity.Name)
                {
                    return(Unauthorized());
                }
            }
            return(await base.Delete(id));
        }
Esempio n. 12
0
        public void Entity_StoredProcedureEntity_Update()
        {
            var writer         = new StoredProcedureWriter <CustomerInfo>();
            var reader         = new EntityReader <CustomerInfo>();
            var resultCustomer = new CustomerInfo();
            var dbCustomer     = new CustomerInfo();
            var uniqueValue    = Guid.NewGuid().ToString().Replace("-", "");
            var lastKey        = TypeExtension.DefaultGuid;
            var originalId     = TypeExtension.DefaultInteger;
            var originalKey    = TypeExtension.DefaultGuid;

            Entity_StoredProcedureEntity_Create();
            lastKey = StoredProcedureEntityTests.RecycleBin.Last();

            dbCustomer  = reader.GetByKey(lastKey);
            originalId  = dbCustomer.Id;
            originalKey = dbCustomer.Key;
            Assert.IsTrue(!dbCustomer.IsNew);
            Assert.IsTrue(dbCustomer.Id != TypeExtension.DefaultInteger);
            Assert.IsTrue(dbCustomer.Key != TypeExtension.DefaultGuid);

            dbCustomer.FirstName = uniqueValue;
            resultCustomer       = writer.Update(dbCustomer);
            Assert.IsTrue(!resultCustomer.IsNew);
            Assert.IsTrue(resultCustomer.Id != TypeExtension.DefaultInteger);
            Assert.IsTrue(resultCustomer.Key != TypeExtension.DefaultGuid);
            Assert.IsTrue(dbCustomer.Id == resultCustomer.Id && resultCustomer.Id == originalId);
            Assert.IsTrue(dbCustomer.Key == resultCustomer.Key && resultCustomer.Key == originalKey);

            dbCustomer = dbCustomer = reader.GetById(originalId);
            Assert.IsTrue(!dbCustomer.IsNew);
            Assert.IsTrue(dbCustomer.Id == resultCustomer.Id && resultCustomer.Id == originalId);
            Assert.IsTrue(dbCustomer.Key == resultCustomer.Key && resultCustomer.Key == originalKey);
            Assert.IsTrue(dbCustomer.Id != TypeExtension.DefaultInteger);
            Assert.IsTrue(dbCustomer.Key != TypeExtension.DefaultGuid);
        }
Esempio n. 13
0
        public async Task Entity_StoredProcedureEntity_Update()
        {
            var reader       = new EntityReader <CustomerInfo>();
            var resultEntity = new CustomerInfo();
            var uniqueValue  = Guid.NewGuid().ToString().Replace("-", "");

            await Entity_StoredProcedureEntity_Create();

            var lastKey = StoredProcedureEntityTests.RecycleBin.Last();

            var testEntity  = reader.GetByKey(lastKey);
            var originalId  = testEntity.Id;
            var originalKey = testEntity.Key;

            Assert.IsTrue(!testEntity.IsNew);
            Assert.IsTrue(testEntity.Id != Defaults.Integer);
            Assert.IsTrue(testEntity.Key != Defaults.Guid);

            testEntity.FirstName = uniqueValue;
            using (var writer = new StoredProcedureWriter <CustomerInfo>(testEntity, new CustomerSPConfig(testEntity)))
            {
                resultEntity = await writer.UpdateAsync();
            }
            Assert.IsTrue(!resultEntity.IsNew);
            Assert.IsTrue(resultEntity.Id != Defaults.Integer);
            Assert.IsTrue(resultEntity.Key != Defaults.Guid);
            Assert.IsTrue(testEntity.Id == resultEntity.Id && resultEntity.Id == originalId);
            Assert.IsTrue(testEntity.Key == resultEntity.Key && resultEntity.Key == originalKey);

            testEntity = reader.GetById(originalId);
            Assert.IsTrue(!testEntity.IsNew);
            Assert.IsTrue(testEntity.Id == resultEntity.Id && resultEntity.Id == originalId);
            Assert.IsTrue(testEntity.Key == resultEntity.Key && resultEntity.Key == originalKey);
            Assert.IsTrue(testEntity.Id != Defaults.Integer);
            Assert.IsTrue(testEntity.Key != Defaults.Guid);
        }
        public override async Task <IHttpActionResult> GetById(int id, [FromUri] string fields)
        {
            try
            {
                var entity = await EntityReader.GetById(id, nameof(Issue.Gebruiker), $"{nameof(Issue.Gebruiker)}.{nameof(Gebruiker.Verantwoordelijke)}", nameof(Issue.IssueStatussen), $"{nameof(Issue.IssueStatussen)}.{nameof(IssueStatus.Solver)}");

                if (entity == null)
                {
                    return(NotFound());
                }

                if (User.IsInRole(Rol.Manager))
                {
                    if (!(entity.Gebruiker.Email == User.Identity.Name || entity.Gebruiker.Verantwoordelijke.Email == User.Identity.Name))
                    {
                        return(Unauthorized());
                    }
                }
                else if (User.IsInRole(Rol.Dispatcher))
                {
                    if (entity.Gebruiker.Email != User.Identity.Name)
                    {
                        var last = entity.IssueStatussen.OrderBy(x => x.CreationDate).LastOrDefault();
                        if (last == null)
                        {
                            return(Unauthorized());
                        }
                        switch (last.StatusBeschrijving)
                        {
                        case IssueStatusBeschrijving.Geweigerd:
                        case IssueStatusBeschrijving.Nieuw:
                            break;

                        default:
                            if (entity.IssueStatussen.OrderBy(x => x.CreationDate).LastOrDefault().Solver.Email !=
                                User.Identity.Name)
                            {
                                return(Unauthorized());
                            }
                            break;
                        }
                    }
                }
                else if (User.IsInRole(Rol.Solver))
                {
                    if (entity.Gebruiker.Email != User.Identity.Name)
                    {
                        if (entity.IssueStatussen.OrderBy(x => x.CreationDate).LastOrDefault().Solver.Email !=
                            User.Identity.Name)
                        {
                            return(Unauthorized());
                        }
                    }
                }
                else if (User.IsInRole(Rol.Gebruiker))
                {
                    if (entity.Gebruiker.Email != User.Identity.Name)
                    {
                        return(Unauthorized());
                    }
                }

                return(Ok(Mapper.Map <IssueModel>(entity)));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }