using Microsoft.EntityFrameworkCore;
using RMuseum.DbContext;
using RMuseum.Models.FAQ;
using RSecurityBackend.Models.Generic;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace RMuseum.Services.Implementation
{
///
/// faq service implementation
///
public class FAQService : IFAQService
{
///
/// add faq category
///
///
///
public async Task> AddCategoryAsync(FAQCategory cat)
{
try
{
_context.FAQCategories.Add(cat);
await _context.SaveChangesAsync();
return new RServiceResult(cat);
}
catch (Exception exp)
{
return new RServiceResult(null, exp.ToString());
}
}
///
/// update faq cateory
///
///
///
public async Task> UpdateCategoryAsync(FAQCategory cat)
{
try
{
var dbModel = await _context.FAQCategories.Where(c => c.Id == cat.Id).SingleAsync();
dbModel.Title = cat.Title;
dbModel.CatOrder = cat.CatOrder;
dbModel.Description = cat.Description;
dbModel.Published = cat.Published;
_context.Update(dbModel);
await _context.SaveChangesAsync();
return new RServiceResult(true);
}
catch (Exception exp)
{
return new RServiceResult(false, exp.ToString());
}
}
///
/// delete faq category
///
///
///
public async Task> DeleteCategoryAsync(int id)
{
try
{
var dbModel = await _context.FAQCategories.Where(c => c.Id == id).SingleAsync();
_context.Remove(dbModel);
await _context.SaveChangesAsync();
return new RServiceResult(true);
}
catch (Exception exp)
{
return new RServiceResult(false, exp.ToString());
}
}
///
/// Database Context
///
protected readonly RMuseumDbContext _context;
///
/// constructor
///
///
public FAQService(RMuseumDbContext context)
{
_context = context;
}
}
}