Exemple #1
0
        /// <summary>
        /// Saves the item registration
        /// </summary>
        /// <param name="registrationCode"></param>
        /// <returns></returns>
        public bool SaveItemRegistration(Lok.Unik.ModelCommon.ItemRegistration.ItemRegistration registrationCode)
        {
            using (var session = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation))
            {
                var itemRegistrationCode =
                    session.Query <Lok.Unik.ModelCommon.ItemRegistration.ItemRegistration>().FirstOrDefault(dr => dr.PassCode == registrationCode.PassCode);

                if (null != itemRegistrationCode)
                {
                    return(false);
                }

                registrationCode.TimeRegistered = DateTime.UtcNow;
                session.Store(registrationCode);
                session.SaveChanges();
                return(true);
            }
        }
Exemple #2
0
        /// <summary>
        /// Registers an item on a previous invite.
        /// </summary>
        /// <param name="registrationCode"></param>
        /// <param name="itemRegistrationCode"></param>
        /// <returns>Result of the registration operation.</returns>
        public ItemRegistrationResult RegisterItem(string registrationCode, out Lok.Unik.ModelCommon.ItemRegistration.ItemRegistration itemRegistrationCode)
        {
            var itemId = Guid.NewGuid();
            var retval = new Lok.Unik.ModelCommon.ItemRegistration.ItemRegistrationResult
            {
                ItemId       = itemId,
                PassCodeName = registrationCode,
                Result       = ResultCode.RegistrationAccepted
            };

            using (var coreSession = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation))
            {
                // get the item matching the given registration code
                itemRegistrationCode =
                    coreSession.Query <Lok.Unik.ModelCommon.ItemRegistration.ItemRegistration>().FirstOrDefault(dr => dr.PassCode == registrationCode);

                // not found? registration not accepted.
                if (null == itemRegistrationCode)
                {
                    retval.ItemId   = Guid.Empty;
                    retval.AuthCode = string.Empty;
                    retval.Result   = ResultCode.RegistrationInvalidPasscode;
                    return(retval);
                }

                // save the item authorization code used to log it in
                var ac = new Lok.Unik.ModelCommon.ItemRegistration.AuthCode
                {
                    Principal  = itemId.ToString(),
                    AuthCodeId = Guid.NewGuid(),
                    Code       = AuthorizationCode.GenerateCode(),
                    Tenant     = itemRegistrationCode.TenancyId
                };

                retval.AuthCode   = ac.Code;
                retval.PassCodeId = itemRegistrationCode.Id;
                coreSession.Store(ac);
                coreSession.SaveChanges();
            }

            return(retval);
        }
Exemple #3
0
        /// <summary>
        /// saves the item registration with tags
        /// </summary>
        /// <param name="name"> </param>
        /// <param name="passcode"></param>
        /// <param name="type"></param>
        /// <param name="newTags"></param>
        /// <param name="selectTag"></param>
        /// <param name="facilityId"> </param>
        /// <returns></returns>
        public bool SaveItemRegistration(
            string name, string passcode,
            string type, IList <Tag> newTags,
            IList <string> selectTag, string facilityId = null)
        {
            using (var session = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation))
            {
                var tenancy = ContextRegistry.ContextsOf("Tenancy").First().Segments[1];

                var query = from entity in session.Query <Lok.Unik.ModelCommon.ItemRegistration.ItemRegistration>()
                            where entity.TenancyId == tenancy
                            select entity;

                // all item registrations in the tenant
                var dRegistration = query.ToArray();

                var oldTag = new List <Tag>();

                // list of existing tags matching the selection
                var oldTagFind = new List <Tag>();

                if (null != selectTag && selectTag.Count > 0)
                {
                    // record all distinct tags used for all registered items
                    oldTag.AddRange(dRegistration.SelectMany(deviceRegistration => deviceRegistration.Tags));
                    oldTag = oldTag.Distinct().ToList();

                    // for every tag selected
                    foreach (var tag2 in selectTag.Where(tag => !string.IsNullOrEmpty(tag)))
                    {
                        var tag3 = tag2;

                        // find all recorded tags matching the selection tags
                        foreach (var tag1 in oldTag.Where(tag1 => tag3.Equals(tag1.Value)))
                        {
                            oldTagFind.Add(tag1);
                            break;
                        }
                    }
                }

                oldTagFind = oldTagFind.Distinct().ToList();

                foreach (var old in oldTagFind)
                {
                    newTags.Add(old);
                }

                // retain all old tags, add in a grouping tag
                var dr = new Lok.Unik.ModelCommon.ItemRegistration.ItemRegistration
                {
                    Id             = Guid.NewGuid(),
                    TenancyId      = tenancy,
                    PassCode       = passcode,
                    Name           = name,
                    Tags           = newTags,
                    TimeRegistered = DateTime.UtcNow,
                    Type           = type,
                    FacilityId     = facilityId
                };

                //Add Default Tag for Grouping.
                dr.Tags.Add(
                    new Tag
                {
                    Id         = Guid.NewGuid(),
                    Type       = TagType.ItemRegistration,
                    Attribute  = dr.Name,
                    Value      = dr.PassCode,
                    CreateDate = DateTime.UtcNow,
                    Category   = new TagCategory {
                        Name = TagType.ItemRegistration.EnumName(), Color = KnownColor.Transparent
                    }
                });

                session.Store(dr);
                session.SaveChanges();
                return(true);
            }
        }