/
DeleteContact.cs
34 lines (31 loc) · 987 Bytes
/
DeleteContact.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Linq;
using AddressBookWithCodeFirst.Models.DB.Context;
using AddressBookWithCodeFirst.Models.DB.Entities;
namespace AddressBookWithCodeFirst.Models.Manager
{
public class DeleteContact
{
protected readonly AddressBookContext _context;
public DeleteContact()
{
_context = new AddressBookContext();
}
public string DeleteContactDetails(Guid contactId)
{
string contactCheck = "";
ContactDetail cd = _context.ContactDetails.Where(x => x.Id == contactId).Distinct().FirstOrDefault();
if (cd != null)
{
_context.ContactDetails.Remove(cd);
_context.SaveChanges();
contactCheck = "Contact Deleted !";
}
else
{
contactCheck = "There is no such !";
}
return contactCheck;
}
}
}