public void OrganizationPropertyTest3() { VcfRow row = VcfRow.Parse("ORG:", new VcfDeserializationInfo()) !; var prop = new OrganizationProperty(row, Enums.VCdVersion.V3_0); Assert.IsNotNull(prop.Value); }
public IHttpActionResult DeleteOrganizationProperty(int id) { try { UnitOfWork unitOfWork = new UnitOfWork(factory); OrganizationProperty organizationProperty = unitOfWork.OrganizationPropertiesRepository .Get(d => d.Id == id).FirstOrDefault(); organizationProperty.Deleted = true; unitOfWork.OrganizationPropertiesRepository.Update(organizationProperty); unitOfWork.Save(); return(Ok(organizationProperty.ToDTO())); } catch (NotFoundException nfe) { return(NotFound()); } catch (ConflictException ce) { return(Conflict()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <IActionResult> Edit(int id, [Bind("OrganizationPropertyId,Title,Value")] OrganizationProperty organizationProperty) { if (id != organizationProperty.OrganizationPropertyId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(organizationProperty); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrganizationPropertyExists(organizationProperty.OrganizationPropertyId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(organizationProperty)); }
public IHttpActionResult PostOrganization(OrganizationEditDTO organization) { try { if (identityHelper.GetUserTableName(User) == "Employee") { if (organization.CountryId == null || organization.CountryId == 0) { return(BadRequest("Empty CountryId")); } Organization org = organization.FromDTO(); //now this information is stored in OrganizationOwner (we do not need this anymore) // organization.EmployeeId = identityHelper.GetUserTableId(User); UnitOfWork unitOfWork = new UnitOfWork(factory); org.Id = org.NewId(unitOfWork); unitOfWork.OrganizationsRepository.Insert(org); unitOfWork.OrganizationOwnersRepository.Insert( new OrganizationOwner() { DateBegin = DateTime.Now, EmployeeId = identityHelper.GetUserTableId(User), OrganizationId = org.Id }); //constant types List <OrganizationPropertyType> types = unitOfWork.OrganizationPropertyTypesRepository.Get(d => d.Constant == true && d.CountryId == org.CountryId).ToList(); foreach (var type in types) { OrganizationProperty property = new OrganizationProperty(); property.Id = property.NewId(unitOfWork); property.OrganizationPropertyTypeId = type.Id; property.OrganizationId = org.Id; unitOfWork.OrganizationPropertiesRepository.Insert(property); } unitOfWork.Save(); OrganizationEditDTO dto = unitOfWork.OrganizationsRepository .Get(d => d.Id == org.Id, includeProperties: "Country,OrganizationLegalForm") .FirstOrDefault().MapToEdit(); return(CreatedAtRoute("GetOrganizationEdit", new { id = dto.Id }, dto)); } } catch (NotFoundException nfe) { return(NotFound()); } catch (ConflictException ce) { return(Conflict()); } catch (Exception e) { return(BadRequest(e.Message)); } return(BadRequest()); }
public void OrganizationPropertyTest1(string?expectedGroup, string?expectedOrganizationName, string[] expectedOrganizationalUnits) { var orgProp = new OrganizationProperty(expectedOrganizationName, expectedOrganizationalUnits, expectedGroup); Assert.IsNotNull(orgProp.Value); Assert.AreEqual(expectedGroup, orgProp.Group); Assert.AreEqual(expectedOrganizationName, orgProp.Value.OrganizationName); CollectionAssert.AreEqual(expectedOrganizationalUnits, orgProp.Value.OrganizationalUnits); }
public async Task <IActionResult> Create(OrganizationProperty model) { if (ModelState.IsValid) { model.OwnerOrganization = _context.Organizations.Find(model.OwnerOrganization.OrganizationId); _context.Add(model); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public IHttpActionResult PutOrganizationProperty(int id, OrganizationPropertyDTO organizationProperty) { if (organizationProperty == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != organizationProperty.Id) { return(BadRequest()); } try { OrganizationProperty property = organizationProperty.FromDTO(); UnitOfWork unitOfWork = new UnitOfWork(factory); int?propertyCountryId = unitOfWork.OrganizationPropertyTypesRepository .Get(d => d.Id == property.OrganizationPropertyTypeId) .Select(d => d.CountryId) .FirstOrDefault(); int?organizationCountryId = unitOfWork.OrganizationsRepository .Get(d => d.Id == property.OrganizationId) .Select(d => d.CountryId) .FirstOrDefault(); if (propertyCountryId != organizationCountryId) { return(BadRequest("Country that property belogs to, doesn't match the Organization registration country")); } unitOfWork.OrganizationPropertiesRepository.Update(property); unitOfWork.Save(); // logger.Log(LogLevel.Info, "how to pass objects"); OrganizationPropertyDTO dto = unitOfWork.OrganizationPropertiesRepository .Get(d => d.Id == id) .FirstOrDefault() .ToDTO(); dto.OrganizationPropertyType = null; return(Ok(dto)); } catch (NotFoundException nfe) { return(NotFound()); } catch (ConflictException ce) { return(Conflict()); } catch (Exception e) { return(BadRequest(e.Message)); } }
/// <summary> /// Copy ctor /// </summary> /// <param name="vCard">The vCard to clone.</param> private VCard(VCard vCard) { Version = vCard.Version; Func <ICloneable?, object?> cloner = Cloned; foreach (KeyValuePair <VCdProp, object> kvp in vCard._propDic) { Set(kvp.Key, kvp.Value switch { XmlProperty xmlProp => xmlProp.Clone(), IEnumerable <XmlProperty?> xmlPropEnumerable => xmlPropEnumerable.Select(cloner).Cast <XmlProperty?>().ToArray(), ProfileProperty profProp => profProp.Clone(), TextProperty txtProp => txtProp.Clone(), IEnumerable <TextProperty?> txtPropEnumerable => txtPropEnumerable.Select(cloner).Cast <TextProperty?>().ToArray(), DateTimeProperty dtTimeProp => dtTimeProp.Clone(), IEnumerable <DateTimeProperty?> dtTimePropEnumerable => dtTimePropEnumerable.Select(cloner).Cast <DateTimeProperty?>().ToArray(), AddressProperty adrProp => adrProp.Clone(), IEnumerable <AddressProperty?> adrPropEnumerable => adrPropEnumerable.Select(cloner).Cast <AddressProperty?>().ToArray(), NameProperty nameProp => nameProp.Clone(), IEnumerable <NameProperty?> namePropEnumerable => namePropEnumerable.Select(cloner).Cast <NameProperty?>().ToArray(), RelationProperty relProp => relProp.Clone(), IEnumerable <RelationProperty?> relPropEnumerable => relPropEnumerable.Select(cloner).Cast <RelationProperty?>().ToArray(), OrganizationProperty orgProp => orgProp.Clone(), IEnumerable <OrganizationProperty?> orgPropEnumerable => orgPropEnumerable.Select(cloner).Cast <OrganizationProperty?>().ToArray(), StringCollectionProperty strCollProp => strCollProp.Clone(), IEnumerable <StringCollectionProperty?> strCollPropEnumerable => strCollPropEnumerable.Select(cloner).Cast <StringCollectionProperty?>().ToArray(), GenderProperty sexProp => sexProp.Clone(), IEnumerable <GenderProperty?> sexPropEnumerable => sexPropEnumerable.Select(cloner).Cast <GenderProperty?>().ToArray(), GeoProperty geoProp => geoProp.Clone(), IEnumerable <GeoProperty?> geoPropEnumerable => geoPropEnumerable.Select(cloner).Cast <GeoProperty?>().ToArray(), DataProperty dataProp => dataProp.Clone(), IEnumerable <DataProperty?> dataPropEnumerable => dataPropEnumerable.Select(cloner).Cast <DataProperty?>().ToArray(), NonStandardProperty nStdProp => nStdProp.Clone(), IEnumerable <NonStandardProperty?> nStdPropEnumerable => nStdPropEnumerable.Select(cloner).Cast <NonStandardProperty?>().ToArray(), PropertyIDMappingProperty pidMapProp => pidMapProp.Clone(), IEnumerable <PropertyIDMappingProperty?> pidMapPropEnumerable => pidMapPropEnumerable.Select(cloner).Cast <PropertyIDMappingProperty?>().ToArray(), TimeZoneProperty tzProp => tzProp.Clone(), IEnumerable <TimeZoneProperty?> tzPropEnumerable => tzPropEnumerable.Select(cloner).Cast <TimeZoneProperty?>().ToArray(), ICloneable cloneable => cloneable.Clone(), // AccessProperty, KindProperty, TimeStampProperty, UuidProperty _ => kvp.Value });
/// <summary> /// This is overridden to allow copying of the additional properties /// </summary> /// <param name="p">The PDI object from which the settings are to be copied</param> protected override void Clone(PDIObject p) { VCard o = (VCard)p; this.ClearProperties(); groupName = o.Group; fn = (FormattedNameProperty)o.FormattedName.Clone(); name = (NameProperty)o.Name.Clone(); title = (TitleProperty)o.Title.Clone(); role = (RoleProperty)o.Role.Clone(); mailer = (MailerProperty)o.Mailer.Clone(); url = (UrlProperty)o.Url.Clone(); org = (OrganizationProperty)o.Organization.Clone(); uid = (UniqueIdProperty)o.UniqueId.Clone(); bday = (BirthDateProperty)o.BirthDate.Clone(); rev = (LastRevisionProperty)o.LastRevision.Clone(); tz = (TimeZoneProperty)o.TimeZone.Clone(); geo = (GeographicPositionProperty)o.GeographicPosition.Clone(); key = (PublicKeyProperty)o.PublicKey.Clone(); photo = (PhotoProperty)o.Photo.Clone(); logo = (LogoProperty)o.Logo.Clone(); sound = (SoundProperty)o.Sound.Clone(); this.Notes.CloneRange(o.Notes); this.Addresses.CloneRange(o.Addresses); this.Labels.CloneRange(o.Labels); this.Telephones.CloneRange(o.Telephones); this.EMailAddresses.CloneRange(o.EMailAddresses); this.Agents.CloneRange(o.Agents); this.CustomProperties.CloneRange(o.CustomProperties); addProfile = o.AddProfile; mimeName = (MimeNameProperty)o.MimeName.Clone(); mimeSource = (MimeSourceProperty)o.MimeSource.Clone(); prodId = (ProductIdProperty)o.ProductId.Clone(); nickname = (NicknameProperty)o.Nickname.Clone(); sortString = (SortStringProperty)o.SortString.Clone(); classification = (ClassificationProperty)o.Classification.Clone(); categories = (CategoriesProperty)o.Categories.Clone(); }
// GET: OrganizationProperties/Create public IActionResult Create(int?id) { if (id == null) { return(NotFound()); } var organization = _context.Organizations .Include(o => o.Properties) .SingleOrDefaultAsync(m => m.OrganizationId == id); var property = new OrganizationProperty() { OwnerOrganization = organization.Result }; organization.Result.Properties.Add(property); _context.Attach(property); return(View(property)); }
/// <summary> /// The method can be called to clear all current property values from the vCard. The version is left /// unchanged. /// </summary> public void ClearProperties() { groupName = null; fn = null; name = null; title = null; role = null; mailer = null; url = null; org = null; uid = null; bday = null; rev = null; tz = null; geo = null; key = null; photo = null; logo = null; sound = null; notes = null; addrs = null; labels = null; phones = null; email = null; agents = null; customProps = null; addProfile = false; mimeName = null; mimeSource = null; prodId = null; nickname = null; sortString = null; classification = null; categories = null; }
public void DeleteProperty_ShouldDeleteAndReturnOk() { var propertiesTestData = new List <OrganizationProperty>() { new OrganizationProperty { Id = 1, OrganizationId = 2 }, new OrganizationProperty { Id = 2, Deleted = true, OrganizationId = 2 }, new OrganizationProperty { Id = 3, OrganizationId = 3 } }; var properties = MockHelper.MockDbSet(propertiesTestData); properties.Setup(d => d.Find(It.IsAny <object>())).Returns <object[]>((keyValues) => { return(properties.Object.SingleOrDefault(product => product.Id == (int)keyValues.Single())); }); var dbContext = new Mock <IAppDbContext>(); dbContext.Setup(m => m.OrganizationProperties).Returns(properties.Object); dbContext.Setup(d => d.Set <OrganizationProperty>()).Returns(properties.Object); var factory = new Mock <IDbContextFactory>(); factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object); OrganizationProperty passport = new OrganizationProperty { Id = 3, OrganizationId = 3 }; var controller = new OrganizationPropertiesController(factory.Object); var result = controller.DeleteOrganizationProperty(3) as OkNegotiatedContentResult <OrganizationPropertyDTO>; Assert.IsNotNull(result); Assert.AreEqual(3, result.Content.Id); Assert.AreEqual(3, result.Content.OrganizationId); }
public IHttpActionResult PostArrayOrganizationProperty(IEnumerable <OrganizationPropertyConstant> properties) { if (properties == null || !ModelState.IsValid) { return(BadRequest()); } List <OrganizationPropertyDTO> propertiesToReturn = new List <OrganizationPropertyDTO>(); UnitOfWork unitOfWork = new UnitOfWork(factory); try { foreach (var item in properties) { OrganizationProperty organizationProperty = new OrganizationProperty() { DateBegin = null, DateEnd = null, Deleted = null, OrganizationId = item.OrganizationId, OrganizationPropertyTypeId = item.OrganizationPropertyTypeId, Value = item.Value }; int?propertyCountryId = unitOfWork.OrganizationPropertyTypesRepository .Get(d => d.Id == organizationProperty.OrganizationPropertyTypeId) .Select(d => d.CountryId) .FirstOrDefault(); int?organizationCountryId = unitOfWork.OrganizationsRepository .Get(d => d.Id == organizationProperty.OrganizationId) .Select(d => d.CountryId) .FirstOrDefault(); if (propertyCountryId != organizationCountryId) { return(BadRequest("Country that property belogs to, doesn't match the Organization registration country")); } organizationProperty.Id = organizationProperty.NewId(unitOfWork); unitOfWork.OrganizationPropertiesRepository.Insert(organizationProperty); unitOfWork.Save(); OrganizationPropertyDTO property = unitOfWork.OrganizationPropertiesRepository .Get(d => d.Id == organizationProperty.Id) .FirstOrDefault() .ToDTO(); property.OrganizationPropertyType = null; propertiesToReturn.Add(property); } } catch (NotFoundException nfe) { return(NotFound()); } catch (ConflictException ce) { return(Conflict()); } catch (Exception e) { return(BadRequest(e.Message)); } return(Ok(propertiesToReturn)); }
///<exclude/> public bool Equals(OrganizationProperty other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return other._Properties.SequenceEqual(_Properties); }
public void PutDocument_ShouldReturnOk() { var propertiesTestData = new List <OrganizationProperty>() { new OrganizationProperty { Id = 1, OrganizationId = 2 }, new OrganizationProperty { Id = 2, Deleted = true, OrganizationId = 2 }, new OrganizationProperty { Id = 3, OrganizationId = 3 } }; var properties = MockHelper.MockDbSet(propertiesTestData); properties.Setup(d => d.Find(It.IsAny <object>())).Returns <object[]>((keyValues) => { return(properties.Object.SingleOrDefault(product => product.Id == (int)keyValues.Single())); }); properties.Setup(d => d.Add(It.IsAny <OrganizationProperty>())).Returns <OrganizationProperty>((contact) => { propertiesTestData.Add(contact); properties = MockHelper.MockDbSet(propertiesTestData); return(contact); }); var typesTestData = new List <OrganizationPropertyType>() { new OrganizationPropertyType { Id = 1, CountryId = 1 }, new OrganizationPropertyType { Id = 2, CountryId = 1 }, new OrganizationPropertyType { Id = 3, CountryId = 2 } }; var types = MockHelper.MockDbSet(typesTestData); var orgsTestData = new List <Organization>() { new Organization { CountryId = 1 } }; var orgs = MockHelper.MockDbSet(orgsTestData); var dbContext = new Mock <IAppDbContext>(); dbContext.Setup(m => m.OrganizationProperties).Returns(properties.Object); dbContext.Setup(d => d.Set <OrganizationProperty>()).Returns(properties.Object); dbContext.Setup(m => m.Organizations).Returns(orgs.Object); dbContext.Setup(d => d.Set <Organization>()).Returns(orgs.Object); dbContext.Setup(m => m.OrganizationPropertyTypes).Returns(types.Object); dbContext.Setup(d => d.Set <OrganizationPropertyType>()).Returns(types.Object); var factory = new Mock <IDbContextFactory>(); factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object); OrganizationProperty passport = new OrganizationProperty { Id = 3, OrganizationId = 3 }; var controller = new OrganizationPropertiesController(factory.Object); var result = controller.PutOrganizationProperty(3, passport.ToDTO()) as OkNegotiatedContentResult <OrganizationPropertyDTO>; Assert.IsNotNull(result); Assert.AreEqual(3, result.Content.Id); }
public void PostProperty_ShoulAddProperty() { var propertiesTestData = new List <OrganizationProperty>() { new OrganizationProperty { Id = 1, OrganizationId = 2 }, new OrganizationProperty { Id = 2, Deleted = true, OrganizationId = 2 }, new OrganizationProperty { Id = 3, OrganizationId = 3 } }; var properties = MockHelper.MockDbSet(propertiesTestData); properties.Setup(d => d.Find(It.IsAny <object>())).Returns <object[]>((keyValues) => { return(properties.Object.SingleOrDefault(product => product.Id == (int)keyValues.Single())); }); properties.Setup(d => d.Add(It.IsAny <OrganizationProperty>())).Returns <OrganizationProperty>((contact) => { propertiesTestData.Add(contact); properties = MockHelper.MockDbSet(propertiesTestData); return(contact); }); var typesTestData = new List <OrganizationPropertyType>() { new OrganizationPropertyType { Id = 1, CountryId = 1 }, new OrganizationPropertyType { Id = 2, CountryId = 1 }, new OrganizationPropertyType { Id = 3, CountryId = 2 } }; var types = MockHelper.MockDbSet(typesTestData); var orgsTestData = new List <Organization>() { new Organization { CountryId = 1 } }; var orgs = MockHelper.MockDbSet(orgsTestData); var dbContext = new Mock <IAppDbContext>(); dbContext.Setup(m => m.OrganizationProperties).Returns(properties.Object); dbContext.Setup(d => d.Set <OrganizationProperty>()).Returns(properties.Object); dbContext.Setup(m => m.Organizations).Returns(orgs.Object); dbContext.Setup(d => d.Set <Organization>()).Returns(orgs.Object); dbContext.Setup(m => m.OrganizationPropertyTypes).Returns(types.Object); dbContext.Setup(d => d.Set <OrganizationPropertyType>()).Returns(types.Object); dbContext.Setup(d => d.ExecuteStoredProcedure <int>(It.IsAny <string>(), It.IsAny <object[]>())) .Returns <string, object[]>((query, parameters) => { List <int> list = new List <int>(); if (query.Contains("NewTableId")) { int i = properties.Object.Max(d => d.Id) + 1; list.Add(i); } else { list.Add(0); } return(list); }); var factory = new Mock <IDbContextFactory>(); factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object); OrganizationProperty passport = new OrganizationProperty { Id = 0, OrganizationId = 3 }; var controller = new OrganizationPropertiesController(factory.Object); var result = controller.PostOrganizationProperty(passport.ToDTO()) as CreatedAtRouteNegotiatedContentResult <OrganizationPropertyDTO>; Assert.IsNotNull(result); Assert.AreEqual(4, result.Content.Id); Assert.AreEqual(3, result.Content.OrganizationId); }