mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-01 16:53:14 +00:00
- Replace all Contacts.Name with (FirstName + " " + LastName) pattern - Fix ContactService, Index.razor, QuotesPDF, QuotesDetails, CreateQuotes - Fix WorkOrderPDF, Viewworkorder, UserViewWordOrder, Addworkorders - Fix ViewTemplate, AddTemplate, Templates settings pages - Blazor project now builds successfully
80 lines
2.4 KiB
C#
80 lines
2.4 KiB
C#
using Data.SeaHavenIndustries;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.JSInterop;
|
|
using SeaHavenIndustries.Data.IRepository;
|
|
using System.Text.Json;
|
|
|
|
namespace SeaHavenIndustries.Data.Services
|
|
{
|
|
public class ContactService : IContactRepository
|
|
{
|
|
private readonly ApplicationDbContext _context;
|
|
|
|
public ContactService(ApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<string> AddContact(Contacts contacts)
|
|
{
|
|
_context.ChangeTracker.Clear();
|
|
try
|
|
{
|
|
var exist = _context.Contacts.Where(w => w.Id == contacts.Id).FirstOrDefault();
|
|
if (exist != null)
|
|
{
|
|
exist.FirstName = contacts.FirstName;
|
|
exist.LastName = contacts.LastName;
|
|
exist.PhoneNumber = contacts.PhoneNumber;
|
|
exist.Email = contacts.Email;
|
|
_context.Update(exist);
|
|
|
|
}
|
|
else
|
|
{
|
|
_context.Contacts.Add(contacts);
|
|
}
|
|
await _context.SaveChangesAsync();
|
|
return "success";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ex.Message;
|
|
}
|
|
}
|
|
public async Task<List<Contacts>> GetContacts()
|
|
{
|
|
var list = await _context.Contacts.ToListAsync();
|
|
return list;
|
|
}
|
|
public async Task<IQueryable<Contacts>> GetContactsiqueryable()
|
|
{
|
|
var list = _context.Contacts;
|
|
return list;
|
|
}
|
|
public async Task<Contacts> GetContactById(int id)
|
|
{
|
|
var data = await _context.Contacts.Where(w => w.Id == id).FirstOrDefaultAsync();
|
|
return data ?? new Contacts();
|
|
}
|
|
public async Task<string> DeleteContact(int id)
|
|
{
|
|
_context.ChangeTracker.Clear();
|
|
try
|
|
{
|
|
var data = await _context.Contacts.Where(w => w.Id == id).FirstOrDefaultAsync();
|
|
if (data != null)
|
|
{
|
|
_context.Contacts.Remove(data);
|
|
}
|
|
await _context.SaveChangesAsync();
|
|
return "success";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ex.Message;
|
|
}
|
|
}
|
|
}
|
|
}
|