Пример #1
0
        /// <summary>
        ///Post service base.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="attachProposedChannels"></param>
        /// <returns></returns>
        protected IActionResult Post(IVmOpenApiServiceInVersionBase request, bool attachProposedChannels = false)
        {
            if (request == null)
            {
                ModelState.AddModelError("RequestIsNull", CoreMessages.OpenApi.RequestIsNull);
                return(new BadRequestObjectResult(ModelState));
            }
            // Validate the items
            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(ModelState));
            }

            // Get the base model for service
            request = request.VersionBase();

            // Check the item values from db and validate
            if (request.PublishingStatus != PublishingStatus.Published.ToString())
            {
                request.PublishingStatus = PublishingStatus.Draft.ToString();
            }

            ServiceValidator service = new ServiceValidator(request, generalDescriptionService, codeService, fintoService, commonService, channelService, request.AvailableLanguages, UserRole());

            service.Validate(this.ModelState);

            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(ModelState));
            }

            var result = serviceService.AddService(request, Settings.AllowAnonymous, versionNumber, attachProposedChannels);

            return(Ok(result));
        }
Пример #2
0
 public IActionResult AddUser([FromBody] Service service)
 {
     if (service != null)
     {
         return(Ok(_service.AddService(service)));
     }
     return(Ok());
 }
Пример #3
0
        public void AddService_CalledCreateMethod()
        {
            //Arrange
            _serviceRepository.Setup(x => x.Create(It.IsAny <Service>()));

            //Act
            _serviceService.AddService(new ServiceDto());

            //Assert
            _serviceRepository.Verify(x => x.Create(It.IsAny <Service>()), Times.Once);
        }
Пример #4
0
        public async Task <IActionResult> CreateService([FromBody] Service service, CancellationToken cancellationToken)
        {
            var serviceAdd = await _serviceService.AddService(service, cancellationToken);

            if (serviceAdd)
            {
                return(Ok());
            }

            return(Conflict());
        }
Пример #5
0
 public IActionResult Service([FromBody] MvService service)
 {
     try
     {
         int serviceId = serviceService.AddService(service);
         return(Ok(serviceId));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Пример #6
0
        public ActionResult Create(ServiceViewModel property)
        {
            var carrierId = Url.RequestContext.RouteData.Values["id"];

            if (ModelState.IsValid)
            {
                property.CarrierId = Convert.ToInt32(carrierId);
                _serviceService.AddService(Mapper.Map <ServiceDTO>(property));
            }

            return(RedirectToAction("Index", "Service", new { id = carrierId }));
        }
Пример #7
0
 public IServiceResultWrap SaveAllChanges([FromBody] VmService model)
 {
     return(serviceManager.CallService(
                () => new ServiceLocalizedResultWrap(model)
     {
         Data = service.AddService(model),
     },
                new Dictionary <Type, string>()
     {
         { typeof(string), MessageAddService },
         { typeof(RoleActionException), MessageAddServiceRole }
     }));
 }
Пример #8
0
        private IVmOpenApiServiceBase GetAndUpdateService(IDataMapper mapper, int serviceId)
        {
            IVmOpenApiServiceBase vmResult = new VmOpenApiServiceVersionBase();

            if (alreadyUpdatedServices.Contains(serviceId))
            {
                return(vmResult);
            }

            try
            {
                var vmService = mapper.MapService(serviceId);
                if (!Settings.DebugData)
                {
                    try
                    {
                        vmResult = serviceService.AddService(vmService, false, 0, UserName);
                    }
                    catch (ExternalSourceExistsException ex)
                    {
                        // The external source for service is already in use so the item was already created into PTV. Let's update the data.
                        vmResult = serviceService.SaveService(vmService, false, 0, vmService.SourceId, UserName);
                    }
                }
                else
                {
                    vmResult = serviceService.GetServiceBySource(vmService.SourceId, 0, userName: UserName);
                }
                serviceUpdateSuccessCount++;
                alreadyUpdatedServices.Add(serviceId);
            }
            catch (Exception ex)
            {
                logger.LogError($"Error occured while updating a service: { serviceId }. { ex.Message }");
                serviceUpdateFailedCount++;
                if (!failedServices.Contains(serviceId))
                {
                    failedServices.Add(serviceId);
                }
                if (ex is EndPointNotFoundException)
                {
                    serviceEndpointNotFoundCount++;
                }
            }
            return(vmResult);
        }
        public async Task Add_Service_Successes(int id)
        {
            Setup();

            var services = GenerateListOfServices();

            var newService = new Service()
            {
                Id          = id,
                Name        = $"TestService{id}",
                Description = "More Tested Service",
                Price       = 1555
            };

            _applicationContextMock.Setup(x => x.Services).ReturnsDbSet(services);

            _testedService = new ServiceService(Logger, _applicationContextMock.Object);

            var result = (await _testedService.AddService(newService, CancellationToken.None));

            Assert.True(result);
        }
Пример #10
0
        public async Task <IActionResult> AddService(AddServiceDto serviceDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                var service = await _serviceService.AddService(serviceDto);

                return(CreatedAtAction(nameof(GetByID), new { service.Id }, service));
            }
            catch (Exception ex)
            {
                if (ex.Message.ToLower() == "conflict")
                {
                    return(Conflict($"Service with the name: {serviceDto.Name} already exists."));
                }

                return(StatusCode(500));
            }
        }
Пример #11
0
 // POST: api/Service
 public void Post([FromBody] ServiceDto service)
 {
     _serviceService.AddService(service);
 }
        private void BtnSubmitService_Click(object sender, EventArgs e)
        {
            string textServiceName            = FindViewById <EditText>(Resource.Id.editServiceName).Text;
            string textServiceDescription     = FindViewById <EditText>(Resource.Id.editServiceDescription).Text;
            string textServicePrice           = FindViewById <EditText>(Resource.Id.editServicePrice).Text;
            string testExecutionTimeInMinutes = FindViewById <EditText>(Resource.Id.etExecutionTimeInMinutes).Text;

            if (string.IsNullOrWhiteSpace(textServiceName))
            {
                Toast.MakeText(Application.Context, "Uzupełnij nazwę usługi", ToastLength.Long).Show();
            }
            else if (string.IsNullOrWhiteSpace(textServiceDescription))
            {
                Toast.MakeText(Application.Context, "Uzupełnij opis usługi", ToastLength.Long).Show();
            }
            else if (string.IsNullOrWhiteSpace(textServicePrice))
            {
                Toast.MakeText(Application.Context, "Uzupełnij cenę", ToastLength.Long).Show();
            }
            else if (!decimal.TryParse(textServicePrice, out decimal servicePrice))
            {
                Toast.MakeText(Application.Context, "Nie poprawna cena", ToastLength.Long).Show();
            }
            else if (!int.TryParse(testExecutionTimeInMinutes, out int executionTimeInMinutes))
            {
                Toast.MakeText(Application.Context, "Nie poprawny czas wykonywania", ToastLength.Long).Show();
            }
            else
            {
                OperationResult operationResult;
                if (selectedService != null)
                {
                    selectedService.Name                   = textServiceName;
                    selectedService.Description            = textServiceDescription;
                    selectedService.Price                  = servicePrice;
                    selectedService.ExecutionTimeInMinutes = executionTimeInMinutes;
                    operationResult = serviceService.EditService(selectedService);
                }
                else
                {
                    selectedService = new BLL.Models.Service
                    {
                        Name                   = textServiceName,
                        Description            = textServiceDescription,
                        Price                  = servicePrice,
                        ExecutionTimeInMinutes = executionTimeInMinutes
                    };
                    operationResult = serviceService.AddService(selectedService);
                }

                if (operationResult.ResultCode == ResultCode.Successful)
                {
                    SetResult(Result.Ok);
                    this.Finish();
                }
                else
                {
                    Toast.MakeText(Application.Context, operationResult.Message, ToastLength.Long).Show();
                }
            }
        }