<repo_name>DeathArmy/AutoStonks.API<file_sep>/AutoStonks.API/Services/ModelService/IModelService.cs
﻿using AutoStonks.API.Dtos.Model;
using AutoStonks.API.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Services.ModelService
{
    public interface IModelService
    {
        public Task<ServiceResponse<Model>> AddModel(AddModelDto newModel);
        public Task<ServiceResponse<List<GetModelDto>>> GetAll();
        public Task<ServiceResponse<GetModelDto>> GetSpecific(int idModel);
        public Task<ServiceResponse<Model>> Update(UpdateModelDto updateModel);
        public Task<ServiceResponse<List<Model>>> Delete(int idModel);
    }
}
<file_sep>/AutoStonks.API/Dtos/Generation/PlainGenerationDto.cs
﻿using AutoStonks.API.Dtos.Model;
using AutoStonks.API.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Dtos.Generation
{
    public class PlainGenerationDto
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public PlainModelDto Model { get; set; }
    }
}
<file_sep>/AutoStonks.API/Controllers/PhotoController.cs
﻿using AutoStonks.API.Dtos.Photo;
using AutoStonks.API.Models;
using AutoStonks.API.Services.PhotoService;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class PhotoController : Controller
    {
        private readonly IPhotoService _photoService;
        public PhotoController(IPhotoService photoService)
        {
            _photoService = photoService;
        }
        [HttpGet("{AdvertId}")]
        public async Task<IActionResult> GetPhotos(int AdvertId)
        {
            ServiceResponse<List<GetPhotosDto>> response = await _photoService.GetPhotos(AdvertId);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
    }
}
<file_sep>/AutoStonks.API/Controllers/GenerationController.cs
﻿using AutoStonks.API.Dtos.Generation;
using AutoStonks.API.Models;
using AutoStonks.API.Services.GenerationService;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class GenerationController : Controller
    {
        private readonly IGenerationService _generationService;
        public GenerationController(IGenerationService generationService)
        {
            _generationService = generationService;
        }
        [HttpGet]
        public async Task<IActionResult> Get()
        {
            ServiceResponse<List<GetGenerationDto>> response = await _generationService.GetAll();
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
        [HttpGet("{idGeneration}")]
        public async Task<IActionResult> GetSpecific(int idGeneration)
        {
            ServiceResponse<GetGenerationDto> response = await _generationService.GetSpecific(idGeneration);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
        [HttpPost]
        public async Task<IActionResult> AddModel(AddGenerationDto newGeneration)
        {
            ServiceResponse<Generation> response = await _generationService.AddGeneration(newGeneration);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }

        [HttpDelete("{idGeneration}")]
        public async Task<IActionResult> DeleteModel(int idGeneration)
        {
            ServiceResponse<List<Generation>> response = await _generationService.Delete(idGeneration);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }

        [HttpPut]
        public async Task<IActionResult> UpdateModel(UpdateGenerationDto updateGeneration)
        {
            ServiceResponse<Generation> response = await _generationService.Update(updateGeneration);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
    }
}
<file_sep>/AutoStonks.API/Services/PaymentService/IPaymentService.cs
﻿using AutoStonks.API.Dtos.Payment;
using AutoStonks.API.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Services.PaymentService
{
    public interface IPaymentService
    {
        public Task<ServiceResponse<Payment>> UpdatePayment(UpdatePaymentDto updatePayment);
        public Task<ServiceResponse<Payment>> AddPayment(AddPaymentDto newPayment);
        public Task<ServiceResponse<List<GetPaymentDto>>> GetAllPaymentsForAdvert(int idAvert);
        public Task<ServiceResponse<GetPaymentDto>> GetSpecific(int idPayment);
    }
}
<file_sep>/AutoStonks.API/Dtos/Payment/AddPaymentDto.cs
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoStonks.API.Dtos.Advert;

namespace AutoStonks.API.Dtos.Payment
{
    public class AddPaymentDto
    {
        public AddAdvertDto Advert { get; set; }
        public int DurationInDays { get; set; }
    }
}
<file_sep>/AutoStonks.API/Services/AdvertService/AdvertService.cs
﻿using AutoMapper;
using AutoStonks.API.Dtos.Advert;
using AutoStonks.API.Dtos.AdvertEquipment;
using AutoStonks.API.Dtos.Payment;
using AutoStonks.API.Dtos.Photo;
using AutoStonks.API.Models;
using AutoStonks.API.Services.AdvertEquipmentService;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Services.AdvertService
{
    public class AdvertService : IAdvertService
    {
        DataContext _context;
        private readonly IMapper _mapper;
        public AdvertService(IMapper mapper, DataContext context)
        {
            _mapper = mapper;
            _context = context;
        }
        public async Task<ServiceResponse<GetPaymentDto>> AddAdvert(AddPaymentDto newAdvert)
        {
            ServiceResponse<GetPaymentDto> serviceResponse = new ServiceResponse<GetPaymentDto>();
            try
            {
                var advert = new Advert();
                advert = _mapper.Map<Advert>(newAdvert.Advert);
                foreach (var ae in newAdvert.Advert.AdvertEquipments)
                {
                    var entity = new AddAdvertEquipmentDto();
                    entity.AdvertId = ae.AdvertId;
                    entity.EquipmentId = ae.EquipmentId;
                    advert.AdvertEquipments.Add(_mapper.Map<AdvertEquipment>(entity));
                }
                _context.Adverts.Add(advert);
                _context.SaveChanges();
                var payment = new Payment();
                payment.DurationInDays = newAdvert.DurationInDays;
                payment.AdvertId = advert.Id;
                payment.PaymentInitiation = DateTime.Now;
                _context.Payments.Add(payment);
                _context.SaveChanges();
                _context.Database.ExecuteSqlRaw($"exec payment_procedure {advert.UserId}, {newAdvert.DurationInDays}, {(advert.IsPromoted ? 1 : 0)}, {payment.Id}");
                _context.Entry(payment).Reload();
                serviceResponse.Data = _mapper.Map<GetPaymentDto>(payment);
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<List<Advert>>> DeleteAdvert(int idAdvert)
        {
            ServiceResponse<List<Advert>> serviceResponse = new ServiceResponse<List<Advert>>();
            try
            {
                var entity = _context.Adverts.FirstOrDefault(a => a.Id == idAdvert);
                entity.State = States.Terminated;
                _context.SaveChanges();
                serviceResponse.Data = _context.Adverts.ToList();
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<List<GetAdvertBasicInfoDto>>> GetAllActiveBasicInfo()
        {
            ServiceResponse<List<GetAdvertBasicInfoDto>> serviceResponse = new ServiceResponse<List<GetAdvertBasicInfoDto>>();
            try
            {
                List<Advert> entity = _context.Adverts.Include(a => a.Generation).ThenInclude(g => g.Model).ThenInclude(m => m.Brand).Where(a => a.IsPromoted == false && a.State != States.Terminated).Include(p => p.Photos).ToList();
                List<Advert> response = new List<Advert>();
                foreach (Advert advert in entity)
                {
                    if (advert.Photos != null)
                    {
                        var temporary = advert.Photos.FirstOrDefault();
                        advert.Photos.Clear();
                        advert.Photos.Add(temporary);
                    }
                    response.Add(advert);
                }
                serviceResponse.Data = _mapper.Map<List<GetAdvertBasicInfoDto>>(response);
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<List<GetAdvertBasicInfoDto>>> GetAllActivePremiumInfo()
        {
            ServiceResponse<List<GetAdvertBasicInfoDto>> serviceResponse = new ServiceResponse<List<GetAdvertBasicInfoDto>>();
            try
            {
                List<Advert> entity = _context.Adverts.Include(a => a.Generation).ThenInclude(g => g.Model).ThenInclude(m => m.Brand).Where(a => a.IsPromoted == true && a.State != States.Terminated).Include(p => p.Photos).ToList();
                List<Advert> response = new List<Advert>();
                foreach (Advert advert in entity)
                {
                    if (advert.Photos != null)
                    {
                        var temporary = advert.Photos.FirstOrDefault();
                        advert.Photos.Clear();
                        advert.Photos.Add(temporary);
                    }
                    response.Add(advert);
                }
                serviceResponse.Data = _mapper.Map<List<GetAdvertBasicInfoDto>>(response);
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<List<GetAdvertBasicInfoDto>>> GetAllInactive()
        {
            ServiceResponse<List<GetAdvertBasicInfoDto>> serviceResponse = new ServiceResponse<List<GetAdvertBasicInfoDto>>();
            try
            {
                serviceResponse.Data = _context.Adverts.Where(a => a.State == States.Terminated).Select(a => _mapper.Map<GetAdvertBasicInfoDto>(a)).ToList();
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<GetAdvertBasicInfoDto>> GetSpecificBasicInfo(int idAdvert)
        {
            ServiceResponse<GetAdvertBasicInfoDto> serviceResponse = new ServiceResponse<GetAdvertBasicInfoDto>();
            try
            {
                serviceResponse.Data = _mapper.Map<GetAdvertBasicInfoDto>(_context.Adverts.Include(a => a.Generation).ThenInclude(g => g.Model).ThenInclude(m => m.Brand).Include(p => p.Photos).FirstOrDefault(a => a.Id == idAdvert));
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<GetAdvertFullInfoDto>> GetSpecificFullInfo(int idAdvert)
        {
            ServiceResponse<GetAdvertFullInfoDto> serviceResponse = new ServiceResponse<GetAdvertFullInfoDto>();
            try
            {
                var entity = _mapper.Map<GetAdvertFullInfoDto>(_context.Adverts.Include(a => a.Generation).ThenInclude(g => g.Model).ThenInclude(m => m.Brand).Include(e => e.AdvertEquipments).ThenInclude(ae => ae.Equipment).Include(p => p.Photos).FirstOrDefault(a => a.Id == idAdvert));
                entity.VisitCount++;
                _context.SaveChanges();
                serviceResponse.Data = entity;
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<string>> UpdateAdvert(UpdateAdvertDto advert)
        {
            ServiceResponse<string> serviceResponse = new ServiceResponse<string>();
            try
            {
                Advert entity = _context.Adverts.Include(ae => ae.AdvertEquipments).FirstOrDefault(a => a.Id == advert.Id);
                entity.CarProductionDate = advert.CarProductionDate;
                entity.Condition = (Models.ConditionState)advert.Condition;
                entity.Title = advert.Title;
                entity.Description = advert.Description;
                entity.Displacement = advert.Displacement;
                entity.DriveType = (Models.DriveTypes)advert.DriveType;
                entity.FirstRegistrationDate = advert.FirstRegistrationDate;
                entity.Fuel = (Models.FuelType)advert.Fuel;
                entity.GenerationId = advert.GenerationId;
                entity.HasBeenCrashed = advert.HasBeenCrashed;
                entity.Horsepower = advert.Horsepower;
                entity.Location = advert.Location;
                entity.Mileage = advert.Mileage;
                entity.PlateNumber = advert.PlateNumber;
                entity.Price = advert.Price;
                entity.State = (Models.States)advert.State;
                entity.TransmissionType = (Models.TransmissionTypes)advert.TransmissionType;
                entity.VIN = advert.VIN;
                entity.PhoneNumber = advert.PhoneNumber;

                var aeEntity = _context.AdvertEquipment.Where(a => a.AdvertId == entity.Id).ToList();
                _context.AdvertEquipment.RemoveRange(aeEntity);
                if (entity.AdvertEquipments == null) entity.AdvertEquipments = new List<AdvertEquipment>();
                foreach (var ae in advert.AdvertEquipments)
                {
                    entity.AdvertEquipments.Add(_mapper.Map<AdvertEquipment>(ae));
                }
                var photoEntity = _context.Photos.Where(a => a.AdvertId == entity.Id).ToList();
                _context.AdvertEquipment.RemoveRange(aeEntity);
                if (entity.Photos == null) entity.Photos = new List<Photo>();
                foreach (var photo in advert.Photos)
                {
                    entity.Photos.Add(_mapper.Map<Photo>(photo));
                }
                _context.SaveChanges();
                serviceResponse.Data = "wykonano";
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }
        public async Task<ServiceResponse<List<GetAdvertBasicInfoDto>>> GetAdvertsMatchingToQuery(QueryAdvertDto query)
        {
            ServiceResponse<List<GetAdvertBasicInfoDto>> serviceResponse = new ServiceResponse<List<GetAdvertBasicInfoDto>>();
            try
            {
                List<Advert> adverts = _context.Adverts.Include(g => g.Generation)
                    .ThenInclude(m => m.Model)
                        .ThenInclude(b => b.Brand)
                    .Include(p => p.Photos)
                    .ToList();
                if (query.VIN != null) adverts = adverts.Where(a => a.VIN == query.VIN).ToList();//co gdy wpiszemy część VINu?
                if (query.MinPrice > 0)
                {
                    if (query.MaxPrice == 0) adverts = adverts.Where(a => a.Price >= query.MinPrice).ToList();
                    else if (query.MaxPrice > 0 && query.MaxPrice > query.MinPrice) adverts = adverts.Where(a => a.Price >= query.MinPrice && a.Price <= query.MaxPrice).ToList();
                }
                else if (query.MaxPrice > 0) adverts = adverts.Where(a => a.Price <= query.MaxPrice).ToList();

                if (query.MinMileage > 0)
                {
                    if (query.MaxMileage == 0) adverts = adverts.Where(a => a.Mileage >= query.MinMileage).ToList();
                    else if (query.MaxMileage > 0 && query.MaxMileage > query.MinMileage) adverts = adverts.Where(a => a.Mileage >= query.MinMileage && a.Mileage <= query.MaxMileage).ToList();
                }
                else if (query.MaxMileage > 0) adverts = adverts.Where(a => a.Mileage <= query.MaxMileage).ToList();

                if (query.MinHorsepower > 0)
                {
                    if (query.MaxHorsepower == 0) adverts = adverts.Where(a => a.Horsepower >= query.MinHorsepower).ToList();
                    else if (query.MaxHorsepower > 0 && query.MaxHorsepower > query.MinHorsepower) adverts = adverts.Where(a => a.Horsepower >= query.MinHorsepower && a.Horsepower <= query.MaxHorsepower).ToList();
                }
                else if (query.MaxHorsepower > 0) adverts = adverts.Where(a => a.Horsepower <= query.MaxHorsepower).ToList();

                if (query.MinDisplacement > 0)
                {
                    if (query.MaxDisplacement == 0) adverts = adverts.Where(a => a.Displacement >= query.MinDisplacement).ToList();
                    else if (query.MaxDisplacement > 0 && query.MaxDisplacement > query.MinDisplacement) adverts = adverts.Where(a => a.Displacement >= query.MinDisplacement && a.Displacement <= query.MaxDisplacement).ToList();
                }
                else if (query.MaxDisplacement > 0) adverts = adverts.Where(a => a.Displacement <= query.MaxDisplacement).ToList();

                if (query.BrandName != null) adverts = adverts.Where(a => a.Generation.Model.Brand.Name == query.BrandName).ToList();

                if (query.ModelName != null) adverts = adverts.Where(a => a.Generation.Model.Name == query.ModelName).ToList();

                if (query.GenerationName != null) adverts = adverts.Where(a => a.Generation.Name == query.GenerationName).ToList();

                if (query.TransmissionType != null) adverts = adverts.Where(a => a.TransmissionType.ToString() == query.TransmissionType.ToString()).ToList();

                if (query.DriveType != null) adverts = adverts.Where(a => a.DriveType.ToString() == query.DriveType.ToString()).ToList();

                if (query.Condition != null) adverts = adverts.Where(a => a.Condition.ToString() == query.Condition.ToString()).ToList();

                if (query.Fuel != null) adverts = adverts.Where(a => a.Fuel.ToString() == query.Fuel.ToString()).ToList();

                if (query.FromCarProductionDate != null)
                {
                    if (query.ToCarProductionDate != null) adverts = adverts.Where(a => a.CarProductionDate.Year >= query.FromCarProductionDate.Value.Year && a.CarProductionDate.Year <= query.ToCarProductionDate.Value.Year).ToList();
                    else adverts = adverts.Where(a => a.CarProductionDate.Year >= query.FromCarProductionDate.Value.Year).ToList();
                }
                else if (query.ToCarProductionDate != null) adverts = adverts.Where(a => a.CarProductionDate.Year <= query.ToCarProductionDate.Value.Year).ToList();

                serviceResponse.Data = adverts.Select(a => _mapper.Map<GetAdvertBasicInfoDto>(a)).ToList();
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }
    }
}
<file_sep>/AutoStonks.API/Services/PaymentService/PaymentService.cs
﻿using AutoMapper;
using AutoStonks.API.Dtos.Payment;
using AutoStonks.API.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Services.PaymentService
{
    public class PaymentService : IPaymentService
    {
        DataContext _context;
        private readonly IMapper _mapper;
        public PaymentService(IMapper mapper, DataContext context)
        {
            _mapper = mapper;
            _context = context;
        }

        public async Task<ServiceResponse<Payment>> AddPayment(AddPaymentDto newPayment)
        {
            ServiceResponse<Payment> serviceResponse = new ServiceResponse<Payment>();
            try
            {
                var entity = _mapper.Map<Payment>(newPayment);
                _context.Payments.Add(entity);
                _context.SaveChanges();
                serviceResponse.Data = entity;
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<List<GetPaymentDto>>> GetAllPaymentsForAdvert(int idAvert)
        {
            ServiceResponse<List<GetPaymentDto>> serviceResponse = new ServiceResponse<List<GetPaymentDto>>();
            try
            {
                serviceResponse.Data = _context.Payments.Where(p => p.AdvertId == idAvert).Select(p => _mapper.Map<GetPaymentDto>(p)).ToList();
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<GetPaymentDto>> GetSpecific(int idPayment)
        {
            ServiceResponse<GetPaymentDto> serviceResponse = new ServiceResponse<GetPaymentDto>();
            try
            {
                serviceResponse.Data = _mapper.Map<GetPaymentDto>(_context.Payments.FirstOrDefault(p => p.Id == idPayment));
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<Payment>> UpdatePayment(UpdatePaymentDto updatePayment)
        {
            ServiceResponse<Payment> serviceResponse = new ServiceResponse<Payment>();
            try
            {
                var updatedPayment = _context.Payments.First(p => p.Id == updatePayment.Id);
                if (updatePayment.isTerminated)
                {
                    updatedPayment.PaymentTermination = DateTime.Now;
                    updatedPayment.StartDate = DateTime.Now;
                    _context.SaveChanges();
                    serviceResponse.Data = updatedPayment;
                }
                else
                {
                    serviceResponse.Data = null;
                }
                
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }
    }
}
<file_sep>/AutoStonks.API/Controllers/BrandController.cs
﻿using AutoStonks.API.Dtos.Brand;
using AutoStonks.API.Models;
using AutoStonks.API.Services.BrandService;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class BrandController : ControllerBase
    {
        private readonly IBrandService _brandService;
        public BrandController(IBrandService brandService)
        {
            _brandService = brandService;
        }
        [HttpGet]
        public async Task<IActionResult> Get()
        {
            ServiceResponse<List<GetBrandDto>> response = await _brandService.GetAll();
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
        [HttpGet("{idBrand}")]
        public async Task<IActionResult> GetSpecific(int idBrand)
        {
            ServiceResponse<GetBrandDto> response = await _brandService.GetSpecific(idBrand);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
        [HttpPost]
        public async Task<IActionResult> AddBrand(AddBrandDto newBrand)
        {
            ServiceResponse<Brand> response = await _brandService.AddBrand(newBrand);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }

        [HttpDelete("{idBrand}")]
        public async Task<IActionResult> DeleteBrand(int idBrand)
        {
            ServiceResponse<List<Brand>> response = await _brandService.DeleteBrand(idBrand);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }

        [HttpPut]
        public async Task<IActionResult> UpdateBrand(UpdateBrandDto brand)
        {
            ServiceResponse<Brand> response = await _brandService.UpdateBrand(brand);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
    }
}
<file_sep>/AutoStonks.API/Controllers/PaymentController.cs
﻿using AutoStonks.API.Dtos.Payment;
using AutoStonks.API.Models;
using AutoStonks.API.Services.PaymentService;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class PaymentController : Controller
    {
        private readonly IPaymentService _paymentService;
        public PaymentController(IPaymentService paymentService)
        {
            _paymentService = paymentService;
        }
        [HttpGet("allfor={idAdvert}")]
        public async Task<IActionResult> GetAllPaymentsForAdvert(int idAdvert)
        {
            ServiceResponse<List<GetPaymentDto>> response = await _paymentService.GetAllPaymentsForAdvert(idAdvert);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
        [HttpGet("{idPayment}")]
        public async Task<IActionResult> GetSpecific(int idPayment)
        {
            ServiceResponse<GetPaymentDto> response = await _paymentService.GetSpecific(idPayment);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
        [HttpPost]
        public async Task<IActionResult> AddPayment(AddPaymentDto addPayment)
        {
            ServiceResponse<Payment> response = await _paymentService.AddPayment(addPayment);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }

        [HttpPut]
        public async Task<IActionResult> UpdatePayment(UpdatePaymentDto updatePayment)
        {
            ServiceResponse<Payment> response = await _paymentService.UpdatePayment(updatePayment);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
    }
}
<file_sep>/AutoStonks.API/Services/GenerationService/IGenerationService.cs
﻿using AutoStonks.API.Dtos.Generation;
using AutoStonks.API.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Services.GenerationService
{
    public interface IGenerationService
    {
        public Task<ServiceResponse<Generation>> AddGeneration(AddGenerationDto newGeneration);
        public Task<ServiceResponse<List<GetGenerationDto>>> GetAll();
        public Task<ServiceResponse<GetGenerationDto>> GetSpecific(int idGeneration);
        public Task<ServiceResponse<Generation>> Update(UpdateGenerationDto updateGeneration);
        public Task<ServiceResponse<List<Generation>>> Delete(int idGeneration);
    }
}
<file_sep>/AutoStonks.API/Services/BrandService/BrandService.cs
﻿using AutoMapper;
using AutoStonks.API.Dtos.Brand;
using AutoStonks.API.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Services.BrandService
{
    public class BrandService : IBrandService
    {
        DataContext _context;
        private readonly IMapper _mapper;
        public BrandService(IMapper mapper, DataContext context)
        {
            _mapper = mapper;
            _context = context;
        }
        public async Task<ServiceResponse<Brand>> AddBrand(AddBrandDto brand)
        {
            ServiceResponse<Brand> serviceResponse = new ServiceResponse<Brand>();
            try
            {
                var entity = _mapper.Map<Brand>(brand);
                _context.Brands.Add(entity);
                _context.SaveChanges();
                serviceResponse.Data = entity;
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<List<Brand>>> DeleteBrand(int idBrand)
        {
            ServiceResponse<List<Brand>> serviceResponse = new ServiceResponse<List<Brand>>();
            try
            {
                var entity = _context.Brands.FirstOrDefault(b => b.Id == idBrand);
                _context.Brands.Remove(entity);
                serviceResponse.Data = _context.Brands.ToList();
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<List<GetBrandDto>>> GetAll()
        {
            ServiceResponse<List<GetBrandDto>> serviceResponse = new ServiceResponse<List<GetBrandDto>>();
            try
            {
                serviceResponse.Data = _context.Brands.Include(b => b.Models).ThenInclude(m => m.Generations).Select(b => _mapper.Map<GetBrandDto>(b)).ToList();
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<Brand>> UpdateBrand(UpdateBrandDto brand)
        {
            ServiceResponse<Brand> serviceResponse = new ServiceResponse<Brand>();
            try
            {
                var entity = _context.Brands.FirstOrDefault(b => b.Id == brand.Id);
                entity.Name = brand.Name;
                _context.SaveChanges();
                serviceResponse.Data = entity;
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<GetBrandDto>> GetSpecific(int idBrand)
        {
            ServiceResponse<GetBrandDto> serviceResponse = new ServiceResponse<GetBrandDto>();
            try
            {
                var temp = _context.Brands.Include(b => b.Models).ThenInclude(m => m.Generations).FirstOrDefault(b => b.Id == idBrand);
                serviceResponse.Data = _mapper.Map<GetBrandDto>(temp);
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }
    }
}
<file_sep>/AutoStonks.API/Services/UserService/IUserService.cs
﻿using AutoStonks.API.Dtos.User;
using AutoStonks.API.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Services.UserService
{
    public interface IUserService
    {
        public Task<ServiceResponse<GetUserDto>> GetUserById(int id);
        public Task<ServiceResponse<UserDto>> AddUser(AddUserDto newUser);
        public Task<ServiceResponse<List<GetUsersDto>>> GetAllUsers();
        public Task<ServiceResponse<GetUserDto>> UpdateUser(UpdateUserDto updateCharacter);
        public Task<ServiceResponse<DeleteUserDto>> DeleteUser(int id);
        public Task<ServiceResponse<UserDto>> Login(LoginDto login);
        public Task<ServiceResponse<UserDto>> PasswordChange(PasswordChangeDto pwdChange);
    }
}
<file_sep>/AutoStonks.API/Migrations/20210201191203_seed.cs
﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace AutoStonks.API.Migrations
{
    public partial class seed : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.InsertData(
                table: "Brands",
                columns: new[] { "Id", "Name" },
                values: new object[,]
                {
                    { 1, "Renault" },
                    { 2, "BMW" },
                    { 3, "Mercedes-Benz" },
                    { 4, "Audi" },
                    { 5, "<NAME>" },
                    { 6, "Opel" },
                    { 7, "Volkswagen" },
                    { 8, "Toyota" },
                    { 9, "Ford" },
                    { 10, "Polonez" }
                });

            migrationBuilder.InsertData(
                table: "Equipment",
                columns: new[] { "Id", "Name" },
                values: new object[,]
                {
                    { 40, "MP3" },
                    { 39, "Kurtyny powietrzne" },
                    { 38, "Komputer pokładowy" },
                    { 37, "Klimatyzacja manualna" },
                    { 36, "Klimtayzacja dwustrefowa" },
                    { 31, "Hak" },
                    { 34, "Klimatyzacja automatyczna" },
                    { 33, "Kamera cofania" },
                    { 32, "Isofix" },
                    { 41, "Nawigacja GPS" },
                    { 35, "Klimatyzacja czterostrefowa" },
                    { 42, "Ogranicznik prędkości" },
                    { 47, "Podgrzewane tylne siedzenia" },
                    { 44, "Podgrzewana przednia szyba" },
                    { 45, "Podgrzewane lusterka boczne" },
                    { 46, "Podgrzewane przednie siedzenia" },
                    { 30, "Gniazdo USB" },
                    { 48, "Szyberdach" },
                    { 49, "Światła do jazdy dziennej" },
                    { 50, "Światła LED" },
                    { 51, "Światła przecwmgielne" },
                    { 52, "Światła Xenonowe" },
                    { 53, "Tapicerka skórzana" },
                    { 54, "Tapicerka welurowa" },
                    { 55, "Tempomat" },
                    { 43, "Ogrzewanie postojowe" },
                    { 29, "Gniazdo SD" },
                    { 24, "Elektrochromatyczne lusterko wsteczne" },
                    { 27, "ESP (stabilizacja toru jazdy)" },
                    { 1, "ABS" },
                    { 2, "CD" },
                    { 3, "Centralny zamek" }
                });

            migrationBuilder.InsertData(
                table: "Equipment",
                columns: new[] { "Id", "Name" },
                values: new object[,]
                {
                    { 4, "Elektryczne szyby przednia" },
                    { 5, "Elektrycznie ustawiane lusterka" },
                    { 6, "Immobilizer" },
                    { 7, "Poduszka powietrzna kierowcy" },
                    { 8, "Poduszka powietrzna pasażera" },
                    { 9, "Radio fabryczne" },
                    { 10, "Wspomaganie kierownicy" },
                    { 11, "Alarm" },
                    { 12, "Alufelgi" },
                    { 28, "Gniazdo AUX" },
                    { 13, "ASR (kontrola trakcji)" },
                    { 15, "Asysten pasa ruchu" },
                    { 16, "Bluetooth" },
                    { 17, "<NAME>" },
                    { 18, "<NAME> pola" },
                    { 19, "<NAME>" },
                    { 20, "Czujniki prakowania przednie" },
                    { 21, "Czujniki parkowania tylne" },
                    { 22, "<NAME>" },
                    { 23, "Elektrochromatyczne lusterka boczne" },
                    { 56, "Wielofunkcyjna kierownica" },
                    { 25, "Elektryczne szyby tylne" },
                    { 26, "Elektrycznie ustawiane fotele" },
                    { 14, "Asystent parkowania" }
                });

            migrationBuilder.InsertData(
                table: "Users",
                columns: new[] { "Id", "EmailAddress", "EnforcePasswordChange", "IsActive", "LastPasswordChange", "Password", "Role", "Salt", "Username" },
                values: new object[] { 1, "<EMAIL>", false, true, new DateTime(2021, 2, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), "츊း뤮䷔뛦熜뀹獳㴗༫暸쨥櫆됈", "A", "⣶刌䅦윽璅ꚮ�闏ⵁ堣帠䳀�壨瘶晤", "admin" });

            migrationBuilder.InsertData(
                table: "Models",
                columns: new[] { "Id", "BrandId", "Name" },
                values: new object[,]
                {
                    { 1, 1, "Clio" },
                    { 26, 9, "Sierra" },
                    { 25, 9, "Escort" },
                    { 24, 8, "Yaris" },
                    { 23, 7, "Bora" },
                    { 22, 7, "Golf" },
                    { 21, 7, "Passat" },
                    { 20, 6, "Insignia" },
                    { 19, 6, "Vectra" },
                    { 18, 6, "Corsa" },
                    { 17, 5, "Brera" },
                    { 16, 5, "156" },
                    { 15, 5, "147" },
                    { 14, 5, "159" },
                    { 13, 4, "A8" },
                    { 12, 4, "A6" },
                    { 11, 4, "A4" },
                    { 10, 3, "<NAME>" },
                    { 9, 3, "<NAME>" },
                    { 8, 2, "<NAME>" },
                    { 7, 2, "<NAME>" },
                    { 6, 2, "<NAME>" },
                    { 5, 1, "Captur" },
                    { 4, 1, "Scenic" },
                    { 3, 1, "Laguna" },
                    { 2, 1, "Megane" },
                    { 27, 9, "Focus" },
                    { 28, 10, "Caro" }
                });

            migrationBuilder.InsertData(
                table: "Generations",
                columns: new[] { "Id", "ModelId", "Name" },
                values: new object[,]
                {
                    { 1, 1, "III (2005-2012)" },
                    { 20, 15, "I (2000-2010)" },
                    { 21, 16, "I (1999-2006)" },
                    { 22, 17, "I (2005-2010)" },
                    { 23, 18, "C (2000-2006)" },
                    { 24, 18, "D (2006-2014)" },
                    { 25, 19, "C (2002-2008)" },
                    { 19, 14, "I (2005-2012)" },
                    { 26, 20, "A (2008-2017)" },
                    { 28, 21, "B5 FL (2000-2005)" },
                    { 29, 22, "V (2003-2009)" },
                    { 30, 23, "V (2003-2009)" },
                    { 31, 24, "Jetta IV (1998-2005)" },
                    { 32, 25, "Mk7 (1995-1999)" },
                    { 33, 26, "Mk2 (1987-1993)" },
                    { 27, 21, "B5 (1996-2000)" },
                    { 34, 27, "Mk4 (2018-)" },
                    { 18, 13, "D3 (2002-2010)" },
                    { 16, 11, "B7 (2004-2007)" },
                    { 2, 1, "IV (2012-2018)" },
                    { 3, 1, "V (2019-)" },
                    { 4, 2, "III (2008-2016)" },
                    { 5, 2, "IV (2016-)" },
                    { 6, 3, "III (2007-2015)" },
                    { 7, 4, "III (2009-2013)" },
                    { 17, 12, "C6 (2004-2011)" },
                    { 8, 4, "I (2013-2019)" },
                    { 10, 5, "E46 (1998-2007)" },
                    { 11, 6, "E39 (1996-2003)" },
                    { 12, 8, "E38 (1994-2001)" },
                    { 13, 9, "W203 (2000-2007)" },
                    { 14, 10, "W124 (1993-1997)" },
                    { 15, 11, "B6 (2000-2004)" },
                    { 9, 5, "E36 (1990-1999)" },
                    { 35, 28, "I (1978-1991)" }
                });
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 1);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 2);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 3);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 4);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 5);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 6);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 7);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 8);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 9);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 10);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 11);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 12);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 13);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 14);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 15);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 16);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 17);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 18);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 19);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 20);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 21);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 22);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 23);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 24);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 25);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 26);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 27);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 28);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 29);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 30);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 31);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 32);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 33);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 34);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 35);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 36);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 37);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 38);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 39);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 40);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 41);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 42);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 43);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 44);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 45);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 46);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 47);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 48);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 49);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 50);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 51);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 52);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 53);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 54);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 55);

            migrationBuilder.DeleteData(
                table: "Equipment",
                keyColumn: "Id",
                keyValue: 56);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 1);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 2);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 3);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 4);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 5);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 6);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 7);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 8);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 9);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 10);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 11);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 12);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 13);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 14);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 15);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 16);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 17);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 18);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 19);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 20);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 21);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 22);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 23);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 24);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 25);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 26);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 27);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 28);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 29);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 30);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 31);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 32);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 33);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 34);

            migrationBuilder.DeleteData(
                table: "Generations",
                keyColumn: "Id",
                keyValue: 35);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 7);

            migrationBuilder.DeleteData(
                table: "Users",
                keyColumn: "Id",
                keyValue: 1);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 1);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 2);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 3);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 4);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 5);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 6);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 8);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 9);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 10);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 11);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 12);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 13);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 14);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 15);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 16);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 17);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 18);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 19);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 20);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 21);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 22);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 23);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 24);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 25);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 26);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 27);

            migrationBuilder.DeleteData(
                table: "Models",
                keyColumn: "Id",
                keyValue: 28);

            migrationBuilder.DeleteData(
                table: "Brands",
                keyColumn: "Id",
                keyValue: 1);

            migrationBuilder.DeleteData(
                table: "Brands",
                keyColumn: "Id",
                keyValue: 2);

            migrationBuilder.DeleteData(
                table: "Brands",
                keyColumn: "Id",
                keyValue: 3);

            migrationBuilder.DeleteData(
                table: "Brands",
                keyColumn: "Id",
                keyValue: 4);

            migrationBuilder.DeleteData(
                table: "Brands",
                keyColumn: "Id",
                keyValue: 5);

            migrationBuilder.DeleteData(
                table: "Brands",
                keyColumn: "Id",
                keyValue: 6);

            migrationBuilder.DeleteData(
                table: "Brands",
                keyColumn: "Id",
                keyValue: 7);

            migrationBuilder.DeleteData(
                table: "Brands",
                keyColumn: "Id",
                keyValue: 8);

            migrationBuilder.DeleteData(
                table: "Brands",
                keyColumn: "Id",
                keyValue: 9);

            migrationBuilder.DeleteData(
                table: "Brands",
                keyColumn: "Id",
                keyValue: 10);
        }
    }
}
<file_sep>/AutoStonks.API/PasswordHashing.cs
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.Text;

namespace AutoStonks.API
{
    public class PasswordHashing
    {
        private const int saltSize = 32;
        private const int hashSize = 32;
        private const int iterationsCount = 10000;
        public PasswordHashing()
        {
        }

        public byte[] GetSalt()
        {
            byte[] salt = new byte[saltSize];
            using (RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider())
            {
                rngCsp.GetBytes(salt);
            }
            return salt;
        }
        public byte[] GetKey(string password, byte[] salt)
        {
            Rfc2898DeriveBytes rfc2898 = new Rfc2898DeriveBytes(password, salt, iterationsCount);
            return rfc2898.GetBytes(hashSize);
        }
        public bool IsValid(string password, string saltValue, string keyValue)
        {
            byte[] salt = Encoding.Unicode.GetBytes(saltValue);
            byte[] hashedValue = GetKey(password, salt);
            if (Encoding.Unicode.GetString(hashedValue) == keyValue) return true;
            else return false;
        }
    }
}
<file_sep>/AutoStonks.API/Services/PhotoService/PhotoService.cs
﻿using AutoMapper;
using AutoStonks.API.Dtos.Photo;
using AutoStonks.API.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Services.PhotoService
{
    public class PhotoService : IPhotoService
    {
        private readonly IMapper _mapper;
        DataContext _context;
        public PhotoService(IMapper mapper, DataContext context)
        {
            _mapper = mapper;
            _context = context;
        }
        public async Task<ServiceResponse<List<GetPhotosDto>>> GetPhotos(int advertId)
        {
            ServiceResponse<List<GetPhotosDto>> serviceResponse = new ServiceResponse<List<GetPhotosDto>>();
            try
            {
                serviceResponse.Data = _context.Photos.Where(p => p.AdvertId == advertId).Select(p => _mapper.Map<GetPhotosDto>(p)).ToList();
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }
    }
}
<file_sep>/AutoStonks.API/Startup.cs
using AutoMapper;
using AutoStonks.API.Services.AdvertEquipmentService;
using AutoStonks.API.Services.AdvertService;
using AutoStonks.API.Services.BrandService;
using AutoStonks.API.Services.EquipmentService;
using AutoStonks.API.Services.GenerationService;
using AutoStonks.API.Services.ModelService;
using AutoStonks.API.Services.PaymentService;
using AutoStonks.API.Services.PhotoService;
using AutoStonks.API.Services.UserService;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.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.AddControllers();
            services.AddAutoMapper(typeof(Startup));
            services.AddScoped<IUserService, UserService>();
            services.AddScoped<IBrandService, BrandService>();
            services.AddScoped<IAdvertService, AdvertService>();
            services.AddScoped<IAdvertEquipmentService, AdvertEquipmentService>();
            services.AddScoped<IEquipmentService, EquipmentService>();
            services.AddScoped<IGenerationService, GenerationService>();
            services.AddScoped<IModelService, ModelService>();
            services.AddScoped<IPaymentService, PaymentService>();
            services.AddScoped<IPhotoService, PhotoService>();

            services.AddDbContext<DataContext>(options =>
            {
                options.UseSqlServer(Configuration.GetConnectionString("AutoStonksDb"));
            });
        }

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

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseCors(o => o.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin());

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}
<file_sep>/AutoStonks.API/Dtos/Payment/GetPaymentDto.cs
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Dtos.Payment
{
    public class GetPaymentDto
    {
        public int Id { get; set; }
        public int AdvertId { get; set; }
        public float Price { get; set; }
        public DateTime PaymentInitiation { get; set; }
        public DateTime PaymentTermination { get; set; }
        public DateTime StartDate { get; set; }
        public int DurationInDays { get; set; }
    }
}
<file_sep>/AutoStonks.API/Dtos/Model/GetModelDto.cs
﻿using AutoStonks.API.Dtos.Brand;
using AutoStonks.API.Dtos.Generation;
using AutoStonks.API.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Dtos.Model
{
    public class GetModelDto
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public List<GetGenerationDto> Generations { get; set; }
    }
}
<file_sep>/AutoStonks.API/Migrations/20210201185646_initial.cs
﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace AutoStonks.API.Migrations
{
    public partial class initial : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Brands",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Brands", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Equipment",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Equipment", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Users",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Username = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    EmailAddress = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Role = table.Column<string>(type: "nvarchar(1)", nullable: false),
                    Password = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Salt = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    LastPasswordChange = table.Column<DateTime>(type: "datetime2", nullable: false),
                    EnforcePasswordChange = table.Column<bool>(type: "bit", nullable: false),
                    IsActive = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Users", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Models",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    BrandId = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Models", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Models_Brands_BrandId",
                        column: x => x.BrandId,
                        principalTable: "Brands",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Generations",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ModelId = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Generations", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Generations_Models_ModelId",
                        column: x => x.ModelId,
                        principalTable: "Models",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Adverts",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    UserId = table.Column<int>(type: "int", nullable: false),
                    CreationDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    ModificationDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    ExpiryDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    IsPromoted = table.Column<bool>(type: "bit", nullable: false),
                    Title = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Description = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    VIN = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    FirstRegistrationDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    PlateNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    State = table.Column<int>(type: "int", nullable: false),
                    Price = table.Column<double>(type: "float", nullable: false),
                    Mileage = table.Column<int>(type: "int", nullable: false),
                    CarProductionDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    Fuel = table.Column<int>(type: "int", nullable: false),
                    Condition = table.Column<int>(type: "int", nullable: false),
                    Horsepower = table.Column<int>(type: "int", nullable: false),
                    Displacement = table.Column<int>(type: "int", nullable: false),
                    Location = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    HasBeenCrashed = table.Column<bool>(type: "bit", nullable: false),
                    TransmissionType = table.Column<int>(type: "int", nullable: false),
                    DriveType = table.Column<int>(type: "int", nullable: false),
                    VisitCount = table.Column<int>(type: "int", nullable: false),
                    GenerationId = table.Column<int>(type: "int", nullable: false),
                    PhoneNumber = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Adverts", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Adverts_Generations_GenerationId",
                        column: x => x.GenerationId,
                        principalTable: "Generations",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_Adverts_Users_UserId",
                        column: x => x.UserId,
                        principalTable: "Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "AdvertEquipment",
                columns: table => new
                {
                    AdvertId = table.Column<int>(type: "int", nullable: false),
                    EquipmentId = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AdvertEquipment", x => new { x.AdvertId, x.EquipmentId });
                    table.ForeignKey(
                        name: "FK_AdvertEquipment_Adverts_AdvertId",
                        column: x => x.AdvertId,
                        principalTable: "Adverts",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_AdvertEquipment_Equipment_EquipmentId",
                        column: x => x.EquipmentId,
                        principalTable: "Equipment",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Payments",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    AdvertId = table.Column<int>(type: "int", nullable: false),
                    Price = table.Column<float>(type: "real", nullable: false),
                    PaymentInitiation = table.Column<DateTime>(type: "datetime2", nullable: false),
                    PaymentTermination = table.Column<DateTime>(type: "datetime2", nullable: false),
                    StartDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    DurationInDays = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Payments", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Payments_Adverts_AdvertId",
                        column: x => x.AdvertId,
                        principalTable: "Adverts",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Photos",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Source = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    AdvertId = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Photos", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Photos_Adverts_AdvertId",
                        column: x => x.AdvertId,
                        principalTable: "Adverts",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_AdvertEquipment_EquipmentId",
                table: "AdvertEquipment",
                column: "EquipmentId");

            migrationBuilder.CreateIndex(
                name: "IX_Adverts_GenerationId",
                table: "Adverts",
                column: "GenerationId");

            migrationBuilder.CreateIndex(
                name: "IX_Adverts_UserId",
                table: "Adverts",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_Generations_ModelId",
                table: "Generations",
                column: "ModelId");

            migrationBuilder.CreateIndex(
                name: "IX_Models_BrandId",
                table: "Models",
                column: "BrandId");

            migrationBuilder.CreateIndex(
                name: "IX_Payments_AdvertId",
                table: "Payments",
                column: "AdvertId");

            migrationBuilder.CreateIndex(
                name: "IX_Photos_AdvertId",
                table: "Photos",
                column: "AdvertId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "AdvertEquipment");

            migrationBuilder.DropTable(
                name: "Payments");

            migrationBuilder.DropTable(
                name: "Photos");

            migrationBuilder.DropTable(
                name: "Equipment");

            migrationBuilder.DropTable(
                name: "Adverts");

            migrationBuilder.DropTable(
                name: "Generations");

            migrationBuilder.DropTable(
                name: "Users");

            migrationBuilder.DropTable(
                name: "Models");

            migrationBuilder.DropTable(
                name: "Brands");
        }
    }
}
<file_sep>/AutoStonks.API/Dtos/Model/AddModelDto.cs
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoStonks.API.Models;

namespace AutoStonks.API.Dtos.Model
{
    public class AddModelDto
    {
        public string Name { get; set; }
        public int BrandId { get; set; }
    }
}
<file_sep>/AutoStonks.API/Services/UserService/UserService.cs
﻿using AutoMapper;
using AutoStonks.API.Dtos.User;
using AutoStonks.API.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Text;

namespace AutoStonks.API.Services.UserService
{
    public class UserService : IUserService
    {
        DataContext _context;
        private readonly IMapper _mapper;
        public UserService(IMapper mapper, DataContext context)
        {
            _mapper = mapper;
            _context = context;
        }

        public async Task<ServiceResponse<UserDto>> AddUser(AddUserDto newUser)
        {
            ServiceResponse<UserDto> serviceResponse = new ServiceResponse<UserDto>();
            User user = new User();
            PasswordHashing ph = new PasswordHashing();
            try
            {
                user = _mapper.Map<User>(newUser);
                user.Salt = Encoding.Unicode.GetString(ph.GetSalt());
                user.Password = Encoding.Unicode.GetString(ph.GetKey(user.Password, Encoding.Unicode.GetBytes(user.Salt)));
                _context.Users.Add(user);
                _context.SaveChanges();
                serviceResponse.Data = _mapper.Map<UserDto>(user);
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<DeleteUserDto>> DeleteUser(int id)
        {
            ServiceResponse<DeleteUserDto> serviceResponse = new ServiceResponse<DeleteUserDto>();
            try
            {
                User user = _context.Users.FirstOrDefault(u => u.Id == id);
                user.IsActive = false;
                _context.SaveChanges();
                serviceResponse.Data = _mapper.Map<DeleteUserDto>(user);
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<List<GetUsersDto>>> GetAllUsers()
        {
            ServiceResponse<List<GetUsersDto>> serviceResponse = new ServiceResponse<List<GetUsersDto>>();
            try
            {
                serviceResponse.Data = _context.Users.Where(u => u.IsActive != false).Select(u => _mapper.Map<GetUsersDto>(u)).ToList();
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<GetUserDto>> GetUserById(int id)
        {
            ServiceResponse<GetUserDto> serviceResponse = new ServiceResponse<GetUserDto>();
            try
            {
                serviceResponse.Data = _mapper.Map<GetUserDto>(_context.Users.FirstOrDefault(u => u.Id == id));
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<GetUserDto>> UpdateUser(UpdateUserDto updateCharacter)
        {
            ServiceResponse<GetUserDto> serviceResponse = new ServiceResponse<GetUserDto>();
            try
            {
                User user = _context.Users.FirstOrDefault(u => u.Id == updateCharacter.Id);
                user.Username = updateCharacter.Username;
                user.EmailAddress = updateCharacter.EmailAddress;
                user.Role = updateCharacter.Role;
                if (user.Password != updateCharacter.Password)
                {
                    user.Password = <PASSWORD>;
                    user.Salt = updateCharacter.Salt;
                    user.LastPasswordChange = updateCharacter.LastPasswordChange;
                    user.EnforcePasswordChange = false;
                }
                serviceResponse.Data = _mapper.Map<GetUserDto>(user);
                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<UserDto>> Login(LoginDto login)
        {
            ServiceResponse<UserDto> serviceResponse = new ServiceResponse<UserDto>();
            PasswordHashing ph = new PasswordHashing();
            User entity = new User();
            try
            {
                entity = _context.Users.First(u => u.Username == login.Username);
                if (ph.IsValid(login.Password, entity.Salt, entity.Password)) serviceResponse.Data = _mapper.Map<UserDto>(entity);
                else throw new Exception("");
                if (entity.EnforcePasswordChange == true) throw new Exception("Password should be changed!");
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = "Wrong username or password.\n";
                serviceResponse.Message += (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<UserDto>> PasswordChange(PasswordChangeDto pwdChange)
        {
            ServiceResponse<UserDto> serviceResponse = new ServiceResponse<UserDto>();
            PasswordHashing ph = new PasswordHashing();
            User entity = new User();
            try
            {
                entity = _context.Users.First(u => u.Username == pwdChange.Username);
                if (ph.IsValid(pwdChange.CurrentPassword, entity.Salt, entity.Password))
                {
                    entity.Salt = Encoding.Unicode.GetString(ph.GetSalt());
                    entity.Password = Encoding.Unicode.GetString(ph.GetKey(pwdChange.NewPassword, Encoding.Unicode.GetBytes(entity.Salt)));
                    entity.LastPasswordChange = DateTime.Now;
                    entity.EnforcePasswordChange = false;
                    _context.SaveChanges();
                    serviceResponse.Data = _mapper.Map<UserDto>(entity);
                }
                else throw new Exception("Wrong current password!");
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }
    }
}
<file_sep>/AutoStonks.API/Services/BrandService/IBrandService.cs
﻿using AutoStonks.API.Dtos.Brand;
using AutoStonks.API.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Services.BrandService
{
    public interface IBrandService
    {
        public Task<ServiceResponse<Brand>> AddBrand(AddBrandDto brand);
        public Task<ServiceResponse<List<Brand>>> DeleteBrand(int idBrand);
        public Task<ServiceResponse<Brand>> UpdateBrand(UpdateBrandDto brand);
        public Task<ServiceResponse<List<GetBrandDto>>> GetAll();
        public Task<ServiceResponse<GetBrandDto>> GetSpecific(int idBrand);
    }
}
<file_sep>/AutoStonks.API/Services/AdvertEquipmentService/IAdvertEquipmentService.cs
﻿using AutoStonks.API.Dtos.AdvertEquipment;
using AutoStonks.API.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Services.AdvertEquipmentService
{
    public interface IAdvertEquipmentService
    {
        public Task<ServiceResponse<List<AdvertEquipment>>> AddAdvert(List<AddAdvertEquipmentDto> newConnection);
    }
}
<file_sep>/AutoStonks.API/Controllers/EquipmentController.cs
﻿using AutoStonks.API.Dtos.Equipment;
using AutoStonks.API.Models;
using AutoStonks.API.Services.EquipmentService;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class EquipmentController : ControllerBase
    {
        private readonly IEquipmentService _equipmentService;
        public EquipmentController(IEquipmentService equipmentService)
        {
            _equipmentService = equipmentService;
        }

        [HttpGet]
        public async Task<IActionResult> GetAll()
        {
            ServiceResponse<List<GetEquipmentDto>> response = await _equipmentService.GetEquipment();
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
    }
}
<file_sep>/AutoStonks.API/Controllers/AdvertController.cs
﻿using AutoStonks.API.Dtos.Advert;
using AutoStonks.API.Dtos.Payment;
using AutoStonks.API.Models;
using AutoStonks.API.Services.AdvertService;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class AdvertController : Controller
    {
        private readonly IAdvertService _advertService;
        public AdvertController(IAdvertService advertService)
        {
            _advertService = advertService;
        }
        [HttpGet("GetActiveBasic")]
        public async Task<IActionResult> GetAllActiveBasicInfo()
        {
            ServiceResponse<List<GetAdvertBasicInfoDto>> response = await _advertService.GetAllActiveBasicInfo();
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
        [HttpGet("GetActivePremium")]
        public async Task<IActionResult> GetAllActivePremiumInfo()
        {
            ServiceResponse<List<GetAdvertBasicInfoDto>> response = await _advertService.GetAllActivePremiumInfo();
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
        [HttpGet("GetInactive")]
        public async Task<IActionResult> GetAllInactive()
        {
            ServiceResponse<List<GetAdvertBasicInfoDto>> response = await _advertService.GetAllInactive();
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
        [HttpGet("GetBasicInfo={idAdvert}")]
        public async Task<IActionResult> GetSpecificBasicInfo(int idAdvert)
        {
            ServiceResponse<GetAdvertBasicInfoDto> response = await _advertService.GetSpecificBasicInfo(idAdvert);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
        [HttpGet("GetFullInfo={idAdvert}")]
        public async Task<IActionResult> GetSpecificFullInfo(int idAdvert)
        {
            ServiceResponse<GetAdvertFullInfoDto> response = await _advertService.GetSpecificFullInfo(idAdvert);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
        [HttpGet("Query")]
        public async Task<IActionResult> Query([FromQuery] QueryAdvertDto queryAdvertDto)
        {
            ServiceResponse<List<GetAdvertBasicInfoDto>> response = await _advertService.GetAdvertsMatchingToQuery(queryAdvertDto);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
        [HttpPost]
        public async Task<IActionResult> AddAdvert(AddPaymentDto newAdvert)
        {
            ServiceResponse<GetPaymentDto> response = await _advertService.AddAdvert(newAdvert);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
        [HttpDelete("{idAdvert}")]
        public async Task<IActionResult> DeleteBrand(int idAdvert)
        {
            ServiceResponse<List<Advert>> response = await _advertService.DeleteAdvert(idAdvert);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
        [HttpPut]
        public async Task<IActionResult> UpdateAdvert(UpdateAdvertDto advert)
        {
            ServiceResponse<string> response = await _advertService.UpdateAdvert(advert);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
    }
}
<file_sep>/AutoStonks.API/Services/GenerationService/GenerationService.cs
﻿using AutoMapper;
using AutoStonks.API.Dtos.Generation;
using AutoStonks.API.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Services.GenerationService
{
    public class GenerationService : IGenerationService
    {
        DataContext _context;
        private readonly IMapper _mapper;
        public GenerationService(IMapper mapper, DataContext context)
        {
            _mapper = mapper;
            _context = context;
        }

        public async Task<ServiceResponse<Generation>> AddGeneration(AddGenerationDto newGeneration)
        {
            ServiceResponse<Generation> serviceResponse = new ServiceResponse<Generation>();
            try
            {
                var entity = _mapper.Map<Generation>(newGeneration);
                _context.Generations.Add(entity);
                _context.SaveChanges();
                serviceResponse.Data = entity;
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<List<GetGenerationDto>>> GetAll()
        {
            ServiceResponse<List<GetGenerationDto>> serviceResponse = new ServiceResponse<List<GetGenerationDto>>();
            try
            {
                serviceResponse.Data = _context.Generations.Select(g => _mapper.Map<GetGenerationDto>(g)).ToList();
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<GetGenerationDto>> GetSpecific(int idGeneration)
        {
            ServiceResponse<GetGenerationDto> serviceResponse = new ServiceResponse<GetGenerationDto>();
            try
            {
                var temp = _context.Generations.FirstOrDefault(g => g.Id == idGeneration);
                serviceResponse.Data = _mapper.Map<GetGenerationDto>(temp);
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<Generation>> Update(UpdateGenerationDto updateGeneration)
        {
            ServiceResponse<Generation> serviceResponse = new ServiceResponse<Generation>();
            try
            {
                var updatedGeneration = _context.Generations.FirstOrDefault(m => m.Id == updateGeneration.Id);
                updatedGeneration.Name = updatedGeneration.Name;
                _context.SaveChanges();
                serviceResponse.Data = updatedGeneration;
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<List<Generation>>> Delete(int idGeneration)
        {
            ServiceResponse<List<Generation>> serviceResponse = new ServiceResponse<List<Generation>>();
            try
            {
                var toDelete = _context.Generations.FirstOrDefault(g => g.Id == idGeneration);
                _context.Generations.Remove(toDelete);
                _context.SaveChanges();
                serviceResponse.Data = _context.Generations.ToList();
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }
    }
}

<file_sep>/AutoStonks.API/Dtos/Payment/UpdatePaymentDto.cs
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Dtos.Payment
{
    public class UpdatePaymentDto
    {
        public int Id { get; set; }
        public bool isTerminated { get; set; }
    }
}
<file_sep>/AutoStonks.API/Services/AdvertService/IAdvertService.cs
﻿using AutoStonks.API.Dtos.Advert;
using AutoStonks.API.Dtos.Payment;
using AutoStonks.API.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Services.AdvertService
{
    public interface IAdvertService
    {
        public Task<ServiceResponse<GetPaymentDto>> AddAdvert(AddPaymentDto newAdvert);
        public Task<ServiceResponse<List<Advert>>> DeleteAdvert(int idAdvert);
        public Task<ServiceResponse<string>> UpdateAdvert(UpdateAdvertDto advert);
        public Task<ServiceResponse<List<GetAdvertBasicInfoDto>>> GetAllActiveBasicInfo();
        public Task<ServiceResponse<List<GetAdvertBasicInfoDto>>> GetAllActivePremiumInfo();
        public Task<ServiceResponse<List<GetAdvertBasicInfoDto>>> GetAllInactive();
        public Task<ServiceResponse<GetAdvertFullInfoDto>> GetSpecificFullInfo(int idAdvert);
        public Task<ServiceResponse<GetAdvertBasicInfoDto>> GetSpecificBasicInfo(int idAdvert);
        public Task<ServiceResponse<List<GetAdvertBasicInfoDto>>> GetAdvertsMatchingToQuery(QueryAdvertDto queryAdvertDto);
    }
}
<file_sep>/AutoStonks.API/Services/AdvertEquipmentService/AdvertEquipmentService.cs
﻿using AutoMapper;
using AutoStonks.API.Dtos.AdvertEquipment;
using AutoStonks.API.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Services.AdvertEquipmentService
{
    public class AdvertEquipmentService : IAdvertEquipmentService
    {
        DataContext _context;
        private readonly IMapper _mapper;
        public AdvertEquipmentService(IMapper mapper, DataContext context)
        {
            _mapper = mapper;
            _context = context;
        }
        public async Task<ServiceResponse<List<AdvertEquipment>>> AddAdvert(List<AddAdvertEquipmentDto> newConnection)
        {
            ServiceResponse<List<AdvertEquipment>> serviceResponse = new ServiceResponse<List<AdvertEquipment>>();
            try
            {
                _context.AdvertEquipment.AddRange(_mapper.Map<List<AdvertEquipment>>(newConnection));
                _context.SaveChanges();
                serviceResponse.Data = _context.AdvertEquipment.Where(ae => ae.AdvertId == newConnection[0].AdvertId).ToList();
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }
    }
}
<file_sep>/AutoStonks.API/Services/EquipmentService/IEquipmentService.cs
﻿using AutoStonks.API.Dtos.Equipment;
using AutoStonks.API.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Services.EquipmentService
{
    public interface IEquipmentService
    {
        public Task<ServiceResponse<List<GetEquipmentDto>>> GetEquipment();
    }
}
<file_sep>/AutoStonks.API/Services/ModelService/ModelService.cs
﻿using AutoMapper;
using AutoStonks.API.Dtos.Model;
using AutoStonks.API.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Services.ModelService
{
    public class ModelService : IModelService
    {
        DataContext _context;
        private readonly IMapper _mapper;
        public ModelService(IMapper mapper, DataContext context)
        {
            _mapper = mapper;
            _context = context;
        }
        public async Task<ServiceResponse<Model>> AddModel(AddModelDto newModel)
        {
            ServiceResponse<Model> serviceResponse = new ServiceResponse<Model>();
            try
            {
                var entity = _mapper.Map<Model>(newModel);
                _context.Models.Add(entity);
                _context.SaveChanges();
                serviceResponse.Data = entity;
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<List<Model>>> Delete(int idModel)
        {
            ServiceResponse<List<Model>> serviceResponse = new ServiceResponse<List<Model>>();
            try
            {
                var toDelete = _context.Models.FirstOrDefault(m => m.Id == idModel);
                _context.Models.Remove(toDelete);
                _context.SaveChanges();
                serviceResponse.Data = _context.Models.ToList();
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<List<GetModelDto>>> GetAll()
        {
            ServiceResponse<List<GetModelDto>> serviceResponse = new ServiceResponse<List<GetModelDto>>();
            try
            {
                serviceResponse.Data = _context.Models.Include(m => m.Generations).Select(m => _mapper.Map<GetModelDto>(m)).ToList();
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<GetModelDto>> GetSpecific(int idModel)
        {
            ServiceResponse<GetModelDto> serviceResponse = new ServiceResponse<GetModelDto>();
            try
            {
                var temp = _context.Models.Include(m => m.Generations).FirstOrDefault(m => m.Id == idModel);
                serviceResponse.Data = _mapper.Map<GetModelDto>(temp);
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }

        public async Task<ServiceResponse<Model>> Update(UpdateModelDto updateModel)
        {
            ServiceResponse<Model> serviceResponse = new ServiceResponse<Model>();
            try
            {
                var updatedModel = _context.Models.FirstOrDefault(m => m.Id == updateModel.Id);
                updatedModel.Name = updateModel.Name;
                _context.SaveChanges();
                serviceResponse.Data = updatedModel;
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }
    }
}
<file_sep>/AutoStonks.API/Controllers/UserController.cs
﻿using AutoStonks.API.Dtos.User;
using AutoStonks.API.Models;
using AutoStonks.API.Services.UserService;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class UserController : ControllerBase
    {
        private readonly IUserService _userService;
        public UserController(IUserService userService)
        {
            _userService = userService;
        }

        [HttpGet("GetAll")]
        public async Task<IActionResult> Get()
        {
            ServiceResponse<List<GetUsersDto>> response = await _userService.GetAllUsers();
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }

        [HttpGet("{id}")]
        public async Task<IActionResult> GetSpecific(int id)
        {
            ServiceResponse<GetUserDto> response = await _userService.GetUserById(id);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }

        [HttpPost]
        public async Task<IActionResult> AddUser(AddUserDto newUser)
        {
            ServiceResponse<UserDto> response = await _userService.AddUser(newUser);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }

        [HttpPut]
        public async Task<IActionResult> UpdateUser(UpdateUserDto updateUser)
        {
            ServiceResponse<GetUserDto> response = await _userService.UpdateUser(updateUser);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
        [HttpDelete("{id}")]
        public async Task<IActionResult> DeleteUser(int id)
        {
            ServiceResponse<DeleteUserDto> response = await _userService.DeleteUser(id);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
        [HttpPost("login")]
        public async Task<IActionResult> Login(LoginDto login)
        {
            ServiceResponse<UserDto> response = await _userService.Login(login);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
        [HttpPost("pwd")]
        public async Task<IActionResult> PasswordChange(PasswordChangeDto pwdChange)
        {
            ServiceResponse<UserDto> response = await _userService.PasswordChange(pwdChange);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
    }
}
<file_sep>/AutoStonks.API/Dtos/Advert/QueryAdvertDto.cs
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Dtos.Advert
{
    public class QueryAdvertDto
    {
        public enum FuelType
        {
            Diesel,
            Petrol,
            Electric,
            LPG
        }
        public enum ConditionState
        {
            Damaged,
            Undamaged
        }
        public enum DriveTypes
        {
            FWD,
            RWD,
            AWD
        }
        public enum TransmissionTypes
        {
            Sequence,
            Automatic,
            Manual
        }
        public string VIN { get; set; }
        public double MinPrice { get; set; }
        public double MaxPrice { get; set; }
        public int MinMileage { get; set; }
        public int MaxMileage { get; set; }
        public DateTime? FromCarProductionDate { get; set; }
        public DateTime? ToCarProductionDate { get; set; }
        public FuelType? Fuel { get; set; }
        public ConditionState? Condition { get; set; }
        public int MinHorsepower { get; set; }
        public int MaxHorsepower { get; set; }
        public int MinDisplacement { get; set; }
        public int MaxDisplacement { get; set; }
        public TransmissionTypes? TransmissionType { get; set; }
        public DriveTypes? DriveType { get; set; }
        public string BrandName { get; set; }
        public string ModelName { get; set; }
        public string GenerationName { get; set; }
    }
}
<file_sep>/AutoStonks.API/Controllers/ModelController.cs
﻿using AutoStonks.API.Dtos.Model;
using AutoStonks.API.Models;
using AutoStonks.API.Services.ModelService;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class ModelController : Controller
    {
        private readonly IModelService _modelService;
        public ModelController(IModelService modelService)
        {
            _modelService = modelService;
        }
        [HttpGet]
        public async Task<IActionResult> Get()
        {
            ServiceResponse<List<GetModelDto>> response = await _modelService.GetAll();
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
        [HttpGet("{idModel}")]
        public async Task<IActionResult> GetSpecific(int idModel)
        {
            ServiceResponse<GetModelDto> response = await _modelService.GetSpecific(idModel);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
        [HttpPost]
        public async Task<IActionResult> AddModel(AddModelDto newModel)
        {
            ServiceResponse<Model> response = await _modelService.AddModel(newModel);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }

        [HttpDelete("{idModel}")]
        public async Task<IActionResult> DeleteModel(int idModel)
        {
            ServiceResponse<List<Model>> response = await _modelService.Delete(idModel);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }

        [HttpPut]
        public async Task<IActionResult> UpdateModel(UpdateModelDto updateModel)
        {
            ServiceResponse<Model> response = await _modelService.Update(updateModel);
            if (response.Data == null)
            {
                return NotFound(response);
            }
            return Ok(response);
        }
    }
}
<file_sep>/AutoStonks.API/Dtos/Photo/AddPhotosDto.cs
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Dtos.Photo
{
    public class AddPhotosDto
    {
        public string Name { get; set; }
        public string Source { get; set; }
        public int AdvertId { get; set; }
    }
}
<file_sep>/AutoStonks.API/Services/PhotoService/IPhotoService.cs
﻿using AutoStonks.API.Dtos.Photo;
using AutoStonks.API.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Services.PhotoService
{
    public interface IPhotoService
    {
        public Task<ServiceResponse<List<GetPhotosDto>>> GetPhotos(int advertId);
    }
}
<file_sep>/AutoStonks.API/Dtos/AdvertEquipment/AddAdvertEquipmentDto.cs
﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Dtos.AdvertEquipment
{
    public class AddAdvertEquipmentDto
    {
        public int AdvertId { get; set; }
        public int EquipmentId { get; set; }
    }
}
<file_sep>/AutoStonks.API/Services/EquipmentService/EquipmentService.cs
﻿using AutoMapper;
using AutoStonks.API.Dtos.Equipment;
using AutoStonks.API.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Services.EquipmentService
{
    public class EquipmentService : IEquipmentService
    {
        private readonly IMapper _mapper;
        DataContext _context;
        public EquipmentService(IMapper mapper, DataContext context)
        {
            _mapper = mapper;
            _context = context;
        }
        public async Task<ServiceResponse<List<GetEquipmentDto>>> GetEquipment()
        {
            ServiceResponse<List<GetEquipmentDto>> serviceResponse = new ServiceResponse<List<GetEquipmentDto>>();
            try
            {
                serviceResponse.Data = _context.Equipment.ToList().Select(e => _mapper.Map<GetEquipmentDto>(e)).ToList();
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
            return serviceResponse;
        }
    }
}
<file_sep>/AutoStonks.API/AutoMapperProfile.cs
﻿using AutoMapper;
using AutoStonks.API.Dtos.Brand;
using AutoStonks.API.Dtos.User;
using AutoStonks.API.Dtos.Equipment;
using AutoStonks.API.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoStonks.API.Dtos.Model;
using AutoStonks.API.Dtos.Generation;
using AutoStonks.API.Dtos.Advert;
using AutoStonks.API.Dtos.AdvertEquipment;
using AutoStonks.API.Dtos.Payment;
using AutoStonks.API.Dtos.Photo;

namespace AutoStonks.API
{
    public class AutoMapperProfile : Profile
    {
        public AutoMapperProfile()
        {
            CreateMap<User, GetUserDto>();
            CreateMap<User, GetUsersDto>();
            CreateMap<User, DeleteUserDto>();
            CreateMap<AddUserDto, User>();
            CreateMap<UserDto, User>();
            CreateMap<User, UserDto>();
            CreateMap<GetUserDto, User>();
            CreateMap<UpdateUserDto, User>();
            CreateMap<Brand, GetBrandDto>();
            CreateMap<AddBrandDto, Brand>();
            CreateMap<UpdateBrandDto, Brand>();
            CreateMap<GetEquipmentDto, Equipment>();
            CreateMap<Equipment, GetEquipmentDto>();
            CreateMap<Model, GetModelDto>();
            CreateMap<GetModelDto, Model>();
            CreateMap<Generation, GetGenerationDto>();
            CreateMap<GetGenerationDto, Generation>();
            CreateMap<AddGenerationDto, Generation>();
            CreateMap<AddAdvertDto, Advert>();
            CreateMap<UpdateAdvertDto, Advert>();
            CreateMap<Advert, UpdateAdvertDto>();
            CreateMap<Advert, GetAdvertBasicInfoDto>();
            CreateMap<Advert, GetAdvertFullInfoDto>();
            CreateMap<List<AddAdvertEquipmentDto>, List<AdvertEquipment>>();
            CreateMap<AddAdvertEquipmentDto, AdvertEquipment>();
            CreateMap<AdvertEquipment, AddAdvertEquipmentDto>();
            CreateMap<List<AdvertEquipment>, List<AddAdvertEquipmentDto>>();
            CreateMap<AdvertEquipment, PlainAdvertEquipmentDto>();
            CreateMap<AddPaymentDto, Payment>();
            CreateMap<UpdatePaymentDto, Payment>();
            CreateMap<Payment, GetPaymentDto>();
            CreateMap<GetPaymentDto, Payment>();
            CreateMap<Generation, PlainGenerationDto>();
            CreateMap<Brand, PlainBrandDto>();
            CreateMap<Model, PlainModelDto>();
            CreateMap<PlainGenerationDto, Generation>();
            CreateMap<PlainBrandDto, Brand>();
            CreateMap<PlainModelDto, Model>();
            CreateMap<AddPhotosDto, Photo>();
            CreateMap<Photo, AddPhotosDto>();
            CreateMap<Photo, GetPhotosDto>();
            CreateMap<GetPhotosDto, Photo>();
        }
    }
}
<file_sep>/AutoStonks.API/DataContext.cs
﻿using AutoStonks.API.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API
{
    public class DataContext : DbContext
    {
        public DbSet<Advert> Adverts { get; set; }
        public DbSet<Photo> Photos { get; set; }
        public DbSet<Equipment> Equipment { get; set; }
        public DbSet<AdvertEquipment> AdvertEquipment { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<Brand> Brands { get; set; }
        public DbSet<Model> Models { get; set; }
        public DbSet<Generation> Generations { get; set; }
        public DbSet<Payment> Payments { get; set; }

        public DataContext(DbContextOptions options) : base(options)
        {
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //Many-To-Many --> AdverEquipment
            modelBuilder.Entity<AdvertEquipment>()
                .HasKey(ae => new { ae.AdvertId, ae.EquipmentId });
            modelBuilder.Entity<AdvertEquipment>()
                .HasOne(ae => ae.Advert)
                .WithMany(a => a.AdvertEquipments)
                .HasForeignKey(ae => ae.AdvertId);
            modelBuilder.Entity<AdvertEquipment>()
                .HasOne(ae => ae.Equipment)
                .WithMany(e => e.AdvertEquipments)
                .HasForeignKey(ae => ae.EquipmentId);

            modelBuilder.Seed();
        }
    }
}
<file_sep>/AutoStonks.API/Dtos/AdvertEquipment/PlainAdvertEquipmentDto.cs
﻿using AutoStonks.API.Dtos.Equipment;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoStonks.API.Dtos.AdvertEquipment
{
    public class PlainAdvertEquipmentDto
    {
        public int AdvertId { get; set; }
        public int EquipmentId { get; set; }
        public GetEquipmentDto Equipment { get; set; }
    }
}
