public void SuggestionServiceTests_AddSuggestions_AddsSuggestion()
        {
            // Setup
            var setup = new TestSetup();
            // Object we will be adding
            var suggestionDto = new SuggestionDto()
            {
                Phrase = "Hello"
            };

            // Call the method we are testing
            var result = setup.SuggestionService.AddSuggestion(suggestionDto);

            // Check that same Phrase is returned
            Assert.Equal(result.Phrase, suggestionDto.Phrase);

            // Verify cache get was called only once
            setup.CacheMock.Verify(x => x.Get(CacheConstants.CACHE_KEY_SUGGESTIONS_DATA), Times.Once());
            // Verify cache add to cache was called only once
            setup.CacheMock.Verify(x => x.Add(CacheConstants.CACHE_KEY_SUGGESTIONS_DATA, It.IsAny <KeyDataSource <Suggestion> >()), Times.Once());
            // Verify repository has the item
            Assert.NotNull(setup.Repository.Queryable().Where(x => x.Phrase == suggestionDto.Phrase).FirstOrDefault());

            var suggestions = setup.SuggestionService.FindSuggestions("Hello");

            Assert.Equal(suggestions.Count(), 1);

            // Lets see if this verifies the code that returns the same suggestion without assert
            var suggestion = setup.SuggestionService.AddSuggestion(suggestionDto);
        }
Esempio n. 2
0
 public static Suggestion ToModel(this SuggestionDto suggestion) =>
 new Suggestion
 {
     Id        = Guid.Parse(suggestion.Id),
     UserId    = Guid.Parse(suggestion.UserId),
     MeetingId = Guid.Parse(suggestion.MeetingId),
     Start     = suggestion.Start.ToDateTimeOffset(),
     End       = suggestion.End.ToDateTimeOffset()
 };
        public IHttpActionResult UpdateSuggestion(SuggestionDto suggestionDto)
        {
            ;
            SuggestionDto s = BL.ManageSuggestion.UpdateSuggestion(suggestionDto);

            if (s != null)
            {
                return(Ok(BL.ManageSuggestion.GetSuggestions(suggestionDto.HostId)));
            }
            return(InternalServerError());
        }
Esempio n. 4
0
        public IHttpActionResult AddSuggestion(SuggestionDto suggestionDto)
        {
            ;
            SuggestionDto s = BL.ManageSuggestion.SaveSuggestion(suggestionDto);

            if (s != null)
            {
                return(Created <SuggestionDto>("The content inserted into the database successfully", s));
            }
            return(InternalServerError());
        }
Esempio n. 5
0
        /// TODO : simplify this part by finding a way to resolve dependencies in automapper profile
        public static SuggestionHalResponse Map(SuggestionDto suggestion, ISuggestionHalService suggestionHalService)
        {
            var mapper = new MapperConfiguration(configuration => configuration
                                                 .CreateMap <SuggestionDto, SuggestionHalResponse>()
                                                 .Ignore(suggestion => suggestion.Comments)
                                                 .AfterMap((dto, suggestionHalResponse) =>
            {
                suggestionHalResponse.Comments = suggestion.Comments.Select(comment => suggestionHalService.AddLinks(comment, suggestion.Id)).ToList();
            })
                                                 ).CreateMapper();
            var suggestionHalResponse = mapper.Map <SuggestionHalResponse>(suggestion);

            return(suggestionHalResponse);
        }
Esempio n. 6
0
        public Result <SuggestionDto> Post([FromBody] SuggestionDto suggestion, string callback = "")
        {
            Result <SuggestionDto> result = new Result <SuggestionDto>();

            try
            {
                result.succeed(suggestionBLL.insert(suggestion, 0));
            }
            catch (Exception e)
            {
                result.fail(e.Message);
            }
            return(result);
        }
        /// <summary>
        /// Save suggestion to the database and to cache.
        /// </summary>
        /// <param name="suggestion"></param>
        /// <returns></returns>
        public Suggestion AddSuggestion(SuggestionDto suggestion)
        {
            var suggestionObject = new Suggestion();

            suggestionObject.FromDto(suggestion);

            // Repository might get a different object back.
            // We will also let repository do the counting
            suggestionObject = PersistSuggestion(suggestionObject);

            var cachedData = GetCachedData();

            cachedData.Insert(suggestionObject);

            return(suggestionObject);
        }
Esempio n. 8
0
        public static DAL.Suggestion ToDAL(SuggestionDto suggestionDto)
        {
            DAL.Suggestion suggestion = new DAL.Suggestion()
            {
                SuggestionID          = suggestionDto.SuggestionID,
                SuggestionDescreotion = suggestionDto.Description,
                SuggestionTitle       = suggestionDto.Title,

                Address = new DAL.Address()
                {
                    city    = suggestionDto.City,
                    country = suggestionDto.Country,
                    street  = suggestionDto.Street,
                },

                gender = suggestionDto.Gender,
                hostId = suggestionDto.HostId,
            };
            suggestion.ServiceTypesToSuggestions = suggestionDto.ServicesType.ConvertAll <DAL.ServiceTypesToSuggestion>(s =>
            {
                return(new ServiceTypesToSuggestion()
                {
                    ServiceTypeListID = s,
                });
            });
            if (suggestionDto.RangeHours != null)
            {
                suggestion.HoursRange = new DAL.HoursRange()
                {
                    hours_end   = suggestionDto.RangeHours.MaxHour,
                    hours_start = suggestionDto.RangeHours.StartHour
                }
            }
            ;
            if (suggestionDto.RangeAge != null)
            {
                suggestion.ageRange = new DAL.ageRange()
                {
                    age_max = suggestionDto.RangeAge.MaxAge,
                    age_min = suggestionDto.RangeAge.MinAge,
                }
            }
            ;
            return(suggestion);
        }
    }
}
Esempio n. 9
0
        public ActionResult SuggestionFormPartial(SuggestionDto model)
        {
            if (!Request.IsAjaxRequest())
            {
                return(new EmptyResult());
            }
            var result = new QsResult();

            if (ModelState.IsValid)
            {
                _suggestionService.AddSuggestion(model);
                result.Success = true;
                return(Json(result));
            }
            result.Success = false;
            result.Message = @"回传成功,验证失败";
            return(Json(result));
        }
Esempio n. 10
0
        public Result <SuggestionDto> Get(int id, string callback = "")
        {
            Result <SuggestionDto> result = new Result <SuggestionDto>();

            if (LoginInfo.Unauthorized(Request.Headers))
            {
                result.unauthorized();
                return(result);
            }
            try
            {
                SuggestionDto suggestionDto = suggestionBLL.getById(id);
                result.succeed(suggestionDto);
            }
            catch (Exception e)
            {
                result.fail(e.Message);
            }
            return(result);
        }
Esempio n. 11
0
        public IActionResult Create([FromBody] SuggestionDto suggestionDto)
        {
            if (ModelState.IsValid)
            {
                if (RecaptchaResponseIsValid(suggestionDto.Recaptcha))
                {
                    Suggestion suggestion = new Suggestion();
                    suggestion.SubmitterName = suggestionDto.SubmitterName;
                    suggestion.SongName      = suggestionDto.SongName;
                    suggestion.ArtistName    = suggestionDto.ArtistName;
                    suggestion.Added         = DateTime.Now;
                    suggestion.IsActive      = true;

                    _context.Suggestions.Add(suggestion);
                    _context.SaveChanges();

                    return(Ok(suggestion));
                }
            }

            return(BadRequest());
        }
        /// <summary>
        /// Creates and returns a list with all desired time-bookings according to the inputs made by the user
        /// </summary>
        private List <SuggestionDto> InitializeSuggestions(SuggestionsQueryParams parameters, DateTimeOffset fromDate, DateTimeOffset toDate)
        {
            var suggestions = new List <SuggestionDto>();

            while (fromDate <= toDate)
            {
                var suggestion = new SuggestionDto {
                    Date = fromDate.GetShortDate()
                };
                var officeHoursStart = DateTimeOffset.Parse($"{fromDate.GetShortDate()} {parameters.OfficehoursStart}");
                var officeHoursEnds  = DateTimeOffset.Parse($"{fromDate.GetShortDate()} {parameters.OfficehoursEnd}").AddMinutes(-parameters.MeetingLength);

                while (officeHoursStart <= officeHoursEnds)
                {
                    suggestion.StartTimes.Add(officeHoursStart.GetTime());
                    officeHoursStart = officeHoursStart.AddMinutes(AppointmentTimeInterval);
                }

                suggestions.Add(suggestion);
                fromDate = fromDate.AddDays(1);
            }

            return(suggestions);
        }
Esempio n. 13
0
 public IHttpActionResult DeleteSuggestion(SuggestionDto suggestionDto)
 {
     ;
     BL.ManageSuggestion.DeleteSuggestion(suggestionDto);
     return(Ok(BL.ManageSuggestion.GetSuggestion(suggestionDto.SuggestionID)));
 }
Esempio n. 14
0
 /// <summary>
 /// עדכון הצעה
 /// </summary>
 /// <param name="suggestionDto"></param>
 /// <returns></returns>
 public static SuggestionDto UpdateSuggestion(SuggestionDto suggestionDto)
 {
     return(Suggestion.ToDTO(DAL.ManageSuggestion.UpdateSuggestion(Suggestion.ToDAL(suggestionDto))));
 }
Esempio n. 15
0
        public static SuggestionDto ToDTO(DAL.Suggestion model, int travelerId = -1)
        {
            //List<int> vs = new List<int>();
            //List<string> vss = new List<string>();
            //if (model.ServiceTypesToSuggestions.Count > 0)
            //{
            //    foreach (var item in model.ServiceTypesToSuggestions)
            //    {
            //        vs.Add(item.ServiceTypeListID);
            //    }
            //}
            //if (model.ServiceTypesToSuggestions.Count > 0)
            //{
            //    //�� �� �����!!
            //    foreach (var item in model.ServiceTypesToSuggestions)
            //    {
            //        vss.Add(item.ServiceTypeList.ServiceTypeName);
            //    }
            //}
            List <ServiceTypeMapper> lstmp = new List <ServiceTypeMapper>();

            if (model.ServiceTypesToSuggestions.Count > 0)
            {
                foreach (var item in model.ServiceTypesToSuggestions)
                {
                    string s = "";

                    //if (item.ServiceTypeList != null)
                    //    s = item.ServiceTypeList.ServiceTypeName;
                    s = DAL.ManageServicesList.GetServiceNameById(item.ServiceTypeListID);
                    lstmp.Add(new ServiceTypeMapper()
                    {
                        IdServiceType = item.ServiceTypeListID, ServiceTypeName = s
                    });
                }
            }
            SuggestionDto suggestionDto = new SuggestionDto()
            {
                SuggestionID = model.SuggestionID,
                Description  = model.SuggestionDescreotion,
                Gender       = model.gender,
                // ServicesTypeName = vss, ServicesType = vs,
                Title          = model.SuggestionTitle,
                mapperServices = lstmp,
                City           = model.Address.city,
                Country        = model.Address.country,
                Street         = model.Address.street,
                HostId         = model.hostId,
                Status         = travelerId == -1 ? null : model.SuggestionTravelers?.FirstOrDefault(s => s.TravelerId == travelerId)?.Status
                                 //boo
            };
            List <DTO.bookedDate> bookedDateDto = new List <DTO.bookedDate>();

            if (model.bookedDates != null && model.bookedDates.Count > 0)
            {
                foreach (var item in model.bookedDates)
                {
                    bookedDateDto.Add(new DTO.bookedDate()
                    {
                        dateEnd   = item.dateEnd.Value,
                        dateStart = item.dateStart.Value
                    });
                }
            }
            suggestionDto.bookedDates = bookedDateDto;
            if (model.ageRange != null)
            {
                suggestionDto.RangeAge = new AgeRange()
                {
                    MaxAge = model.ageRange.age_max,
                    MinAge = model.ageRange.age_min,
                }
            }
            ;
            if (model.HoursRange != null)
            {
                suggestionDto.RangeHours = new DTO.HoursRange()
                {
                    MaxHour   = model.HoursRange.hours_end,
                    StartHour = model.HoursRange.hours_start
                }
            }
            ;
            return(suggestionDto);
        }
Esempio n. 16
0
        public ActionResult _SuggestionFormPartial()
        {
            var model = new SuggestionDto();

            return(PartialView(model));
        }
Esempio n. 17
0
 public void AddSuggestion(SuggestionDto suggestionDto)
 {
     suggestionDto.CreateTime = DateTime.Now;
     _suggestionRepository.Add(QsMapper.CreateMap <SuggestionDto, Suggestion>(suggestionDto));
     _suggestionRepository.UnitOfWork.Commit();
 }
Esempio n. 18
0
        public static DAL.Suggestion ToDAL(SuggestionDto suggestionDto)
        {
            DAL.Suggestion suggestion = new DAL.Suggestion()
            {
                SuggestionID          = suggestionDto.SuggestionID,
                SuggestionDescreotion = suggestionDto.Description,
                SuggestionTitle       = suggestionDto.Title,

                Address = new DAL.Address()
                {
                    city    = suggestionDto.City,
                    country = suggestionDto.Country,
                    street  = suggestionDto.Street,
                },

                gender = suggestionDto.Gender,
                hostId = suggestionDto.HostId,
            };
            //suggestion.ServiceTypesToSuggestions = suggestionDto.ServicesType.ConvertAll<DAL.ServiceTypesToSuggestion>(s =>
            // {
            //     return new ServiceTypesToSuggestion()
            //     {
            //         ServiceTypeListID = s,

            //     };
            // });
            suggestion.ServiceTypesToSuggestions = suggestionDto.mapperServices.ConvertAll <DAL.ServiceTypesToSuggestion>(s =>
            {
                return(new ServiceTypesToSuggestion()
                {
                    ServiceTypeListID = s.IdServiceType,
                    // ServiceTypeList = new ServiceTypeList() { ServiceTypeListID = s.IdServiceType, ServiceTypeName = s.ServiceTypeName },
                });
            }
                                                                                                                          );
            if (suggestionDto.RangeHours != null)
            {
                suggestion.HoursRange = new DAL.HoursRange()
                {
                    hours_end   = suggestionDto.RangeHours.MaxHour,
                    hours_start = suggestionDto.RangeHours.StartHour
                }
            }
            ;
            if (suggestionDto.RangeAge != null)
            {
                suggestion.ageRange = new DAL.ageRange()
                {
                    age_max = suggestionDto.RangeAge.MaxAge,
                    age_min = suggestionDto.RangeAge.MinAge,
                }
            }
            ;
            suggestion.bookedDates = suggestionDto.bookedDates.ConvertAll <DAL.bookedDate>(s =>
            {
                return(new DAL.bookedDate()
                {
                    dateEnd = s.dateEnd, dateStart = s.dateStart,
                });
            });
            return(suggestion);
        }
    }
}
Esempio n. 19
0
        public static SuggestionDto ToDTO(DAL.Suggestion model)
        {
            List <int>    vs  = new List <int>();
            List <string> vss = new List <string>();

            if (model.ServiceTypesToSuggestions.Count > 0)
            {
                foreach (var item in model.ServiceTypesToSuggestions)
                {
                    vs.Add(item.ServiceTypeListID);
                }
            }
            if (model.ServiceTypesToSuggestions.Count > 0)
            {
                foreach (var item in model.ServiceTypesToSuggestions)
                {
                    vss.Add(item.ServiceTypeList.ServiceTypeName);
                }
            }

            SuggestionDto suggestionDto = new SuggestionDto()
            {
                SuggestionID     = model.SuggestionID,
                Description      = model.SuggestionDescreotion,
                Gender           = model.gender,
                ServicesTypeName = vss,
                Title            = model.SuggestionTitle,
                ServicesType     = vs,
                City             = model.Address.city,
                Country          = model.Address.country,
                Street           = model.Address.street,
                HostId           = model.hostId,
                //boo
            };
            List <bookedDateDto> bookedDateDto = new List <bookedDateDto>();

            if (model.bookedDates != null && model.bookedDates.Count > 0)
            {
                foreach (var item in model.bookedDates)
                {
                    bookedDateDto.Add(new DTO.bookedDateDto()
                    {
                        dateEnd   = item.dateEnd.Value,
                        dateStart = item.dateStart.Value
                    });
                }
            }
            suggestionDto.bookedDates = bookedDateDto;
            if (model.ageRange != null)
            {
                suggestionDto.RangeAge = new AgeRange()
                {
                    MaxAge = model.ageRange.age_max,
                    MinAge = model.ageRange.age_min,
                }
            }
            ;
            if (model.HoursRange != null)
            {
                suggestionDto.RangeHours = new DTO.HoursRange()
                {
                    MaxHour   = model.HoursRange.hours_end,
                    StartHour = model.HoursRange.hours_start
                }
            }
            ;
            return(suggestionDto);
        }
 public static bool DeleteSuggestion(SuggestionDto suggestionDto)
 {
     return(DAL.ManageSuggestion.DeleteSuggestion(Suggestion.ToDAL(suggestionDto)));
 }