Beispiel #1
0
        /// <summary>
        /// Gets new carsale from controller and transfers data to repo
        /// Takes in the date  of today to get the time of application
        /// </summary>
        /// <param name=”newCarSale”>
        /// Parameter newCarSale requires a CarSaleViewModel argument.
        /// </param>
        /// <returns>
        /// Boolean
        /// True if the car was added
        /// False if something went wrong
        /// </returns>
        public bool AddCarSale(CarSaleViewModel newCarSale)
        {
            Console.WriteLine("IN SERVICE");
            DateTime now = new DateTime(); // Date at time of application

            CarSale carSale = new CarSale
            {
                Name              = newCarSale.Name,
                SSN               = newCarSale.SSN,
                Email             = newCarSale.Email,
                Address           = newCarSale.Address,
                PhoneNum          = newCarSale.PhoneNum,
                Webpage           = newCarSale.Webpage,
                Accepted          = false,
                Active            = false,
                DateOfApplication = now
            };

            var res = _repo.AddCarSale(carSale);

            if (res == true)
            {
                // If the carsale was added successfully, we want to send email to the admin to notify
                var email = _email.CreateAdminEmail(newCarSale);
                _email.SendEmail(email);

                return(res);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        public IActionResult AddCarSale([FromBody] CarSaleViewModel newCarSale)
        {
            Console.WriteLine("CARSALE: " + newCarSale.Name);

            if (newCarSale == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(StatusCode(412));
            }

            var checkIfExists = _carSaleService.GetCarSaleByEmail(newCarSale.Email);

            if (checkIfExists != null)
            {
                return(BadRequest("This carsale is already in the database"));
            }

            var res = _carSaleService.AddCarSale(newCarSale);

            if (res == false)
            {
                return(BadRequest("Unable to post")); // Add exception here!
            }

            return(CreatedAtAction("Registered", newCarSale)); // TODO: Better way to do this? Return something else?
        }
Beispiel #3
0
        /// <summary>
        /// Composes the email that is sent to admin when a carsale has applied for an account
        /// </summary>
        /// <param name=”carSale”>
        /// CarSaleViewModel with the information about the carSale
        /// </param>
        /// <returns>
        /// EmailDTO with the composed email
        /// </returns>
        public EmailDTO CreateAdminEmail(CarSaleViewModel carSale)
        {
            EmailDTO email = new EmailDTO
            {
                head    = "Bílkaup",
                subject = "Nýr umsækjandi að kerfinu",
                body    = "Ný umsókn hefur borist á Bílkaup.is. Þú getur séð umsóknina á þínum síðum. <br /> <br />" +
                          "<strong>Bílasala:</strong> " + carSale.Name + "<br />" +
                          "<strong>Kennitala:</strong> " + carSale.SSN + "<br />" +
                          "<strong>E-mail:</strong> " + carSale.Email + "<br />" +
                          "<strong>Símanúmer:</strong> " + carSale.PhoneNum,
                receiverEmail = "*****@*****.**"
            };

            return(email);
        }
Beispiel #4
0
        public void AddCarSale()
        {
            // Arrange:
            var okCarSale = _data.okAddCarSale;
            CarSaleViewModel invalidCarSale = _data.invalidAddCarSale;

            // Act:
            var okResponse = _carSaleController.AddCarSale(okCarSale);
            CreatedAtActionResult okResult = okResponse as CreatedAtActionResult;
            //CarSaleViewModel okValue = okResult.Value as CarSaleViewModel;

            var badResponse = _carSaleController.AddCarSale(invalidCarSale);
            BadRequestObjectResult badResult = badResponse as BadRequestObjectResult;

            // Assert:
            Assert.IsInstanceOfType(okResponse, typeof(CreatedAtActionResult));
            Assert.IsInstanceOfType(badResponse, typeof(BadRequestObjectResult));
        }
Beispiel #5
0
 public EmailDTO CreateAdminEmail(CarSaleViewModel carSale)
 {
     return(new EmailDTO());
 }