예제 #1
0
        public ServiceOperationStatus ActivateUserService(UserOffice userOffice, string serviceTypeName, IDictionary <string, string> data = null)
        {
            var service = GetUserService(userOffice, serviceTypeName);

            if (service == null || service.ServiceStatusId != (int)ServiceStatuses.Available)
            {
                return(ServiceOperationStatus.UnableToActivate);
            }
            data = data ?? new Dictionary <string, string>();

            var unfilledData =
                _userServiceDataRepository.GetAll(x => x.UserServiceId.Equals(service.Id) && string.IsNullOrEmpty(x.Value)).ToList();
            bool allDataUpdated = true;

            foreach (var serviceData in unfilledData)
            {
                string value;
                var    result = data.TryGetValue(serviceData.Key, out value);
                if (result)
                {
                    serviceData.Value = value;
                    _userServiceDataRepository.Update(serviceData);
                }
                else
                {
                    allDataUpdated = false;
                    break;
                }
            }
            return(allDataUpdated ? _userServiceRepository.Activate(service) : ServiceOperationStatus.RequireAdditionData);
        }
예제 #2
0
        public IActionResult GetServiceData([FromBody] UserServiceRequestModel model)
        {
            var response = new ApiResponseModel();

            var service = _userOfficeManager.GetUserService(UserOffice, model.ServiceTypeName);

            if (service.ServiceStatusId != (int)ServiceStatuses.Activated)
            {
                response.Message = "Service doesn't have an activated status";
                return(BadRequest(response));
            }

            var data = _userServiceDataRepository.GetAll(x => x.UserServiceId.Equals(service.Id));

            foreach (var d in data)
            {
                response.Data.Add(d.Key, d.Value);
            }
            return(Ok(response));
        }