Beispiel #1
0
        public bool DeleteContactInfo(ContactInfoData objContactInfoData, IDbTransaction objOrgTran = null)
        {
            bool bolResult = false;

            try
            {
                if (null == objOrgTran)
                {
                    using (var objConnect = GetDBConnection())
                    {
                        objConnect.Delete(objContactInfoData);
                    }
                }
                else
                {
                    GetDBConnection().Delete(objContactInfoData, objOrgTran);
                }

                bolResult = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(bolResult);
        }
        public ActionResult Edit(long lContactInfoID)
        {
            ContactInfoRepository objContactInfoRepository = new ContactInfoRepository();
            ContactInfoData       objContactInfoData       = objContactInfoRepository.GetContactInfo(lContactInfoID);

            return(View(objContactInfoData));
        }
Beispiel #3
0
        public bool AddUpdateContactInfo(ContactInfoData objContactInfoData)
        {
            bool bolResult = false;

            try
            {
                using (var objConnect = GetDBConnection())
                {
                    using (var objTran = objConnect.BeginTransaction())
                    {
                        try
                        {
                            AddContactInfo(objContactInfoData, objTran);
                            objContactInfoData.Nickname = (string.IsNullOrWhiteSpace(objContactInfoData.Nickname) ? objContactInfoData.Name : objContactInfoData.Nickname);
                            UpdateContactInfo(objContactInfoData, objTran);

                            objTran.Commit();
                            bolResult = true;
                        }
                        catch (Exception ex)
                        {
                            objTran.Rollback();
                            throw ex;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(bolResult);
        }
Beispiel #4
0
        public void SetContactData(ContactInfoData pData)
        {
            _Data = pData;

            OnPropertyChanged("Name");
            //OnPropertyChanged("ContactStateType");
        }
 public ActionResult Create_AjaxModelPost(ContactInfoData objContactInfoData)
 {
     try
     {
         if (ModelState.IsValid)
         {
             ContactInfoRepository objContactInfoRepository = new ContactInfoRepository();
             objContactInfoRepository.AddContactInfo(objContactInfoData);
             var returnData = new
             {
                 IsSuccess = true
             };
             return(Content(JsonConvert.SerializeObject(returnData), "application/json"));
         }
         else
         {
             ModelState.AddModelError("InsertError", "新增失敗!");
             var returnData = new
             {
                 IsSuccess        = false,
                 ModelStateErrors = ModelState.Where(p => p.Value.Errors.Count > 0).ToDictionary(p => p.Key, p => p.Value.Errors.Select(e => e.ErrorMessage).ToArray())
             };
             return(Content(JsonConvert.SerializeObject(returnData), "application/json"));
         }
     }
     catch (Exception ex)
     {
         var returnData = new
         {
             IsSuccess    = false,
             ExceptionMsg = ex.Message
         };
         return(Content(JsonConvert.SerializeObject(returnData), "application/json"));
     }
 }
        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 IHttpActionResult Get(long id)
        {
            QueryResponse objQueryResponse;

            if (ModelState.IsValid)
            {
                try
                {
                    ContactInfoRESTfulRepository objContactInfoRESTfulRepository = new ContactInfoRESTfulRepository();
                    ContactInfoData objContactInfoData = objContactInfoRESTfulRepository.Query(id);
                    if (null == objContactInfoData)
                    {
                        objQueryResponse = new QueryResponse()
                        {
                            Result = $"{ MsgFail } : No Data"
                        };
                    }
                    else
                    {
                        objQueryResponse = new QueryResponse()
                        {
                            Result = MsgSuccess, Data = objContactInfoData
                        };
                    }
                }
                catch (Exception ex)
                {
                    objQueryResponse = new QueryResponse()
                    {
                        Result = $"{MsgException} : {ex.Message}"
                    };
                }

                //return Ok(objQueryResponse);
            }
            else
            {
                //return BadRequest(ModelState);

                string strErrorMsg = string.Empty;
                foreach (var item in ModelState.Values)
                {
                    strErrorMsg += string.Join(",", item.Errors.Select(e => e.ErrorMessage));
                }
                objQueryResponse = new QueryResponse()
                {
                    Result = string.IsNullOrWhiteSpace(strErrorMsg) ? "Request Format Error" : strErrorMsg
                };
            }

            //轉換JSON格式回傳
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(Utility.GetJSON(objQueryResponse), Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(ResponseMessage(result));
        }
        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
            }
        }
Beispiel #9
0
        public bool Delete(ContactInfoData objContactInfoData)
        {
            bool bolResult = false;

            try
            {
                using (var db = new SqlConnection(DBConnectString))
                {
                    db.Delete <ContactInfoData>(objContactInfoData);
                }
                bolResult = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(bolResult);
        }
 public ActionResult Create(ContactInfoData objContactInfoData)
 {
     try
     {
         if (ModelState.IsValid)
         {
             ContactInfoRepository objContactInfoRepository = new ContactInfoRepository();
             objContactInfoRepository.AddContactInfo(objContactInfoData);
             return(RedirectToAction("Index"));
         }
         else
         {
             ModelState.AddModelError("InsertError", "新增失敗!");
             return(View(objContactInfoData));
         }
     }
     catch
     {
         ModelState.AddModelError("InsertError", "新增失敗!");
         return(View(objContactInfoData));
     }
 }
Beispiel #11
0
        public ContactInfoData GetContactInfo(long ContactInfoID)
        {
            ContactInfoData objContactInfoData = null;

            try
            {
                using (var objConnect = GetDBConnection())
                {
                    StringBuilder sbSQL = new StringBuilder();
                    sbSQL.AppendLine("SELECT * FROM Tbl_ContactInfo");
                    sbSQL.AppendLine("WHERE ContactInfoID=@ContactInfoID");
                    sbSQL.AppendLine("ORDER BY ContactInfoID DESC");

                    objContactInfoData = objConnect.Query <ContactInfoData>(sbSQL.ToString(), new { ContactInfoID = ContactInfoID }).FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(objContactInfoData);
        }
 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());
     }
 }
 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());
     }
 }
Beispiel #14
0
        public bool AddContactInfo(ContactInfoData objContactInfoData, IDbTransaction objOrgTran = null)
        {
            bool bolResult = false;

            try
            {
                if (null == objOrgTran)
                {
                    using (var objConnect = GetDBConnection())
                    {
                        objContactInfoData.IsEnable   = true;
                        objContactInfoData.CreateTime = DateTime.Now;

                        long?ContactInfoID = objConnect.Insert(objContactInfoData);

                        objContactInfoData.ContactInfoID = Convert.ToInt64(ContactInfoID);
                    }
                }
                else
                {
                    objContactInfoData.IsEnable   = true;
                    objContactInfoData.CreateTime = DateTime.Now;

                    long?ContactInfoID = GetDBConnection().Insert(objContactInfoData, objOrgTran);

                    objContactInfoData.ContactInfoID = Convert.ToInt64(ContactInfoID);
                }

                bolResult = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(bolResult);
        }
Beispiel #15
0
        public bool Insert(ContactInfoData objContactInfoData)
        {
            bool bolResult = false;

            try
            {
                using (var db = new SqlConnection(DBConnectString))
                {
                    objContactInfoData.IsEnable   = true;
                    objContactInfoData.CreateTime = DateTime.Now;

                    long?lContactInfoID = db.Insert <ContactInfoData>(objContactInfoData);

                    objContactInfoData.ContactInfoID = Convert.ToInt64(lContactInfoID);
                }
                bolResult = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(bolResult);
        }
Beispiel #16
0
 public void SetContactData(ContactInfoData pData)
 {
     _Data = pData;
     OnPropertyChanged("Name");
     OnPropertyChanged("_GreenDotVisibility");
 }
        public IHttpActionResult Post([FromBody] AddRequest objAddRequest)
        {
            AddResponse objAddResponse;

            if (null != objAddRequest && ModelState.IsValid)
            {
                try
                {
                    ContactInfoData objContactInfoData = new ContactInfoData();
                    objContactInfoData.Name     = objAddRequest.Name.Trim();
                    objContactInfoData.Nickname = (!string.IsNullOrWhiteSpace(objAddRequest.Nickname) ? objAddRequest.Nickname.Trim() : null);
                    objContactInfoData.Gender   = (ContactInfoData.EnumGender?)objAddRequest.Gender;
                    objContactInfoData.Age      = objAddRequest.Age;
                    objContactInfoData.PhoneNo  = objAddRequest.PhoneNo.Trim();
                    objContactInfoData.Address  = objAddRequest.Address.Trim();

                    ContactInfoRESTfulRepository objContactInfoRESTfulRepository = new ContactInfoRESTfulRepository();
                    bool bolResult = objContactInfoRESTfulRepository.Insert(objContactInfoData);
                    if (bolResult)
                    {
                        objAddResponse = new AddResponse()
                        {
                            Result = MsgSuccess, Data = objContactInfoData
                        };
                    }
                    else
                    {
                        objAddResponse = new AddResponse()
                        {
                            Result = $"{MsgFail} : Insert Data Error"
                        };
                    }
                }
                catch (Exception ex)
                {
                    objAddResponse = new AddResponse()
                    {
                        Result = $"{MsgException} : {ex.Message}"
                    };
                }

                //return Ok(objAddResponse);
            }
            else
            {
                //return BadRequest(ModelState);

                string strErrorMsg = string.Empty;
                foreach (var item in ModelState.Values)
                {
                    strErrorMsg += string.Join(",", item.Errors.Select(e => e.ErrorMessage));
                }
                objAddResponse = new AddResponse()
                {
                    Result = string.IsNullOrWhiteSpace(strErrorMsg) ? "Request Format Error" : strErrorMsg
                };
            }

            //轉換JSON格式回傳
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(Utility.GetJSON(objAddResponse), Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(ResponseMessage(result));
        }