Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mehmetalierol
Created September 29, 2018 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mehmetalierol/766322b418acc7921e5db788cfbba389 to your computer and use it in GitHub Desktop.
Save mehmetalierol/766322b418acc7921e5db788cfbba389 to your computer and use it in GitHub Desktop.
using Company.Application.Common.Api;
using Company.Application.Common.Api.Base;
using Company.Application.Data.Entities;
using Company.Application.Dto;
using System;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using AutoMapper;
using Microsoft.AspNetCore.Http;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Company.Application.Common.Paging;
namespace Company.Application.WebApi.Controllers
{
/// <summary>
/// Müşteri tablosu işlemleri için kullanılacak sınıf.
/// </summary>
[ApiController]
[Route("Customer")]
public class CustomerController : ApiBase<Customer, CustomerDto, CustomerController>
{
public CustomerController(IServiceProvider service) : base(service)
{
}
/// <summary>
/// Include işlemi olduğu için Find metodunu override ediyoruz.
/// </summary>
/// <param name="id">İstenen kaydın Id bilgisi</param>
/// <returns></returns>
//public override ApiResult<CustomerDto> Find(Guid id)
//{
// return new ApiResult<CustomerDto>
// {
// StatusCode = StatusCodes.Status200OK,
// Message = "User founded",
// Data = Mapper.Map<Customer, CustomerDto>(GetQueryable().Include(x => x.Organization).FirstOrDefault(x => x.Id == id))
// };
//}
/// <summary>
/// Include işlemi olduğu için getall metodunu override ediyoruz.
/// </summary>
/// <returns></returns>
//public override ApiResult<List<CustomerDto>> GetAll()
//{
// return new ApiResult<List<CustomerDto>>
// {
// StatusCode = StatusCodes.Status200OK,
// Message = "User founded",
// Data = GetQueryable().Include(x=>x.Organization).ToList().Select(x => Mapper.Map<CustomerDto>(x)).ToList()
// };
//}
/// <summary>
/// Unit of work 'ün çalışması ve kayıtların veritabanına ulaşması için Add,Update,Delete metotlarını override ediyoruz
/// Bu bir zorunluluk değil eğer unitofwork'ü ApiBase içerisinde savechanges yapacak şekilde kullanırsanız bu metotları override etmek zorunda kalmazsınız
/// Ancak o zaman unit of work mantığı boş yere bu sisteme eklenmiş gibi olacak
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public override ApiResult<CustomerDto> Add([FromBody] CustomerDto item)
{
var result = base.Add(item);
_uow.SaveChanges(false);
return result;
}
public override ApiResult<CustomerDto> Update([FromBody] CustomerDto item)
{
var result = base.Update(item);
_uow.SaveChanges(true);
return result;
}
public override ApiResult<string> Delete([FromBody] CustomerDto item)
{
var result = base.Delete(item);
_uow.SaveChanges(true);
return result;
}
public override ApiResult<string> DeleteById(Guid id)
{
var result = base.DeleteById(id);
_uow.SaveChanges(true);
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment