public bool BlackListCompany(BlackList entity) { try { if (validateBlackList(entity)) { _repo.AddBlackList(entity); _repo.SaveChanges(); return true; } else { return false; } } catch (Exception ex) { ValidationDic.Clear(); ValidationDic.Add("Exception", ex.Message); return false; } }
private bool validateBlackList(BlackList entity) { bool valid = true; ValidationDic.Clear(); var results = _repo.QueryBlackList().Where(b => b.BlackListedCompanyId == entity.BlackListedCompanyId && b.CompanyId == b.CompanyId); if (results != null && results.Count() > 0) { ValidationDic.Add("BlackListedCompanyId", "company is already blacklisted"); valid = false; } return valid; }
public bool UnblackListCompany(BlackList entity) { try { if (_repo.FindBlackList(entity.CompanyId, entity.BlackListedCompanyId) != null) { _repo.DeleteBlackList(entity); _repo.SaveChanges(); return true; } else { ValidationDic.Clear(); ValidationDic.Add("Entity", "nothing to delete"); return false; } } catch (Exception ex) { ValidationDic.Clear(); ValidationDic.Add("Exception", ex.Message); return false; } }
public void DeleteBlackList(BlackList entity) { _blackLists.Remove(entity); }
public void AddBlackList(BlackList entity) { _blackLists.Add(entity); }
public HttpResponseMessage Post(HttpRequestMessage request, int companyToBlackList, string note) { int companyId = _service.GetUserProfile(_security.GetUserId(User.Identity.Name)).CompanyId; // if connected to company, delete connection ContactConnection conn = _service.GetNetworkConnection(companyId, companyToBlackList); if (conn != null) { if (!_service.RemoveNetworkConnection(conn)) { return request.CreateResponse(HttpStatusCode.InternalServerError, "cannot remove connection"); } } // if already blacklisted var existingBlackList = _service.GetBlackListItem(companyId, companyToBlackList); if (existingBlackList != null) { return request.CreateResponse(HttpStatusCode.Conflict, "already blacklisted"); } BlackList blackList = new BlackList { CompanyId = companyId, BlackListedCompanyId = companyToBlackList, BlackListDate = DateTime.Now, Notes = note }; if (_service.BlackListCompany(blackList)) { return request.CreateResponse(HttpStatusCode.NoContent); } else { return request.CreateResponse(HttpStatusCode.InternalServerError, _service.ValidationDic); } }