예제 #1
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var organisation = new Domain.Organisation
                {
                    Id          = request.Id,
                    name        = request.name,
                    description = request.description,
                };

                _context.Organisations.Add(organisation);

                var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName ==
                                                                     _userAccessor.GetCurrentUsername());

                var admin = new UserOrganisationAdmin
                {
                    AppUser      = user,
                    Organisation = organisation,
                    orgAdmin     = true
                };

                _context.UserOrganisationAdmins.Add(admin);

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving changes");
            }
예제 #2
0
        public void CreateOrganisation(Organisation Organisation)
        {

            utOfWork.OrganisationRepository.Add(Organisation);


        }
        private Organisation GetOrganisation()
        {
            User user = UserFactory.Create(userId, "firstName", "lastName", "9123456789", "*****@*****.**");
            Organisation org = new Organisation(name, BusinessType.Other, otherDescription);
            EntityHelper.SetEntityId(org, organisationId);

            user.LinkToOrganisation(org);
            return org;
        }
        private User GetUser()
        {
            User user = UserFactory.Create(userId, "firstName", "lastName", "9123456789", "*****@*****.**");
            user.LinkToAddress(new UserAddress(new Address(address1, address2, town, null, postcode, "United Kingdom")));
            Organisation org = new Organisation(name, BusinessType.Other, otherDescription);
            EntityHelper.SetEntityId(org, organisationId);

            user.LinkToOrganisation(org);
            return user;
        }
        public async Task UpdateOrganisation_BusinessType_Should_Not_Remove_Organisation()
        {
            //Create new user
            var newUser = UserFactory.Create(userId, "testFirst", "testLast", "9999", "*****@*****.**");

            //Create new org
            var country = context.Countries.Single(c => c.IsoAlpha2Code.Equals("gb"));
            var address = TestAddress(country);
            var org = new Organisation("SFW Ltd", BusinessType.LimitedCompany);

            try
            {
                context.Users.Add(newUser);
                await context.SaveChangesAsync();

                context.Organisations.Add(org);
                await context.SaveChangesAsync();

                //Assign org to user
                newUser.LinkToOrganisation(org);
                await context.SaveChangesAsync();

                //Hold OrgID of newly created entity
                var oldOrgId = org.Id;

                //Update org with change in Business Type
                org = new Organisation("Name Changed", BusinessType.SoleTrader);
                context.Organisations.Add(org);
                await context.SaveChangesAsync();

                //Update user with newly created org2
                var user = await context.Users.SingleAsync(u => u.Id == newUser.Id);
                user.UpdateOrganisationOfUser(org);
                await context.SaveChangesAsync();
                Assert.True(user.Organisation.Id == org.Id);

                //Both Orgs should have different OrgIds
                Assert.False(oldOrgId == org.Id);

                //Check if old org exists
                var oldExists = context.Organisations.Any(x => x.Id == oldOrgId);
                Assert.True(oldExists);

                //Check if new org exists
                var newExists = context.Organisations.Any(x => x.Id == org.Id);
                Assert.True(newExists);
            }
            finally
            {
                context.DeleteOnCommit(org);

                context.Entry(newUser).State = EntityState.Deleted;
                context.SaveChanges();
            }
        }
        public void UpdateExistingOrganisation()
        {
            var country = context.Countries.Single(c => c.IsoAlpha2Code.Equals("gb"));
            var org = new Organisation("SFW Ltd", BusinessType.LimitedCompany);

            context.Organisations.Add(org);
            context.SaveChanges();

            var orgId = org.Id;
            org.Update("Only Name Changed", BusinessType.LimitedCompany);
            context.SaveChanges();
            Assert.Equal(orgId, org.Id);

            CleanUp(org);
        }
        private Organisation GetOrganisationWithName(string name)
        {
            var organisation = new Organisation(name, anyType);

            var properties = typeof(Organisation).GetProperties();

            foreach (var propertyInfo in properties)
            {
                if (propertyInfo.Name.Equals("Id", StringComparison.InvariantCultureIgnoreCase))
                {
                    var baseProperty = typeof(Organisation).BaseType.GetProperty(propertyInfo.Name);

                    baseProperty.SetValue(organisation, Guid.NewGuid(), null);

                    break;
                }
            }

            return organisation;
        }
        public void CanCreateOrganisation()
        {
            var country = context.Countries.Single(c => c.IsoAlpha2Code.Equals("gb"));

            var address = TestAddress(country);

            var org = new Organisation("SFW Ltd", BusinessType.LimitedCompany);

            context.Organisations.Add(org);

            try
            {
                context.SaveChanges();
                CleanUp(org);
            }
            catch (Exception)
            {
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
                throw;
            }
        }
예제 #9
0
 public void UpdateOrganisationDetached(Organisation e)
 {
     utOfWork.OrganisationRepository.UpdateOrganisationDetached(e);
 }
예제 #10
0
        public ActionResult CreateOrganisation(Organisation org, FormCollection collection)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    HttpPostedFileBase file1 = Request.Files["Image"];
                    org.Logo = ConvertToBytes(file1);
                    var logo = org.Logo;
                    BissInventaireEntities.Instance.Organisation.Add(org);
                    BissInventaireEntities.Instance.SaveChanges();
                    return RedirectToAction("GetOrganisation");
                }
                catch (Exception ex)
                {
                    LogThread.WriteLine(ex.Message);
                    return RedirectToAction("Index", "Error");
                }
            }
            else

            {
                ViewData["pays"] = new SelectList(BissInventaireEntities.Instance.Pays.ToList(), "idPays", "libelle");
                ViewData["gouvernourat"] = new SelectList(BissInventaireEntities.Instance.Gouvernorat.ToList(), "idGouvernorat", "libelle");
                ViewData["delegation"] = new SelectList(BissInventaireEntities.Instance.Delegation.ToList(), "idDelegation", "libelle");
                return View();
            }
        }
예제 #11
0
        public ActionResult EditOrganisation(Organisation org)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    db3.UpdateOrganisationDetached(org);
                    db3.SaveOrganisation();
                    return RedirectToAction("GetOrganisation");
                }
                catch (Exception ex)
                {
                    LogThread.WriteLine(ex.Message);
                    return RedirectToAction("Index", "Error");
                }
            }
            else

            {
                ViewData["pays"] = new SelectList(BissInventaireEntities.Instance.Pays.ToList(), "libelle", "libelle");
                ViewData["gouvernourat"] = new SelectList(BissInventaireEntities.Instance.Gouvernorat.ToList(), "idGouvernorat", "libelle");
                ViewData["delegation"] = new SelectList(BissInventaireEntities.Instance.Delegation.ToList(), "idDelegation", "libelle");
                return View();
            }
        }
        private void CleanUp(Organisation organisation)
        {
            context.Organisations.Remove(organisation);

            context.SaveChanges();
        }
예제 #13
0
 public ActionResult EditOrganisation(Organisation org)
 {
     try
     {
         db3.UpdateOrganisationDetached(org);
         db3.SaveOrganisation();
         return RedirectToAction("GetOrganisation");
     }
     catch (Exception ex)
     {
         LogThread.WriteLine(ex.Message);
         return RedirectToAction("Index", "Error");
     }
 }
예제 #14
0
 public ActionResult CreateOrganisation(Organisation org)
 {
     try
     {
         BissInventaireEntities.Instance.Organisation.Add(org);
         BissInventaireEntities.Instance.SaveChanges();
         return RedirectToAction("GetOrganisation");
     }
     catch (Exception ex)
     {
         LogThread.WriteLine(ex.Message);
         return RedirectToAction("Index", "Error");
     }
 }