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 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()); } }