public ActionResult Edit(long lContactInfoID) { ContactInfoRepository objContactInfoRepository = new ContactInfoRepository(); ContactInfoData objContactInfoData = objContactInfoRepository.GetContactInfo(lContactInfoID); return(View(objContactInfoData)); }
public UpdateResponse Update(UpdateRequest objUpdateRequest) { UpdateResponse objUpdateResponse = new UpdateResponse(); ContactInfoRepository objContactInfoRepository = new ContactInfoRepository(); try { #region [Validation] bool bolCheckSign = Utility.CheckSHA(objUpdateRequest.Sign.Trim(), GetSign(objUpdateRequest, ApiSignKey)); if (!bolCheckSign) { objUpdateResponse.Result = $"{MsgFail} : Sign Validate Error"; return(objUpdateResponse); } #endregion #region [Logic] ContactInfoData objContactInfoData = objContactInfoRepository.GetContactInfo(Convert.ToInt64(objUpdateRequest.ContactInfoID)); if (null == objContactInfoData) { objUpdateResponse.Result = $"{MsgFail} : No Data"; } else { objContactInfoData.Name = objUpdateRequest.Name.Trim(); objContactInfoData.Nickname = (!string.IsNullOrWhiteSpace(objUpdateRequest.Nickname) ? objUpdateRequest.Nickname.Trim() : null); objContactInfoData.Gender = (ContactInfoData.EnumGender?)objUpdateRequest.Gender; objContactInfoData.Age = objUpdateRequest.Age; objContactInfoData.PhoneNo = objUpdateRequest.PhoneNo.Trim(); objContactInfoData.Address = objUpdateRequest.Address.Trim(); bool bolUpdateResult = objContactInfoRepository.UpdateContactInfo(objContactInfoData); if (bolUpdateResult) { objUpdateResponse.Result = MsgSuccess; objUpdateResponse.Data = objContactInfoData; objUpdateResponse.Sign = GetSign(objUpdateResponse, ApiSignKey); } else { objUpdateResponse.Result = $"{MsgFail} : Update Data Error"; } } return(objUpdateResponse); #endregion } catch (Exception ex) { #region [Exception] objUpdateResponse.Result = $"{MsgException} : {ex.Message}"; return(objUpdateResponse); #endregion } }
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()); } }
public ActionResult Edit(long lContactInfoID, FormCollection objFormCollection) { try { ContactInfoRepository objContactInfoRepository = new ContactInfoRepository(); ContactInfoData objContactInfoData = objContactInfoRepository.GetContactInfo(lContactInfoID); if (null != objContactInfoData && TryUpdateModel <ContactInfoData>(objContactInfoData, "", objFormCollection.AllKeys, new string[] { "ContactInfoID", "CreateTime", "UpdateTime" })) { objContactInfoRepository.UpdateContactInfo(objContactInfoData); return(RedirectToAction("Index")); } else { ModelState.AddModelError("UpdateError", "更新失敗!"); return(View(objContactInfoData)); } } catch { ModelState.AddModelError("UpdateError", "更新失敗!"); return(View()); } }