/
CustomersController.cs
111 lines (101 loc) · 2.87 KB
/
CustomersController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using Business.Abstract;
using Entities.Concrete;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebAPI.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class CustomersController : ControllerBase
{
ICustomerService _customerService;
public CustomersController(ICustomerService customerService)
{
_customerService = customerService;
}
[HttpGet("getall")]
public IActionResult GetAll()
{
var result = _customerService.GetAll();
if (result.Success)
{
return Ok(result);
}
return BadRequest(result);
}
[HttpGet("getbyid")]
public IActionResult GetById(int id)
{
var result = _customerService.GetById(id);
if (result.Success)
{
return Ok(result);
}
return BadRequest(result);
}
[HttpGet("getbyuserid")]
public IActionResult GetByUserId(int userId)
{
var result = _customerService.GetByUserId(userId);
if (result.Success)
{
return Ok(result);
}
return BadRequest(result);
}
[HttpGet("getbycompanyname")]
public IActionResult GetByCompanyName(string companyName)
{
var result = _customerService.GetByCompanyName(companyName);
if (result.Success)
{
return Ok(result);
}
return BadRequest(result);
}
[HttpGet("getcustomerdetails")]
public IActionResult GetCustomerDetails()
{
var result = _customerService.GetCustomerDetails();
if (result.Success)
{
return Ok(result);
}
return BadRequest(result);
}
[HttpPost("add")]
public IActionResult Add(Customer customer)
{
var result = _customerService.Add(customer);
if (result.Success)
{
return Ok(result);
}
return BadRequest(result);
}
[HttpPost("delete")]
public IActionResult Delete(Customer customer)
{
var result = _customerService.Delete(customer);
if (result.Success)
{
return Ok(result);
}
return BadRequest(result);
}
[HttpPost("update")]
public IActionResult Update(Customer customer)
{
var result = _customerService.Update(customer);
if (result.Success)
{
return Ok(result);
}
return BadRequest(result);
}
}
}