public void Appoint_ValidObjectPassed_ReturnsOkResponse()
        {
            // Arrange
            AppointConsultantViewModel model = new AppointConsultantViewModel
            {
                ShopId       = "1",
                ConsultantId = "1"
            };

            // Act
            var okResponse = consultantsController.AppointConsultantToShop(model);

            // Assert
            Assert.IsType <OkResult>(okResponse.Result);
        }
Пример #2
0
        public async Task <ActionResult> AppointConsultantToShop([FromBody] AppointConsultantViewModel model)
        {
            logger.LogInformation("Method Consultants/AppointConsultantToShop() is called ");
            if (!ModelState.IsValid)
            {
                logger.LogInformation("Result is BadRequest(400). Error: {0}", ModelState.Values.ToString());
                return(BadRequest(ModelState));
            }

            if (await service.AppointConsultant(model))
            {
                logger.LogInformation("Result is OK(200)");
                return(Ok());
            }
            logger.LogInformation("Result is Internal Server Error(500)");
            return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
        }
Пример #3
0
 // Назначение консультанта в магазин
 public async Task <bool> AppointConsultant(AppointConsultantViewModel model)
 {
     try
     {
         var shop       = unitOfWork.Shops.GetAll().FirstOrDefault(s => s.ShopId == Convert.ToInt32(model.ShopId));
         var consultant = unitOfWork.Consultants.GetAll().FirstOrDefault(c => c.ConsultantId == Convert.ToInt32(model.ConsultantId));
         consultant.ShopId     = shop.ShopId;
         consultant.Shop       = shop;
         consultant.DateHiring = DateTime.Now;
         shop.Consultant.Add(consultant);
         unitOfWork.Shops.Update(shop);
         logger.LogInformation("Consultant {0} {1} was appointed to the shop {2} with address {3}",
                               consultant.Name, consultant.Surname, shop.ShopName, shop.Address);
         return(await unitOfWork.Complete());
     }
     catch (Exception ex)
     {
         logger.LogError("Error in Consultants/AppointConsultant: {0}", ex.Message);
         unitOfWork.Rollback();
     }
     return(false);
 }