Exemple #1
0
        protected virtual void BindParameter(IRequestBindingContext bindingContext, RequestParameterMetadata param, RestValue sourceValue)
        {
            if (param.ParameterKind == RequestParameterKind.Route)
            {
                var segments = Bind(param, sourceValue, (n, v) => new RequestRouteSegment(n, v));
                foreach (var segment in segments)
                {
                    bindingContext.AddRouteSegment(segment);
                }
            }
            else if (param.ParameterKind == RequestParameterKind.Header)
            {
                var headers = Bind(param, sourceValue, (n, v) => new RequestHeader(n, v));
                foreach (var header in headers)
                {
                    bindingContext.AddHeader(header);
                }
            }
            else if (param.ParameterKind == RequestParameterKind.Query)
            {
                var queries = Bind(param, sourceValue, (n, v) => new RequestQuery(n, v));

                if (param.StringFormat != null)                                  //TODO костыль
                {
                    foreach (var query in queries.Where(x => !x.Content.IsNull)) //TODO filter at source level
                    {
                        var value          = (IFormattable)query.Content.Value;
                        var formattedValue = value.ToString(param.StringFormat, bindingContext.CultureInfo);

                        bindingContext.AddQuery(new RequestQuery(query.Name, RestValue.Create(formattedValue)));
                    }
                }
                else
                {
                    foreach (var query in queries.Where(x => !x.Content.IsNull)) //TODO filter at source level
                    {
                        bindingContext.AddQuery(query);
                    }
                }
            }
            else if (param.ParameterKind.In(RequestParameterKind.Body, RequestParameterKind.FormField, RequestParameterKind.FormFile))
            {
                if (bindingContext.BindingSource.TryGetValue(param.BindingSourceName, param.BindingPath, out var contentValue))
                {
                    if (param.ParameterKind == RequestParameterKind.Body)
                    {
                        var contentMediaType = param.MediaType ?? MimeTypes.Application.Json;                               //TODO
                        var contentType      = new ContentType(contentMediaType, DefaultEncodingProvider.Encoding.WebName); //TODO charset

                        bindingContext.Body = new RequestBody(contentValue, contentType);
                    }
                    else if (param.ParameterKind == RequestParameterKind.FormField)
                    {
                        var field = new RequestFormField(param.ParameterName, contentValue, param.MediaType ?? DefaultMediaTypeProvider.MediaType);

                        bindingContext.AddFormField(field);
                    }
                    else if (param.ParameterKind == RequestParameterKind.FormFile)
                    {
                        throw new NotImplementedException();
                        //var file = new RequestFormFile(contentValue, param.ParameterName)
                        //{
                        //    FileName = param.FileName,
                        //};

                        //bindingContext.AddFormField(field);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else if (param.IsRequired)
                {
                    throw new RestException(RestExceptionKind.Mapping, "req param missed");//TODO msg
                }
            }
            else
            {
                throw new NotImplementedException(param.ParameterKind.ToString()); //TODO msg
            }
            //TODO mark parameter as valid
        }
Exemple #2
0
        public void AddFormField(RequestFormField field)
        {
            field.AssertNotNull(nameof(field));

            _formFields.Add(field);
        }
Exemple #3
0
Fichier : UI.cs Projet : apxlee/SAP
        public static string GetDetails(int requestId)
        {
            Role userRole = SnapSession.CurrentUser.CurrentRole;
            bool includeADManager = false;
            int[] commentFilter;
            switch (userRole)
            {
                case Role.AccessTeam:
                case Role.SuperUser:
                    commentFilter = new int[]{(int)CommentsType.Access_Notes_Requestor,
                        (int)CommentsType.Access_Notes_ApprovingManager,
                        (int)CommentsType.Access_Notes_AccessTeam};
                    includeADManager = true;
                    break;

                case Role.ApprovingManager:
                    commentFilter = new int[]{(int)CommentsType.Access_Notes_Requestor,
                        (int)CommentsType.Access_Notes_ApprovingManager};
                    break;

                case Role.Requestor:
                default:
                    commentFilter = new int[] { (int)CommentsType.Access_Notes_Requestor };
                    break;
            }

            using (var db = new SNAPDatabaseDataContext())
            {
                var textIds = from a in db.SNAP_Access_User_Texts
                              where a.requestId == requestId
                              group a by new { a.access_details_formId } into grp
                              select new { ID = grp.Max(s => s.pkId) };

                List<int> currentTextIds = new List<int>();

                foreach (var id in textIds)
                {
                    currentTextIds.Add(id.ID);
                }

                var details = from r in db.SNAP_Requests
                              join ut in db.SNAP_Access_User_Texts on r.pkId equals ut.requestId
                              join adf in db.SNAP_Access_Details_Forms on ut.access_details_formId equals adf.pkId
                              where r.pkId == requestId && adf.isActive == true && currentTextIds.Contains(ut.pkId)
                              orderby adf.pkId ascending
                              select new
                              {
                                  Title = r.userTitle,
                                  Manager = r.managerDisplayName,
                                  ADManager = r.managerUserId,
                                  Requestor = r.submittedBy,
                                  UserId = r.userId,
                                  Label = adf.label,
                                  Text = ut.userText
                              };
                var comments = from r in db.SNAP_Requests
                               join rc in db.SNAP_Request_Comments on r.pkId equals rc.requestId
                               where r.pkId == requestId && commentFilter.Contains(rc.commentTypeEnum)
                               orderby rc.createdDate descending
                               select new
                               {
                                   Audience = MakeFriendlyCommentAudience((CommentsType)rc.commentTypeEnum),
                                   CreatedDate = rc.createdDate,
                                   Text = rc.commentText
                               };

                if (details != null)
                {
                    RequestDetails newDetails = new RequestDetails();
                    List<RequestFormField> newForm = new List<RequestFormField>();
                    string ADManager = String.Empty;
                    foreach (var detail in details)
                    {
                        if (ADManager == String.Empty) { ADManager = (includeADManager ? CompareManagerName(detail.UserId, detail.ADManager) : null); }
                        newDetails.Title = detail.Title;
                        newDetails.Manager = detail.Manager;
                        newDetails.ADManager = ADManager;
                        newDetails.Requestor = detail.Requestor;
                        newDetails.SearchLinkUrl= Model.Utilities.WebRootUrl + Model.PageNames.SEARCH + ".aspx?requestId=" +  requestId.ToString();

                        RequestFormField newField = new RequestFormField();
                        newField.Label = detail.Label;
                        newField.Text = detail.Text;
                        newForm.Add(newField);
                    }
                    newDetails.Details = newForm;

                    if (comments != null)
                    {

                        List<RequestComments> newComments = new List<RequestComments>();

                        foreach (var comment in comments)
                        {
                            RequestComments newComment = new RequestComments();
                            newComment.Audience = comment.Audience;
                            newComment.CreatedDate = comment.CreatedDate.ToString("MMM d, yyyy") + " at " + comment.CreatedDate.ToString("h:mm tt");
                            newComment.Text = comment.Text;
                            newComments.Add(newComment);
                        }
                        newDetails.Comments = newComments;
                    }

                    DataContractJsonSerializer serializer = new DataContractJsonSerializer(newDetails.GetType());
                    using (MemoryStream ms = new MemoryStream())
                    {
                        serializer.WriteObject(ms, newDetails);
                        string retVal = Encoding.Default.GetString(ms.ToArray());
                        return retVal;
                    }
                }
                return string.Empty;
            }
        }