Posts

Showing posts from 2019

Web Api Create method with multiple parameters

Also, how to overload a method, say GET or PUT?

Well, lets start that with simple settings, you can't. Too many resources with partial examples makes you sometimes believe that it should be that simple (and maybe it should?), while its not.

It's also not that complicated...


Part 1 - understanding default design

When you create a new Web Api project (in vs 2017 Web Application -> empty, mark web api) you get basically nothing but the "WebApiConfig.cs" withing the "interesting" line is
routeTemplate: "api/{controller}/{id}",

And that means that whatever controller you create by default can only have it's 1st parameter, as in the url part, as "id". You cant create a method sending something like "string name".

Next step will be creating a controller class (with the (v2.1) in the end) and you will always get the suggestion of "ValuesController1". You cannot have the end of the controller name other than "Control…

How to access ngFor variable from child component or directive

the answer is ViewContainerRef

when you inject it into your constructor it has so much data in it. the ngFor data is in
this.vc['_view']['context']['$implicit']
directive full example

@Directive({
    selector:'td'
}) exportclassAddInvAmountBtnDirectiveimplementsAfterViewInit {
  el:HTMLElement constructor(ref:ElementRef, privatevc: ViewContainerRef) { this.el = ref.nativeElement   }

  @HostListener('click', ['$event']) tdClick(ev: Event){ console.log('vc._view.context.$implicit',
         this.vc['_view']['context']['$implicit']); ev.stopPropagation()   }
}

C# Asp.Net Mvc Impesonate in inner Ajax

Image
Scenario - an MVC app, while in the C# we are calling a REST api.

To make the job easier we are using RestSharp

The API is an inner api, using windows authentication

my steps:
1. using NtlmAuthenticator




2. using default credentials



3. web config - added all the following















4. IIS -> your site -> Authentication -> changed to the following











The great angular dynamic (components) edit page

Image
This one is a long story...

My comps goes like this, I GET from API a list of config rows, each of those has a list of config fields, each of those dynamically renders to an appropriate component, 2 of them are inherited 1 from another.

The flow is:
1. CTOR and ngOnInit, subscribce to 2 observables, 2 http requests for data.
2. Both subscribces call a ready fn that triggers the *ngIf
3. Then there is an *ngFor for the rows and another *ngFor for the fields
4. Down there I have my #container's for placement of a dynamic component
5. In some cases, since the dynamic component is inherited, its calling ngOnInit twice (its parent's ngOnInit)

Lets see how can we overcome each of these problems...
For implementation, see in my specially crafted git.



Problem 1:  the containers prop (my QueryList) is undefined

@ViewChildren ('container', { read:ViewContainerRef }) containers: QueryList<ViewContainerRef>;
In Part 1 of my app, open the console and see for yourself, whe…

sharepoint 2013 workflow copy list item to another site - FULL TUTORIAL

Image
This also works for SP2016, and most likely 2019.

There are quite a few tutorials out there, but each missing a step, so this is going to be a full one top to bottom.

I will make a rich tutorial with pictures, but lets review the steps, and how its done.

Workflows doesn't have a way to copy list items to another site, so you need to make an HTTP Request for that, with the Rest API. Also Workflows can't build really JSON objects, so we will need to create Workflow Dictionaries.

1. Have a source list on site A, and a destination list on site B, and open SharePoint Designer 2013 on site A.
2. Learn and test Rest request for adding an item.
3. Build our Workflow, and lets not forget to make the Request as an "App Step"
4. Enable site feature for app step
5. Give the app permissions on site B
6. Run on Item Created (for the example)
7. Error Handling

So lets go!



1. Have a source list on site A, and a destination list on site B, and open SharePoint Designer 2013 on site A.

Illegal state: Could not load the summary for directive

The above error in my case was because one of our own node modules was compiled with "node_modules" lib inside, after deleting it all worked again.

Note that with "ng build" we didnt get any errors only with "ng build -prod" (no need for double dash "--")

Error publishing (to Azure) dotnetcore app after upgrading from dotnetcore 2.0 to 2.1

Image
Background:

We just upgraded from dotnetcore 2.0 to 2.1. Most stations had the build successfully except 1, but that was because he had some dependencies projects of his own, we changed them all to 2.1 and he also had referenced one of them both in Assembly and in Projects, we removes the assembly as suggested in stackoverflow.

Then while trying to publish we got this exception in most stations:

Assets file '(project)\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v2.0'. Ensure that restore has run and that you have included 'netcoreapp2.0' in the TargetFrameworks for your project.
Most answers hiding in github mentioned deleting the bin and obj, and than help a couple of stations.
We then also Clean and Rebuild, but that also helped just a couple more.

Eventually by mistake I played and changed the Publish Configuration Settings, Save, Publish, and back to old configuration and it worked. I guess that it cleaned it own publish conf …