public async void UnassignProfileTag(int userId, int tagId)
        {
            ProfileTag profileTag = await _context.ProfileTags.FindAsync(userId, tagId);

            if (profileTag != null)
            {
                Remove(profileTag);
            }
        }
        public async Task AssignProfileTag(int userId, int tagId)
        {
            ProfileTag profileTag = await FindByUserIdAndTagId(userId, tagId);

            if (profileTag == null)
            {
                profileTag = new ProfileTag {
                    UserId = userId, TagId = tagId
                };
                await AddAsync(profileTag);
            }
        }
        public async Task <ProfileTagResponse> UnassignProfileTagAsync(int userId, int tagId)
        {
            try
            {
                ProfileTag profileTag = await profileTagRepository.FindByUserIdAndTagId(userId, tagId);

                profileTagRepository.UnassignProfileTag(userId, tagId);
                await unitOfWork.CompleteAsync();

                return(new ProfileTagResponse(profileTag));
            }
            catch (Exception ex)
            {
                return(new ProfileTagResponse($"An error ocurred while unassigning Tag to User: {ex.Message}"));
            }
        }
Beispiel #4
0
        public static ProfileTag?DecodeProfileTag(byte[] tag)
        {
            if (tag == null || tag.Length != 20)
            {
                return(null);
            }

            ProfileTag phTag = new ProfileTag();

            BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;

            byte[] tmp = new byte[4];

            phTag.Version   = BigEndianBitConverter.ToUInt16(tag, 0);
            phTag.Kind      = (byte)((tag[2] & 0xC0) >> 6);
            phTag.Reserved  = (byte)(tag[2] & 0x3F);
            phTag.Volume    = tag[3];
            phTag.FileId    = BigEndianBitConverter.ToInt16(tag, 4);
            phTag.ValidChk |= (tag[6] & 0x80) == 0x80;
            phTag.UsedBytes = (ushort)(BigEndianBitConverter.ToUInt16(tag, 6) & 0x7FFF);

            tmp[0]        = 0x00;
            tmp[1]        = tag[8];
            tmp[2]        = tag[9];
            tmp[3]        = tag[10];
            phTag.AbsPage = BigEndianBitConverter.ToUInt32(tmp, 0);

            phTag.Checksum = tag[11];
            phTag.RelPage  = BigEndianBitConverter.ToUInt16(tag, 12);

            tmp[0]          = 0x00;
            tmp[1]          = tag[14];
            tmp[2]          = tag[15];
            tmp[3]          = tag[16];
            phTag.NextBlock = BigEndianBitConverter.ToUInt32(tmp, 0);

            tmp[0]          = 0x00;
            tmp[1]          = tag[17];
            tmp[2]          = tag[18];
            tmp[3]          = tag[19];
            phTag.PrevBlock = BigEndianBitConverter.ToUInt32(tmp, 0);

            phTag.IsLast  = phTag.NextBlock == 0xFFFFFF;
            phTag.IsFirst = phTag.PrevBlock == 0xFFFFFF;

            return(phTag);
        }
Beispiel #5
0
        //////////////////////////
        //helpers
        ///////////////////////
        //attempt to geocode the profile address
        protected void addUpdateAddrGeoTag(int profileId)
        {
            var profile = _workUnit.ProfileRepository.GetEntityByID(profileId);

            if (profile == null)
            {
                return;
            }

            var address = profile.Organization.StreetAddress;
            var zip     = profile.Organization.Zip;
            var city    = profile.Organization.City;
            var state   = profile.Organization.State;

            //if any field is empty do nothing
            if (string.IsNullOrEmpty(address) ||
                string.IsNullOrEmpty(zip) ||
                string.IsNullOrEmpty(city))
            {
                return;
            }

            //geocode
            var geocoder   = new MDLocatorWithZip();
            var jsonResult = geocoder.geocode(address, city, zip);
            var resultObj  = Net.deserializeJson(jsonResult);

            if (resultObj == null)
            {
                return;
            }
            var result = resultObj.candidates as IEnumerable <dynamic>;

            if (result == null)
            {
                return;
            }

            var     bestScore = geocoder.AcceptableScore;
            dynamic location  = null;

            //parse result (get the entry with highest score and above acceptable score 65)
            foreach (var candidate in result)
            {
                if (candidate.score > bestScore)
                {
                    bestScore = candidate.score;
                    location  = candidate.location;
                }
            }
            //create geo tag
            if (location != null)
            {
                var tagName = string.Format("{0}, {1}, {2} {3}", address, city, state, zip);
                var wkt     = string.Format("POINT({0} {1})", location.x, location.y);
                //create geo tag
                var geoTag = new GeoTag()
                {
                    Name        = tagName,
                    Geometry    = DbGeometry.PointFromText(wkt, geocoder.SpatialReference),
                    Description = "address"
                };
                //remove all old references
                try {
                    var oldAddrTagRefs = profile
                                         .ProfileTags
                                         .Where(x => (x.Tag is GeoTag) && x.Tag.Description == "address")
                                         .ToList();
                    oldAddrTagRefs.ForEach(x => _workUnit.ProfileTagRepository.DeleteEntity(x));
                    _workUnit.saveChanges();
                }
                catch (ArgumentNullException) {
                    //no item found
                }
                //update new tags
                try {
                    var currentTag = _workUnit.TagRepository.Entities.OfType <GeoTag>().First(x => x.Name.ToUpper() == tagName.ToUpper());
                    //update the geometry if it already exists
                    currentTag.Geometry = geoTag.Geometry;
                    if (currentTag.Description == "")
                    {
                        currentTag.Description = "address";
                    }
                    //update to database
                    _workUnit.TagRepository.UpdateEntity(currentTag);
                    //check if it already has referenced this profile
                    if (!profile.ProfileTags.Select(x => x.Tag).Contains(currentTag))
                    {
                        var profileTag = new ProfileTag()
                        {
                            Tag     = currentTag,
                            Profile = profile
                        };
                        _workUnit.ProfileTagRepository.InsertEntity(profileTag);
                    }
                }
                catch {
                    //create ProfileTag
                    var profileTag = new ProfileTag()
                    {
                        Tag     = geoTag,
                        Profile = profile
                    };
                    _workUnit.ProfileTagRepository.InsertEntity(profileTag);
                }
                finally {
                    _workUnit.saveChanges();
                }
            }
        }
 public void Remove(ProfileTag profileTag)
 {
     _context.ProfileTags.Remove(profileTag);
 }
 public async Task AddAsync(ProfileTag profileTag)
 {
     await _context.ProfileTags.AddAsync(profileTag);
 }
Beispiel #8
0
        public ActionResult ManageTag(ICollection <string> tags)
        {
            if (tags == null)
            {
                return(RedirectToAction("Detail", "Profile"));
            }
            var profile = CurrentAccount.Profile;

            if (profile == null)
            {
                return(new EmptyResult());
            }

            if (ModelState.IsValid)
            {
                //preexisting tags
                var preExistingTags = _workUnit.TagRepository.Entities.Select(x => x.Name).ToList();
                //new tags to be added to both reference table and tag table
                var newTags = tags.Where(x => !preExistingTags.Contains(x)).ToList();

                //now add the new tags to tag table and create new refs for them
                //this list is exclusive from the current tag list
                if (newTags != null)
                {
                    newTags.ForEach(x => {
                        var newTag = new Tag {
                            Name = x
                        };
                        _workUnit.TagRepository.InsertEntity(newTag);
                        _workUnit.ProfileTagRepository.InsertEntity(new ProfileTag {
                            Profile = profile, Tag = newTag
                        });
                    });
                }
                List <string> addedTags = null;
                //remove tags marked as removed and add current added tags
                if (profile.ProfileTags != null)
                {
                    //list of profile tag to be removed from reference table
                    var removedProfileTags = profile.ProfileTags.Where(x => !tags.Contains(x.Tag.Name)).ToList();
                    //remove tag references
                    if (removedProfileTags != null)
                    {
                        removedProfileTags.ForEach(x => _workUnit.ProfileTagRepository.DeleteEntity(x));
                    }
                    //now get the current tags
                    var currentTags = profile.ProfileTags.Select(x => x.Tag.Name).ToList();
                    //tag list to be added to reference table
                    addedTags = tags.Where(x => !currentTags.Contains(x) && preExistingTags.Contains(x)).ToList();
                }
                //no new tags but profile tags container is empty
                //so add the preExisting tags to profile
                else
                {
                    addedTags = tags.Where(x => !newTags.Contains(x)).ToList();
                }

                //now add the references to profiles
                if (addedTags != null)
                {
                    addedTags.ForEach(x => {
                        try {
                            //get the tag
                            var t = _workUnit.TagRepository.Entities.First(k => k.Name == x);
                            //create new reference
                            var reference = new ProfileTag {
                                Profile = profile, Tag = t
                            };
                            _workUnit.ProfileTagRepository.InsertEntity(reference);
                        }
                        catch {
                            //tag doesn't exist
                        }
                    });
                }

                _workUnit.saveChanges();
                return(RedirectToAction("Detail", "Profile"));
            }
            return(View());
        }