Exemple #1
0
        public QueryResultSet<ServiceResponse> GetAllServices(string st)
        {
            int serviceStatus = -1;

            List<ServiceDetails> serviceDetailsList = null;

            List<ServiceResponse> serviceResponseList = new List<ServiceResponse>();
            QueryResultSet<ServiceResponse> resultSet = new QueryResultSet<ServiceResponse>();

            try
            {
                if (string.IsNullOrEmpty(st))
                {

                    var err = new List<Message>();
                    err.Add(new Message { Code = Convert.ToInt32(Enums.MessageCode.WarningMessage), Text = "Session Token is empty" });
                    resultSet.InfoMessages = err;

                    resultSet.IsOperationSuccessful = false;
                    resultSet.IsResult = false;
                    resultSet.ResultSet = null;
                    return resultSet;
                }

                if (!SessionHelper.IsValidSession(st))
                {
                    var err = new List<Message>();
                    err.Add(new Message { Code = Convert.ToInt32(Enums.MessageCode.WarningMessage), Text = "Invalid Session Token" });
                    resultSet.InfoMessages = err;

                    resultSet.IsOperationSuccessful = false;
                    resultSet.IsResult = false;
                    resultSet.ResultSet = null;
                    return resultSet;
                }

                using (var owlsService = new OwlsService())
                {

                    serviceStatus = Convert.ToInt32(Enums.ServiceStatus.Active);
                    var serviceItems = owlsService.dbContext.Service.Where(x => x.Status == serviceStatus).ToList();

                    if (serviceItems.Count > 0)
                    {
                        serviceDetailsList = new List<ServiceDetails>();
                        foreach(Service service in serviceItems)
                        {
                            serviceDetailsList = new ServiceDetailService().dbContext.ServiceDetails.Where(x =>x.ServiceId == service.Id && x.Status == serviceStatus).ToList();
                            var serviceResponse = owlsService.ToModelResponse(service, serviceDetailsList);
                            if (serviceResponse != null)
                            {
                                serviceResponseList.Add(serviceResponse);
                            }
                        }

                        resultSet.IsResult = true;
                        resultSet.IsOperationSuccessful = true;
                        resultSet.ResultSet = serviceResponseList;
                    }
                    else
                    {
                        var err = new List<Message>();
                        err.Add(new Message { Code = Convert.ToInt32(Enums.MessageCode.WarningMessage), Text = "Service list is empty" });
                        resultSet.InfoMessages = err;

                        resultSet.IsResult = false;
                        resultSet.IsOperationSuccessful = true;
                        resultSet.ResultSet = null;
                    }

                }
            }
            catch(Exception ex)
            {
                var err = new List<Message>();
                err.Add(new Message { Code = Convert.ToInt32(Enums.MessageCode.ErrorMessage), Text = ex.Message });
                resultSet.ErrorMessages = err;

                resultSet.IsResult = false;
                resultSet.IsOperationSuccessful = true;
                resultSet.ResultSet = null;
            }

            return resultSet;
        }
Exemple #2
0
        public QueryResult<ServiceResponse> GetServiceById(int serviceId, string st)
        {
            QueryResult<ServiceResponse> result = new QueryResult<ServiceResponse>();
            try
            {

                if (string.IsNullOrEmpty(st))
                {
                    var err = new List<Message>();
                    err.Add(new Message { Code = Convert.ToInt32(Enums.MessageCode.WarningMessage), Text = "Session Token is empty" });
                    result.InfoMessages = err;

                    result.IsOperationSuccessful = false;
                    result.IsResult = false;

                    result.Result = null;
                    return result;
                }

                if (!SessionHelper.IsValidSession(st))
                {
                    var err = new List<Message>();
                    err.Add(new Message { Code = Convert.ToInt32(Enums.MessageCode.WarningMessage), Text = "Invalid Session Token" });
                    result.InfoMessages = err;

                    result.IsOperationSuccessful = false;
                    result.IsResult = false;
                    result.Result = null;
                    return result;
                }

                if (serviceId <= 0)
                {
                    var err = new List<Message>();
                    err.Add(new Message { Code = Convert.ToInt32(Enums.MessageCode.WarningMessage), Text = "Provider id should be greather than zero" });
                    result.InfoMessages = err;

                    result.IsOperationSuccessful = false;
                    result.IsResult = false;

                    result.Result = null;
                    return result;
                }

                using (var owlsService = new OwlsService())
                {

                    Service service = owlsService.GetSingle(x => x.Id == serviceId);
                    if (service != null)
                    {
                        var response = owlsService.ToModelResponse(service);

                        if (response != null)
                        {
                            result.IsResult = true;
                            result.IsOperationSuccessful = true;
                            result.Result = response;
                        }
                        else
                        {
                            result.IsOperationSuccessful = true;
                            result.IsResult = false;
                            result.Result = null;

                            var err = new List<Message>();
                            err.Add(new Message { Code = Convert.ToInt32(Enums.MessageCode.WarningMessage), Text = "Failed to get service response model" });
                            result.InfoMessages = err;
                        }
                    }
                    else
                    {
                        result.IsOperationSuccessful = false;
                        result.IsResult = false;
                        result.Result = null;

                        var err = new List<Message>();
                        err.Add(new Message { Code = Convert.ToInt32(Enums.MessageCode.WarningMessage), Text = "Service not found" });
                        result.InfoMessages = err;
                    }

                }
            }
            catch(Exception ex)
            {
                var err = new List<Message>();
                err.Add(new Message { Code = Convert.ToInt32(Enums.MessageCode.ErrorMessage), Text = ex.Message });
                result.ErrorMessages = err;

                result.IsResult = false;
                result.IsOperationSuccessful = false;
                result.Result = null;
            }

            return result;
        }