public DeleteResponse Delete(DeleteRequest objDeleteRequest) { DeleteResponse objDeleteResponse = new DeleteResponse(); ContactInfoRepository objContactInfoRepository = new ContactInfoRepository(); try { #region [Validation] bool bolCheckSign = Utility.CheckSHA(objDeleteRequest.Sign.Trim(), GetSign(objDeleteRequest, ApiSignKey)); if (!bolCheckSign) { objDeleteResponse.Result = $"{MsgFail} : Sign Validate Error"; return(objDeleteResponse); } #endregion #region [Logic] ContactInfoData objContactInfoData = objContactInfoRepository.GetContactInfo(Convert.ToInt64(objDeleteRequest.ContactInfoID)); if (null == objContactInfoData) { objDeleteResponse.Result = $"{MsgFail} : No Data"; } else { bool bolDeleteResult = objContactInfoRepository.DeleteContactInfo(objContactInfoData); if (bolDeleteResult) { objDeleteResponse.Result = MsgSuccess; objDeleteResponse.Sign = GetSign(objDeleteResponse, ApiSignKey); } else { objDeleteResponse.Result = $"{MsgFail} : Delete Data Error"; } } return(objDeleteResponse); #endregion } catch (Exception ex) { #region [Exception] objDeleteResponse.Result = $"{MsgException} : {ex.Message}"; return(objDeleteResponse); #endregion } }
public ActionResult Delete(long lContactInfoID, FormCollection objFormCollection) { try { ContactInfoRepository objContactInfoRepository = new ContactInfoRepository(); ContactInfoData objContactInfoData = objContactInfoRepository.GetContactInfo(lContactInfoID); if (null != objContactInfoData) { objContactInfoRepository.DeleteContactInfo(objContactInfoData); return(RedirectToAction("Index")); } else { ModelState.AddModelError("DeleteError", "刪除失敗!"); return(View(objContactInfoData)); } } catch { ModelState.AddModelError("DeleteError", "刪除失敗!"); return(View()); } }