示例#1
0
        private UserViewModel Convert(User user)
        {
            var viewModel = new UserViewModel()
            {
                FacebookLink = user.FacebookLink,
                Gender = user.Gender.HasValue ? user.Gender == Gender.Female ? "Feminino" : "Masculino" : null,
                Id = user.Id,
                Name = user.Name,
                Picture = user.Picture,
                CityName = user.City != null ? user.City.Name : null,
                StateCode = user.City != null ? user.City.State.Code : null,
                BirthDate = user.BirthDate,
                CityId = user.City != null ? user.City.Id : 0,
                StateId = user.City != null ? user.City.State.Id : 0
            };

            if (user.BirthDate.HasValue)
            {
                DateTime today = DateTime.Today;
                int age = today.Year - user.BirthDate.Value.Year;
                if (user.BirthDate.Value > today.AddYears(-age)) age--;

                viewModel.Age = age;
            }

            return viewModel;
        }
示例#2
0
        public void Remove(int id, User loggedUser)
        {
            var message = messageRepository.Get(id);

            if (message.From.Id == loggedUser.Id || message.To.Id == loggedUser.Id)
            {
                messageRepository.Remove(id);
            }
        }
示例#3
0
        public void RemoveBusLine(int busLineId, int markerId, User loggedUser)
        {
            var marker = busMarkerRepository.Get(markerId);

            if (marker.Owner.Id == loggedUser.Id)
            {
                busMarkerRepository.RemoveBusLine(busLineId, markerId);
            }
        }
示例#4
0
        public User Create(User entity)
        {
            using (var client = Server.OpenClient())
            {
                entity.Id = entity.GetHashCode();
                client.Store(entity);
            }

            return entity;
        }
示例#5
0
        public int CountUserAnswers(User user)
        {
            var count = 0;

            using (var client = Server.OpenClient())
            {
                count = client.Query<UserAnswer>(u => u.AnsweredBy.Id == user.Id).Count;
            }

            return count;
        }
示例#6
0
        public User ChangePicture(User entity)
        {
            User user = entity;

            using (var client = Server.OpenClient())
            {
                user = client.Query<User>(u => u.Id == entity.Id).SingleOrDefault();
                user.Picture = entity.Picture;

                client.Store(user);
            }

            return user;
        }
示例#7
0
        public void SaveUserAnswers(IDictionary<int, int> answers, User loggedUser)
        {
            foreach (var answer in answers)
            {
                var userAnswer = new UserAnswer()
                {
                    AnsweredBy = loggedUser,
                    AnsweredOn = DateTime.Now,
                    Question = questionRepository.Get(answer.Key),
                    Value = answer.Value
                };

                userAnswerRepository.Create(userAnswer);
            }
        }
示例#8
0
        public ActionResult Update(UserViewModel viewModel)
        {
            var user = new User()
            {
                Id = LoggedUser.Id,
                BirthDate = viewModel.BirthDate,
                City = viewModel.CityId > 0 ? cityService.Get(viewModel.CityId) : null,
                FacebookLink = viewModel.FacebookLink,
                Gender = !string.IsNullOrEmpty(viewModel.Gender) ? (Gender)(int.Parse(viewModel.Gender)) : new Gender?(),
                Name = viewModel.Name
            };

            LoggedUser = accountService.UpdateUser(user);

            return RedirectToAction("Index");
        }
示例#9
0
        public IList<HelpMarker> List(LatLng southWest, LatLng northEast, User loggedUser)
        {
            var markers = new List<HelpMarker>();

            using (var client = Server.OpenClient())
            {
                markers = client.Query<HelpMarker>(m => southWest.Lat() <= m.Lat && m.Lat <= northEast.Lat() &&
                                                        southWest.Lng() <= m.Lng && m.Lng <= northEast.Lng() &&
                                                        (
                                                            (m.Owner.Email == loggedUser.Email) ||
                                                            (!string.IsNullOrEmpty(m.Question))
                                                        )).ToList();
            }

            return markers;
        }
示例#10
0
        public IList<MarkerViewModel> ListMarkers(LatLng southWest, LatLng northEast, User loggedUser)
        {
            var markers = new List<MarkerViewModel>();

            var busMarkers = busMarkerRepository.List(southWest, northEast);
            var rideOfferMarkers = rideOfferMarkerRepository.List(southWest, northEast, loggedUser);
            var rideRequestMarkers = rideRequestMarkerRepository.List(southWest, northEast, loggedUser);
            var helpMarkers = helpMarkerRepository.List(southWest, northEast, loggedUser);

            markers.AddRange(Convert(busMarkers));
            markers.AddRange(Convert(rideOfferMarkers));
            markers.AddRange(Convert(rideRequestMarkers));
            markers.AddRange(Convert(helpMarkers));

            return markers;
        }
        public string GetRideRequestMarkerInfoDetails(int id, string template, User loggedUser)
        {
            var marker = rideRequestMarkerRepository.Get(id);

            if (marker != null)
            {
                var displayAll = (marker.Owner.Email != loggedUser.Email) ? "block" : "none";
                var displayOwner = (marker.Owner.Email != loggedUser.Email) ? "none" : "block";

                var userPicture = marker.Owner.Picture;

                var date = string.Empty;
                var time = string.Empty;

                if (marker.DateTime != DateTime.MinValue)
                {
                    date = marker.DateTime.ToString("d", new CultureInfo("pt-BR"));
                    time = marker.DateTime.ToString("t", new CultureInfo("pt-BR"));
                }

                var added = marker.Offers.Any(h => h.Id == loggedUser.Id) ? "block" : "none";
                var notAdded = added == "block" ? "none" : "block";

                var offersPictures = new StringBuilder();

                foreach (var offer in marker.Offers)
                {
                    offersPictures.AppendFormat("<a href='/Perfil/{2}'><img src='{0}' alt='Imagem do usuário' title='{1}' /></a>",
                                                    offer.Picture, offer.Name, offer.Id);
                }

                template = template.SetParam("userPicture", userPicture)
                                   .SetParam("userName", marker.Owner.Name)
                                   .SetParam("displayAll", displayAll)
                                   .SetParam("displayOwner", displayOwner)
                                   .SetParam("date", date)
                                   .SetParam("time", time)
                                   .SetParam("destination", marker.Destination)
                                   .SetParam("added", added)
                                   .SetParam("notAdded", notAdded)
                                   .SetParam("offersPictures", offersPictures.ToString())
                                   .SetParam("userId", marker.Owner.Id.ToString());
            }

            return template;
        }
示例#12
0
        public string GetHelpMarkerInfoDetails(int id, string template, User loggedUser)
        {
            var marker = helpMarkerRepository.Get(id);

            if (marker != null)
            {
                var question = marker.Question;

                var displayAll = (marker.Owner.Email != loggedUser.Email) ? "block" : "none";
                var displayOwner = (marker.Owner.Email != loggedUser.Email) ? "none" : "block";
                var displayOwner2 = (marker.Owner.Email != loggedUser.Email) ? "none" : "inline";

                var answers = new StringBuilder();

                var markerAnswers = answerRepository.List(marker.Id);

                foreach (var answer in markerAnswers.OrderByDescending(a => a.CreatedOn))
                {
                    answers.Append("<div class='item'>");
                    answers.AppendFormat("<input type='hidden' name='answerId' value='{0}' />", answer.Id);
                    answers.AppendFormat("<a href='/Perfil/{0}'><img src='{1}' alt='Imagem do usuário' title='{2}' /></a>",
                                            answer.CreatedBy.Id, answer.CreatedBy.Picture, answer.CreatedBy.Name);
                    answers.AppendFormat("<p>{0}</p>", answer.Text);
                    answers.AppendFormat("<p class='date'>{0} {1}", answer.CreatedOn.ToString("d", new CultureInfo("pt-BR")), answer.CreatedOn.ToString("t", new CultureInfo("pt-BR")));

                    if (loggedUser.Id == answer.CreatedBy.Id || loggedUser.Id == marker.Owner.Id)
                    {
                        answers.Append("<input type='button' name='remove' class='remove' value='Excluir' />");
                    }

                    answers.Append("</p></div>");
                }

                template = template.SetParam("question", question)
                                   .SetParam("displayAll", displayAll)
                                   .SetParam("displayOwner", displayOwner)
                                   .SetParam("ownerId", marker.Owner.Id.ToString())
                                   .SetParam("ownerPicture", marker.Owner.Picture)
                                   .SetParam("ownerName", marker.Owner.Name)
                                   .SetParam("date", marker.CreatedOn.ToString("d", new CultureInfo("pt-BR")))
                                   .SetParam("answers", answers.ToString())
                                   .SetParam("displayOwner2", displayOwner2);
            }

            return template;
        }
        public IList<RideRequestMarker> List(LatLng southWest, LatLng northEast, User loggedUser)
        {
            var markers = new List<RideRequestMarker>();

            using (var client = Server.OpenClient())
            {
                markers = client.Query<RideRequestMarker>(m => southWest.Lat() <= m.Lat && m.Lat <= northEast.Lat() &&
                                                             southWest.Lng() <= m.Lng && m.Lng <= northEast.Lng() &&
                                                             (
                                                                (m.Owner.Email == loggedUser.Email) ||
                                                                (m.Destination != null && m.DateTime >= DateTime.Now)
                                                             ))
                                                             .ToList();
            }

            return markers;
        }
示例#14
0
        public User CreateUser(User user, out OperationStatus operationStatus)
        {
            operationStatus = Success();

            IList<string> errors;

            if (ValidateUserCreation(user, out errors))
            {
                user.Password = EncryptPassword(user.Password);
                userRepository.Create(user);
            }
            else
            {
                operationStatus.Success = false;
                operationStatus.Messages = errors;
            }

            return user;
        }
示例#15
0
        public string GetBusMarkerInfoDetails(int id, string template, User loggedUser)
        {
            var marker = busMarkerRepository.Get(id);

            StringBuilder details = new StringBuilder("<li class='noLines'>Não há linhas associadas a este ponto de ônibus.</li>");

            if (marker.Lines.Count > 0)
            {
                details.Clear();

                foreach (var busLine in marker.Lines)
                {
                    var remove = marker.Owner.Id == loggedUser.Id ? "<input type='button' class='remove' value='Excluir'>" : "";

                    details.AppendFormat("<li><input type='hidden' name='busLineId' value='{3}' /><a href='{0}' target='_blank'>{1}</a>{2}</li>", busLine.InfoUrl, busLine.Name, remove, busLine.Id);
                }
            }

            var displayOwner = marker.Owner.Id == loggedUser.Id ? "inline" : "none";

            return template.SetParam("details", details.ToString())
                           .SetParam("displayOwner", displayOwner);
        }
        private bool CanUpdate(DateTime dateTime, int markerId, User loggedUser)
        {
            var marker = rideRequestMarkerRepository.Get(markerId);

            return (
                (marker.Owner.Id == loggedUser.Id) &&
                (dateTime > DateTime.Now)
            );
        }
        public RideRequestMarker Update(DateTime dateTime, string destination, int id, User loggedUser)
        {
            RideRequestMarker marker = null;

            if (CanUpdate(dateTime, id, loggedUser))
            {
                marker = rideRequestMarkerRepository.Update(dateTime, destination, id);
            }

            return marker;
        }
示例#18
0
        private bool ValidateUserCreation(User user, out IList<string> errors)
        {
            errors = new List<string>();

            if (ExistsEmail(user.Email))
            {
                errors.Add("Já existe uma conta registrada com esse e-mail.");
            }

            return errors.Count == 0;
        }
示例#19
0
        public void RemoveAnswer(int answerId, User loggedUser)
        {
            var answer = answerRepository.Get(answerId);

            if (answer.CreatedBy.Id == loggedUser.Id || answer.Marker.Owner.Id == loggedUser.Id)
            {
                helpMarkerRepository.RemoveAnswer(answerId);
            }
        }
示例#20
0
 public User ChangePicture(User user)
 {
     return userRepository.ChangePicture(user);
 }
示例#21
0
        public User Update(User entity)
        {
            User user = entity;

            using (var client = Server.OpenClient())
            {
                user = client.Query<User>(u => u.Id == entity.Id).SingleOrDefault();

                if (entity.City != null)
                {
                    entity.City = client.Query<City>(c => c.Id == entity.City.Id).SingleOrDefault();
                }

                user.BirthDate = entity.BirthDate;
                user.City = entity.City;
                user.FacebookLink = entity.FacebookLink;
                user.Gender = entity.Gender;
                user.Name = entity.Name;

                client.Store(user);
            }

            return user;
        }
示例#22
0
 public bool CanEvaluate(User loggedUser)
 {
     return userAnswerRepository.CountUserAnswers(loggedUser) == 0;
 }
        public void Remove(int markerId, User loggedUser)
        {
            var marker = rideRequestMarkerRepository.Get(markerId);

            if (marker.Owner.Id == loggedUser.Id)
            {
                rideRequestMarkerRepository.Remove(markerId);
            }
        }
示例#24
0
        public void Remove(int markerId, User loggedUser)
        {
            var marker = helpMarkerRepository.Get(markerId);

            if (marker.Owner.Id == loggedUser.Id)
            {
                helpMarkerRepository.Remove(markerId);
            }
        }
示例#25
0
        private bool CanUpdate(DateTime dateTime, int markerId, User loggedUser)
        {
            var marker = rideOfferMarkerRepository.Get(markerId);

            return (
                (marker.Owner.Email == loggedUser.Email) &&
                (dateTime > DateTime.Now)
            );
        }
示例#26
0
 public User UpdateUser(User user)
 {
     return userRepository.Update(user);
 }