public async Task <ApiResponse <RequestTypeVm> > AddRequestType([FromBody] RequestTypeVm requestTypeVm)
        {
            var dbResponse = await repository.RequestTypes.AddAsync(requestTypeVm);

            if (dbResponse.Success)
            {
                return(new ApiResponse <RequestTypeVm>
                {
                    Message = dbResponse.Message,
                    Response = new RequestTypeVm(dbResponse.Response)
                });
            }

            return(new ApiResponse <RequestTypeVm>
            {
                ErrorMessage = dbResponse.ErrorMessage
            });
        }
        public async Task <ApiResponse <RequestTypeVm> > UpdateRequestType([FromBody] RequestTypeVm requestTypeVm)
        {
            var dbResponse = await repository.RequestTypes.UpdateAsync(requestTypeVm);

            if (dbResponse.Success)
            {
                var reqTypeVm = new RequestTypeVm(dbResponse.Response);

                return(new ApiResponse <RequestTypeVm>
                {
                    Message = dbResponse.Message,
                    Response = reqTypeVm
                });
            }

            return(new ApiResponse <RequestTypeVm>
            {
                ErrorMessage = dbResponse.ErrorMessage
            });
        }
Exemple #3
0
        public async Task <ApiResponse <RequestTypeVm> > GetFieldsData(long reqId, long typeId)
        {
            var requestType = await repository.RequestTypes.Items
                              .Include(x => x.RequestTypeFields)
                              .FirstOrDefaultAsync(x => x.Id == typeId);

            var defaultErrorResponse = new ApiResponse <RequestTypeVm>
            {
                ErrorMessage = "Произошла ошибка при обработке вашего запроса"
            };

            if (requestType == null)
            {
                return(defaultErrorResponse);
            }

            var dbResponse = await repository.Requests.GetRequestValuesById(reqId);

            if (dbResponse.Success)
            {
                var requestTypeVm = new RequestTypeVm(requestType);

                foreach (var fieldType in requestTypeVm.RequestTypeFields)
                {
                    var requestValue = dbResponse.Response.FirstOrDefault(x => x.RequestTypeFieldId == fieldType.Id);

                    if (requestValue != null)
                    {
                        fieldType.RequestValue = new RequestValueVm(requestValue);
                    }
                }

                return(new ApiResponse <RequestTypeVm>
                {
                    Response = requestTypeVm
                });
            }

            return(defaultErrorResponse);
        }