Exemplo n.º 1
0
        public UserInterest AddUserInterest(int userid, int interestid)
        {
            var connection = new SqlConnection(ConnectionString);

            connection.Open();

            var addUserInterests = connection.CreateCommand();

            addUserInterests.CommandText = $@"Insert into [userinterests](userid, interestid)
                                       Output inserted.*
                                       Values(@userid, @interestid)";

            addUserInterests.Parameters.AddWithValue("userid", userid);
            addUserInterests.Parameters.AddWithValue("interestid", interestid);

            var reader = addUserInterests.ExecuteReader();

            if (reader.Read())
            {
                var insertedId = (int)reader["Id"];

                var newUserInterest = new UserInterest(userid, interestid)
                {
                    Id = insertedId
                };
                connection.Close();
                return(newUserInterest);
            }
            throw new System.Exception("No interest added");
        }
        public IActionResult DeleteField(string ContentTypeID)
        {
            if (_user == null)
            {
                _user = _userManager.GetUserAsync(User).Result;
            }

            var interest = _db.ContentTypes.Where(c => c.Name == ContentTypeID).FirstOrDefault();

            _db.Entry(_user)
            .Collection(x => x.Interests)
            .Load();

            UserInterest userInterest = null;

            if (_user != null && interest != null)
            {
                userInterest = _user.Interests.Where(ui => ui.User == _user && ui.ContentType == interest).FirstOrDefault();
            }

            if (userInterest != null)
            {
                _user.Interests.Remove(userInterest);
                _db.SaveChanges();
            }

            return(RedirectToAction(nameof(MyContent)));
        }
Exemplo n.º 3
0
 public bool CheckIfSport(Sports[] sports, UserInterest userInterest, User foundUser)
 {
     for (int i = 0; i < sports.Length; i++)
     {
         if (sports[i].name == userInterest.Name)
         {
             if (ModelState.IsValid)
             {
                 try
                 {
                     userInterest.UserId = foundUser.UserId;
                     _repo.UserInterest.Create(userInterest);
                     _repo.Save();
                 }
                 catch (DbUpdateConcurrencyException)
                 {
                     if (!UserExists(foundUser.UserId))
                     {
                         return(false);
                     }
                     else
                     {
                         throw;
                     }
                 }
                 return(true);
             }
         }
     }
     return(false);
 }
 public ActionResult Wall([Bind(Include = "UserName,Interest")] UserInterest @urinterest)
 {
     db.UserInterests.Add(@urinterest);
     //var user = await UserManager.FindAsync(model.UserName, model.Password);
     db.SaveChanges();
     return(RedirectToAction("FindFriends", @urinterest));
 }
Exemplo n.º 5
0
        // Add User Interest //
        public UserInterest AddUserInterest(int userId, int interestId)
        {
            using (var connection = new SqlConnection(ConnectionString))
            {
                connection.Open();
                var insertUserInterestCommand = connection.CreateCommand();
                insertUserInterestCommand.CommandText = $@"Insert into userinterests (userId, interestId)
                                                        Output inserted.*
                                                        Values(@userId, @interestId)";

                insertUserInterestCommand.Parameters.AddWithValue("userId", userId);
                insertUserInterestCommand.Parameters.AddWithValue("interestId", interestId);

                var reader = insertUserInterestCommand.ExecuteReader();

                if (reader.Read())
                {
                    var insertedUserId     = (int)reader["userId"];
                    var insertedInterestId = (int)reader["interestId"];

                    var insertedId = (int)reader["Id"];

                    var newUserInterest = new UserInterest(insertedUserId, insertedInterestId)
                    {
                        Id = insertedId
                    };

                    return(newUserInterest);
                }
            }

            throw new Exception("Cannot Find Any User Interests");
        }
Exemplo n.º 6
0
        public void TestTeaching()
        {
            string userName = "******";

            List <BagOfWords> bags = feedService.GetAllBags();

            UserInterest interest = userService.GetUser(userName);

            if (interest == null)
            {
                interest = userService.AddUser(userName);

                FeedItem document = feedService.GetDocument("tag:blogger.com,1999:blog-19732346.post-6636802898282623833");
                userService.LikeDocument(interest, document);
                document = feedService.GetDocument("tag:blogger.com,1999:blog-19732346.post-1441194024531049182");
                userService.LikeDocument(interest, document);
            }

            BagOfWords userBag = new BagOfWords(interest.Id, interest);

            interest.Ratings = userBag.CalculateRatings(bags).Where(rating => rating.Rating > 0).ToList();
            userService.UpdateUser(interest);

            //userService.RemoveUser(userName);
        }
Exemplo n.º 7
0
        public async Task <Unit> Handle(AddUserInterestsCommand request, CancellationToken cancellationToken)
        {
            var user = await _context.Users.SingleOrDefaultAsync(x => x.Email == _userAccessor.GetEmail(), cancellationToken : cancellationToken);

            if (_context.UserInterests.Any(x => x.AppUser.Id == user.Id))
            {
                _context.UserInterests.RemoveRange(_context.UserInterests.Where(x => x.AppUser == user));
            }
            foreach (var interest in request.Ids)
            {
                if (!_context.Categories.Any(x => x.Id == interest))
                {
                    throw new RestException(HttpStatusCode.NotFound, new { Interest = "Not found" });
                }
                var interestToAdd = new UserInterest
                {
                    AppUser    = user,
                    CategoryId = interest
                };
                await _context.UserInterests.AddAsync(interestToAdd, cancellationToken);
            }
            var success = await _context.SaveChangesAsync(cancellationToken) > 0;

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

            throw new Exception("problem saving new post.");
        }
Exemplo n.º 8
0
 public EmailSendApplicationModel(UserInterest lead)
 {
     LandlordEmail = lead.Building.User.Email;
     LandlordFirstName = lead.Building.User.FirstName;
     LeadName = string.Format("{0} {1}", lead.User.FirstName, lead.User.LastName);
     BuildingId = lead.BuildingId;
 }
Exemplo n.º 9
0
        public void LikeDocument(string name, FeedItem document)
        {
            UserInterestRepository uiRep    = new UserInterestRepository();
            UserInterest           interest = uiRep.Get(name);

            LikeDocument(interest, document);
        }
Exemplo n.º 10
0
        public void LikeDocument(UserInterest interest, FeedItem document)
        {
            UserInterestRepository uiRep = new UserInterestRepository();

            interest.AddDocument(document);
            uiRep.Update(interest);
        }
Exemplo n.º 11
0
        public List <UserInterest> GetAllUserInterests()
        {
            var userInterests = new List <UserInterest>();

            var connection = new SqlConnection("Server=localhost;Database=ClinkedIn;Trusted_Connection=True;");

            connection.Open();

            var getAllUserInterestsCommand = connection.CreateCommand();

            getAllUserInterestsCommand.CommandText = @"select u.Name, i.Name Interest
                                                      from UserInterestJoin ui
                                                      left join Users u on u.Id = ui.UserId
                                                      left join Interests i on i.Id = ui.InterestId
                                                      order by u.Name";
            var reader = getAllUserInterestsCommand.ExecuteReader();

            while (reader.Read())
            {
                var name     = (string)reader["Name"];
                var interest = (string)reader["Interest"];

                var userInterest = new UserInterest(name, interest);

                userInterests.Add(userInterest);
            }

            connection.Close();

            return(userInterests);
        }
Exemplo n.º 12
0
 public EmailSendApplicationModel(UserInterest lead)
 {
     LandlordEmail     = lead.Building.User.Email;
     LandlordFirstName = lead.Building.User.FirstName;
     LeadName          = string.Format("{0} {1}", lead.User.FirstName, lead.User.LastName);
     BuildingId        = lead.BuildingId;
 }
            public async Task <bool> Handle(
                Command request,
                CancellationToken cancellationToken
                )
            {
                Guid id = request.UserInterestId;

                UserInterest existingUserInterest = _interestsDbContext.UserInterests.Find(id);

                if (existingUserInterest != null)
                {
                    Guid interestId = existingUserInterest.IdInterest;
                    _interestsDbContext.UserInterests.Remove(existingUserInterest);
                    Interest existingInterest = _interestsDbContext.Interests.Find(interestId);

                    if (existingInterest != null)
                    {
                        existingInterest.PeopleCount = existingInterest.PeopleCount - 1;
                        _interestsDbContext.Interests.Update(existingInterest);

                        return(await _interestsDbContext.SaveChangesAsync() > 0);
                    }
                    else
                    {
                        throw new AppException($"The interest {interestId} already as not been found");
                    }
                }
                else
                {
                    throw new AppException($"The user interest {id} already as not been found");
                }
            }
        // GET: Admin/Delete/5
        public ActionResult DeleteInterest(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            String user       = User.Identity.GetUserId();
            var    AdminCheck = (from p in db.CppUsers
                                 where
                                 p.AspNetUserId == user
                                 select new
            {
                p.Id,
                p.PermissionLevel
            }).FirstOrDefault();

            if (AdminCheck.PermissionLevel == 1)
            {
                UserInterest userInterest = db.UserInterests.Find(id);
                if (userInterest == null)
                {
                    return(HttpNotFound());
                }
                return(View(userInterest));
            }
            else
            {
                return(HttpNotFound());
            }
        }
Exemplo n.º 15
0
        // Get All User Interests //
        public List <UserInterest> GetAll()
        {
            var userInterests = new List <UserInterest>();

            var connection = new SqlConnection(ConnectionString);

            connection.Open();

            var getAllUserInterestsCommand = connection.CreateCommand();

            getAllUserInterestsCommand.CommandText = @"select userId, interestId, id
                                                    from userinterests";

            var reader = getAllUserInterestsCommand.ExecuteReader();

            while (reader.Read())
            {
                var id         = (int)reader["Id"];
                var userId     = (int)reader["userId"];
                var interestId = (int)reader["interestId"];

                var userinterest = new UserInterest(userId, interestId)
                {
                    Id = id
                };

                userInterests.Add(userinterest);
            }

            connection.Close();

            return(userInterests);
        }
        public ActionResult DeleteInterestConfirmed(int id)
        {
            UserInterest userInterest = db.UserInterests.Find(id);

            db.UserInterests.Remove(userInterest);
            db.SaveChanges();
            return(RedirectToAction("Admin"));
        }
Exemplo n.º 17
0
        public IActionResult RemoveInterest(int id, UserInterest userInterest)
        {
            var foundUserInterest = _repo.UserInterest.FindByCondition(a => a.UserInterestId == id).SingleOrDefault();

            _repo.UserInterest.Delete(foundUserInterest);
            _repo.Save();
            return(RedirectToAction(nameof(ViewInterests)));
        }
 /// <summary>Snippet for GetUserInterest</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetUserInterest()
 {
     // Create client
     UserInterestServiceClient userInterestServiceClient = UserInterestServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER_ID]/userInterests/[USER_INTEREST_ID]";
     // Make the request
     UserInterest response = userInterestServiceClient.GetUserInterest(resourceName);
 }
 /// <summary>Snippet for GetUserInterest</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetUserInterestResourceNames()
 {
     // Create client
     UserInterestServiceClient userInterestServiceClient = UserInterestServiceClient.Create();
     // Initialize request argument(s)
     UserInterestName resourceName = UserInterestName.FromCustomerUserInterest("[CUSTOMER_ID]", "[USER_INTEREST_ID]");
     // Make the request
     UserInterest response = userInterestServiceClient.GetUserInterest(resourceName);
 }
        public ActionResult FindFriends([Bind(Include = "UserName,Interest")] UserInterest @urinterest)
        {
            String a     = @urinterest.Interest;
            var    query = from c in db.UserInterests
                           where c.Interest == a
                           select c;

            return(View(query.ToList()));
        }
        /// <summary>Snippet for GetUserInterestAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetUserInterestAsync()
        {
            // Create client
            UserInterestServiceClient userInterestServiceClient = await UserInterestServiceClient.CreateAsync();

            // Initialize request argument(s)
            string resourceName = "customers/[CUSTOMER_ID]/userInterests/[USER_INTEREST_ID]";
            // Make the request
            UserInterest response = await userInterestServiceClient.GetUserInterestAsync(resourceName);
        }
        public int DeleteSkills([FromBody] UserInterest interest)

        {
            FRDBEntities db = new FRDBEntities();

            using (db)
            {
                return(db.DeleteUserInterest(interest.user, interest.id));
            }
        }
 public ActionResult EditInterest([Bind(Include = "Id,Interest")] UserInterest userInterest)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userInterest).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Admin"));
     }
     return(View(userInterest));
 }
        /// <summary>Snippet for GetUserInterestAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task GetUserInterestResourceNamesAsync()
        {
            // Create client
            UserInterestServiceClient userInterestServiceClient = await UserInterestServiceClient.CreateAsync();

            // Initialize request argument(s)
            UserInterestName resourceName = UserInterestName.FromCustomerUserInterest("[CUSTOMER_ID]", "[USER_INTEREST_ID]");
            // Make the request
            UserInterest response = await userInterestServiceClient.GetUserInterestAsync(resourceName);
        }
 /// <summary>Snippet for GetUserInterest</summary>
 public void GetUserInterest()
 {
     // Snippet: GetUserInterest(string, CallSettings)
     // Create client
     UserInterestServiceClient userInterestServiceClient = UserInterestServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER]/userInterests/[USER_INTEREST]";
     // Make the request
     UserInterest response = userInterestServiceClient.GetUserInterest(resourceName);
     // End snippet
 }
Exemplo n.º 26
0
        /// <summary>
        /// Creates the interest in building from the user to the current
        /// listing.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="listingId">The listing id.</param>
        /// <returns>
        /// A status of whether or not the interest was created.
        /// </returns>
        public Status <UserInterest> CreateInterestInBuilding(string username, long listingId, string message)
        {
            if (listingId == 0)
            {
                return(Status.ValidationError <UserInterest>(null, "listingId", "listingId is required"));
            }

            if (string.IsNullOrWhiteSpace(username))
            {
                return(Status.ValidationError <UserInterest>(null, "username", "username is required"));
            }

            using (var context = new RentlerContext())
            {
                try
                {
                    User user = (from u in context.Users
                                 where u.Username == username
                                 select u).SingleOrDefault();

                    if (user == null)
                    {
                        return(Status.NotFound <UserInterest>());
                    }

                    UserInterest newInterest = new UserInterest()
                    {
                        BuildingId = listingId,
                        UserId     = user.UserId,
                        Message    = message
                    };

                    context.UserInterests.Add(newInterest);
                    context.SaveChanges();

                    // loads the building, which generated this interest, into newInterest
                    context.Entry(newInterest).Reference(e => e.Building).Load();

                    // notify landlord of interest
                    // TODO: if we are unable to send this email we need a way to allow the user
                    // to re-notify the Landlord without requiring them to continue to create
                    // interests
                    EmailListingInterestedModel model = new EmailListingInterestedModel(newInterest);
                    mailer.Interested(model);

                    return(Status.OK <UserInterest>(newInterest));
                }
                catch (Exception ex)
                {
                    // log exception
                    return(Status.Error <UserInterest>("System was unable to create interest", null));
                }
            }
        }
 /// <summary>Snippet for GetUserInterest</summary>
 public void GetUserInterestResourceNames()
 {
     // Snippet: GetUserInterest(UserInterestName, CallSettings)
     // Create client
     UserInterestServiceClient userInterestServiceClient = UserInterestServiceClient.Create();
     // Initialize request argument(s)
     UserInterestName resourceName = UserInterestName.FromCustomerUserInterest("[CUSTOMER]", "[USER_INTEREST]");
     // Make the request
     UserInterest response = userInterestServiceClient.GetUserInterest(resourceName);
     // End snippet
 }
        public ActionResult AddInterest([Bind(Include = "Interest")] UserInterest userInterest)
        {
            if (ModelState.IsValid)
            {
                db.UserInterests.Add(userInterest);
                db.SaveChanges();
                return(RedirectToAction("Admin"));
            }

            return(View(userInterest));
        }
Exemplo n.º 29
0
        public AccountSendAppModel(UserInterest lead)
        {
            this.Lead = lead;

            if (lead.User == null || lead.User.UserApplication == null)
            {
                this.Input = new AccountSendAppInputModel();
            }

            this.Input = new AccountSendAppInputModel(lead.User.UserApplication);
        }
Exemplo n.º 30
0
 public async Task <IHttpActionResult> AddInterest(UserInterest Interest)
 {
     try
     {
         adminusermanagerlogic.AddInterest(Interest);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Error Occured Internally")));
     }
 }
Exemplo n.º 31
0
 public BagOfWords(string name, UserInterest interest) : this()
 {
     Name     = name;
     Interest = interest;
     foreach (Label label in interest.Labels)
     {
         Labels.Add(label.Name, new WordFrequency()
         {
             Count = label.Count, Frequency = label.Frequency
         });
     }
 }
Exemplo n.º 32
0
 public EmailRequestApplicationModel(UserInterest interest)
 {
     this.Address1 = interest.Building.Address1;
     this.Address2 = interest.Building.Address2;
     this.City = interest.Building.City;
     this.State = interest.Building.State;
     this.Zip = interest.Building.Zip;
     this.LandlordEmail = interest.Building.User.Email;
     this.LeadEmail = interest.User.Email;
     this.LeadFirstName = interest.User.FirstName;
     this.LeadId = interest.UserInterestId;
     this.Text = interest.ResponseMessage;
 }
Exemplo n.º 33
0
 public EmailListingInterestedModel(UserInterest interest)
 {
     this.Address1 = interest.Building.Address1;
     this.Address2 = interest.Building.Address2;
     this.City = interest.Building.City;
     this.State = interest.Building.State;
     this.Zip = interest.Building.Zip;
     this.LandlordEmail = interest.Building.User.Email;
     this.LandlordName = string.Format("{0} {1}", interest.Building.User.FirstName, interest.Building.User.LastName);
     this.LeadEmail = interest.User.Email;
     this.LeadName = string.Format("{0} {1}", interest.User.FirstName, interest.User.LastName);
     this.LeadId = interest.UserInterestId;
     this.Text = interest.Message;
 }
Exemplo n.º 34
0
 public PropertyViewLeadModel(UserInterest lead)
 {
     this.Lead = lead;
 }
Exemplo n.º 35
0
 public PropertyRequestAppModel(UserInterest userInterest)
 {
     this.Lead = userInterest;
     this.Input = new PropertyRequestAppInputModel();
 }
Exemplo n.º 36
0
 public AccountSendAppModel(UserInterest lead, UserApplication application)
 {
     this.Lead = lead;
     this.Input = new AccountSendAppInputModel(application);
 }
Exemplo n.º 37
0
        public AccountSendAppModel(UserInterest lead)
        {
            this.Lead = lead;

            if (lead.User == null || lead.User.UserApplication == null)
                this.Input = new AccountSendAppInputModel();

            this.Input = new AccountSendAppInputModel(lead.User.UserApplication);
        }