Esempio n. 1
0
 /// <summary>
 /// Create establishment from specified dto.
 /// </summary>
 /// <param name="imageUrl"></param>
 /// <param name="thumbnailUrl"></param>
 /// <param name="dto"></param>
 /// <returns></returns>
 private Establishment CreateEstablishment(UploadImageModel uploadedImage, RegisterEstablishmentDTO dto)
 {
     return(new Establishment(
                dto.Name,
                uploadedImage.Image,
                uploadedImage.Thumbnail,
                dto.Description,
                dto.Location != null
             ? new Location(
                    dto.Location.Street,
                    dto.Location.Number,
                    dto.Location.State,
                    dto.Location.Country,
                    dto.Location.City,
                    new GeoJson2DGeographicCoordinates(
                        dto.Location.Longitude,
                        dto.Location.Latitude
                        )
                    )
             : null,
                dto.EstablishmentTypes,
                dto.Availabilities != null
             ? dto.Availabilities.Select(availability => new Availability(availability.DayOfWeek, availability.OpenTime, availability.CloseTime))
             : null
                ));
 }
Esempio n. 2
0
        /// <summary>
        /// Inserts a new establishment.
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <Establishment> Insert(RegisterEstablishmentDTO dto)
        {
            UploadImageModel uploadedImage = await this.ImageService.UploadImage(
                EstablishmentService.EstablishmentContainer, dto.Image);

            Establishment establishment = this.CreateEstablishment(uploadedImage, dto);

            this.MongoRepository.Insert(establishment);

            return(establishment);
        }
Esempio n. 3
0
        /// <summary>
        /// Register a new user and establishment.
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <UserLoginResultDTO> Register(RegisterEstablishmentDTO dto)
        {
            dto.User.Email = dto.User.Email.ToLower();

            if (this.MongoRepository.Exists <User>(x => x.Email == dto.User.Email))
            {
                throw new BadRequestException($"Email {dto.User.Email} already in use.");
            }

            Establishment establishment = await this.EstablishmentService.Insert(dto);

            User user = this.CreateUser(establishment.Id, dto.User);

            this.MongoRepository.Insert(user);

            return(this.LoginService.Login(user, establishment));
        }
Esempio n. 4
0
        public async Task <IActionResult> Post([FromBody] RegisterEstablishmentDTO dto)
        {
            UserLoginResultDTO response = await this.RegisterService.Register(dto);

            return(Ok(response));
        }