123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using System;
- using System.Collections.Generic;
- using System.IdentityModel.Tokens.Jwt;
- using System.Linq;
- using System.Security.Claims;
- using System.Text;
- using FMSAdmin.Data;
- using FMSAdmin.Helpers;
- using FMSAdmin.Entities;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using Microsoft.IdentityModel.Tokens;
- using FMSAdmin.Models;
- namespace FMSAdmin.Services {
- public class PartnerTypeService {
- private readonly ILogger<PartnerTypeService> _logger;
- private readonly FMSContext _context;
- public PartnerTypeService(
- ILogger<PartnerTypeService> logger,
- FMSContext context) {
- _logger = logger;
- _context = context;
- }
- public void Save(CmPartnerType data) {
- var persist = _context.CmPartnerType
- .Where(x => x.PartnerTypeId == data.PartnerTypeId).FirstOrDefault();
- if (persist == null) {
- var check = _context.CmPartnerType.Where(x => x.Name == data.Name || x.PartnerTypeId == data.PartnerTypeId).Count();
- if (check > 0) {
- throw new ServiceException("이미 동일한 정보가 존재합니다.");
- }
- if (data.Name.Trim() == "검사기관") {
- throw new ServiceException("거래처 유형 명 [검사기관]은 등록할 수 없습니다.");
- }
- _context.CmPartnerType.Add(data);
- _context.SaveChanges();
- } else {
- //거래처 유형 명이 [검사기관]은 수정, 삭제할 수 없다. 2020-03-19
- if (data.PartnerTypeId == 1) {
- throw new ServiceException("거래처 유형 [검사기관]은 수정할 수 없습니다.");
- }
- //거래처 유형 명이 [검사기관]은 수정, 삭제할 수 없다. 2020-03-19
- if (data.PartnerTypeId != 1 && data.Name == "검사기관") {
- throw new ServiceException("거래처 유형 명을 [검사기관]으로 수정할 수 없습니다.");
- }
- //거래처 유형 명 중복 체크
- var check1 = _context.CmPartnerType.Where(x => x.Name == data.Name && x.PartnerTypeId != data.PartnerTypeId).Count();
- if (check1 > 0) {
- throw new ServiceException("거래처 유형 명이 동일한 정보가 존재합니다.");
- }
- persist.PartnerTypeId = data.PartnerTypeId;
- persist.Name = data.Name;
- persist.IsUse = data.IsUse;
- //
- _context.SaveChanges();
- }
- }
- public IQueryable<CmPartnerType> GetAll() {
- var query = _context.CmPartnerType;
- return query;
- }
- public IQueryable<CmPartnerType> Get(int id) {
- var data = _context.CmPartnerType.Where(x => x.PartnerTypeId == id);
- return data;
- }
- public void Delete(int id) {
- var data = _context.CmPartnerType.First(x => x.PartnerTypeId == id);
- //data.IsUse = false;
- //거래처 유형 명 [검사기관]은 삭제할 수 없다. 2020-03-19
- if (id == 1 || data.Name == "검사기관") {
- throw new ServiceException("거래처 유형이 [검사기관]은 삭제할 수 없습니다.");
- }
- _context.CmPartnerType.Remove(data); //실제 행이 삭제될 경우 처리
- _context.SaveChanges();
- }
- }
- }
|