Sei sulla pagina 1di 3

Klasni tipovi(Objekti) se nalaze na HEAPu(Dinamickoj zoni memorije).

Prosti tipovi(reference, int, double) se nalaze na STACKu(Staticka zona memorije).


SVI su izvedeni iz klase OBJECT ( Prosti izvedeni iz Value Type).
Boxing - konvertovanje prostog tipa u klasni tip.
Unbox - konvertovanje klasnog tipa u prost.
Unboxing se moze koristiti kada se ako se u metodi kao argument trazi object.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Application.Commands;
using Application.DataTransfer;
using Application.Exceptions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Northwind.API.Controllers
{
[Produces("application/json")]
[Route("api/Orders")]
public class OrdersController : Controller
{
private readonly ICreateOrderCommand _createOrder;
private readonly IDeleteOrderCommand _deleteOrders;

public OrdersController(ICreateOrderCommand createOrder,


IDeleteOrderCommand deleteOrders)
{
_createOrder = createOrder;
_deleteOrders = deleteOrders;
}

// GET: api/Orders
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}

// GET: api/Orders/5
[HttpGet("{id}", Name = "Get")]
public string Get(int id)
{
return "value";
}

// POST: api/Orders
[HttpPost]
public IActionResult Post([FromBody] CreateOrderDto dto)
{
try
{
_createOrder.Execute(dto);
return Ok();
}
catch (EntityNotFoundException e)
{
throw new EntityNotFoundException("nema");
}
catch (Exception)
{
return StatusCode(500);
}
}

// PUT: api/Orders/5
[HttpPut("{id}")]
public void Put(int id, [FromBody]string value)
{
}

// DELETE: api/ApiWithActions/5
[HttpDelete("{id}")]
public IActionResult Delete(int id)
{
try
{
_deleteOrders.Execute(id);
return NoContent();
}
catch (EntityNotFoundException e)
{
return NotFound(e.Message);
}
catch
{
return StatusCode(500, "server error");
}
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Application.Commands;
using Commands;
using DataAccess.Domain;
using EfCommands;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace Northwind.API
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services
to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddDbContext<NorthwindContext>();
services.AddTransient<ICreateOrderCommand, EfCreateOrderCommand>();
services.AddTransient<IDeleteOrderCommand, EfDeleteOrderCommand>();
services.AddTransient<IEditProductCommand, EfEditProductCommand>();
}

// This method gets called by the runtime. Use this method to configure the
HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseMvc();
}
}
}

Potrebbero piacerti anche