예제 #1
0
        public ServiceBidViewModel(Model.Service service, User user)
        {
            decimal highestBid =
                new List<decimal>
                    {
                        0
                    }.Concat(
                service
                .LatestBids()
                .Select(o => o.Amount))
                .Max(o => o);

            decimal userCurrentBid =
                service
                .LatestBidForUser(user.Id)
                .Amount;

            if (service != null)
            {
                _userId = user.Id;
                _serviceId = service.Id;
                _highestBid = highestBid;
                _userCurrentBid = userCurrentBid;
                _biddingCompletionDate = service.BiddingCompletionDate;
                _description = service.Description;
                _location = service.Location.Name;
                _reference = service.Reference;
                _serviceDate = service.ServiceDue;
                _serviceTag = service.Tag.Title;
                _addtionalInfo = service.AdditionalInfos.Select(o => o.Comment).ToList();
                _addtionalInfoRequests = service.AdditionalInfoRequests.Select(o => o.Comment).ToList();

            }
            else
            {
                _addtionalInfo = new List<string>();
                _addtionalInfoRequests = new List<string>();
            }
        }
예제 #2
0
        public ServiceBidViewModel(Model.Service service, User user)
        {
            decimal lowestBid =

                service
                .LatestBids()
                .Select(o => o.Amount)
                .OrderBy(o=>o)
                .FirstOrDefault();

            Bid latestBid = service
                .LatestBidForUser(user.Id);

            decimal userCurrentBid = latestBid == null ? 0 : latestBid.Amount;

            if (service != null)
            {
                _userId = user.Id;
                _serviceId = service.Id;
                _lowestBid =  lowestBid;
                _userCurrentBid = userCurrentBid;
                _biddingCompletionDate = service.BiddingCompletionDate;
                _description = service.Description;
                _location = service.Location.Name;
                _reference = service.Reference;
                _serviceDate = service.ServiceDue;
                _serviceTag = service.Tag.Title;
                _addtionalInfo = service.AdditionalInfos.Select(o => o.Comment).ToList();
                _addtionalInfoRequests = service.AdditionalInfoRequests.Select(o => o.Comment).ToList();

            }
            else
            {
                _addtionalInfo = new List<string>();
                _addtionalInfoRequests = new List<string>();
            }
        }
예제 #3
0
        public void SaveUserProfile(Models.UserProfileViewModel userProfileViewModel)
        {
            if (userProfileViewModel == null)
                throw new ArgumentNullException("userProfileViewModel");

            int userProfileId = WebSecurity.CurrentUserId;
            User user = _serviceHubEntities.Users.SingleOrDefault(o => o.UserProfileId == userProfileId);

            if (user == null)
            {
                user = new User();
                _serviceHubEntities.Users.Add(user);
                user.UserProfileId = userProfileId;
            }

            user.About = userProfileViewModel.About ?? string.Empty;
            user.Name = userProfileViewModel.Name;
            user.ContactNumber = userProfileViewModel.ContactNumber;

            user.IsPublic = userProfileViewModel.IsPublic;

            foreach (Location location in user.Locations.ToList())
                user.Locations.Remove(location);
            foreach (Location location in _serviceHubEntities.Locations.Where(o => userProfileViewModel.Locations.Contains(o.Id)).ToList())
                user.Locations.Add(location);

            if (userProfileViewModel.Tags != null)
            {
                List<string> tagsText = userProfileViewModel.Tags.Split(',').ToList();

                List<Tag> existingTags = _serviceHubEntities.Tags.Where(o => tagsText.Contains(o.Title)).ToList();
                foreach (string tagText in tagsText)
                {
                    if (!existingTags.Any(o => string.Equals(tagText, o.Title, StringComparison.OrdinalIgnoreCase)))
                    {
                        existingTags.Add(new Tag { Title = tagText });
                    }
                }

                foreach (Tag tag in user.Tags.ToList())
                    user.Tags.Remove(tag);
                foreach (Tag tag in existingTags.ToList())
                    user.Tags.Add(tag);
            }
        }