Esempio n. 1
0
 public IHttpActionResult GetResourceById(int id)
 {
     Resource resource = resourceService.GetResourceById(id);
     var viewModel = new ResourceViewModel();
     Mapper.Map(resource, viewModel);
     return Ok(viewModel);
 }
 public IHttpActionResult PutResource(int id, ResourceViewModel resourceViewModel)
 {
     resourceViewModel.Id = id;
     var resource = resourceService.GetResourceById(id);
     Mapper.Map(resourceViewModel, resource);
     resourceService.UpdateResource(resource);
     return Ok(resourceViewModel);
 }
 public IHttpActionResult PostResource(ResourceViewModel resourceViewModel)
 {
     Resource resource = new Resource();
     Mapper.Map(resourceViewModel, resource);
     resource.CreatedOn = DateTime.Now;
     resource = resourceService.AddResource(resource);
     Mapper.Map(resource, resourceViewModel);
     return Created(Url.Link("DefaultApi", new { controller = "Resources", id = resourceViewModel.Id }), resourceViewModel);
 }
        public IHttpActionResult PostResource(ResourceViewModel resourceViewModel)
        {
            Resource resource = new Resource();
            Mapper.Map(resourceViewModel, resource);
            resource.CreatedOn = DateTime.Now;
            resource.UserId = userManager.FindByName(RequestContext.Principal.Identity.Name).Id;

            resource = resourceService.AddResource(resource);
            resourceViewModel.Id = resource.Id;
            return Created(Url.Link("DefaultApi", new { controller = "Resources", id = resourceViewModel.Id }), resourceViewModel);
        }