コード例 #1
0
        public async Task <IActionResult> Update(string id, [FromBody] PS_HSU_THONGTIN_TS thongtin_ts)
        {
            var userId = this.GetUserId();

            if (this.CurrentUserIsAdmin())
            {
                thongtin_ts.HSU_NGUOISUA_TTTS = userId;
                thongtin_ts.HSU_NGAYSUA_TTTS  = DateTime.Now;
            }
            else
            {
                if (!id.Equals(userId))
                {
                    return(BadRequest());
                }
            }

            var ts = _uow.PS_HSU_THONGTIN_TS_Repository.GetByCMNNAsNoTracking(id);

            if (ts.IsMapValue(thongtin_ts) && IsValidRecord(thongtin_ts).Result)
            {
                ts = thongtin_ts;
                _uow.PS_HSU_THONGTIN_TS_Repository.Update(ts);
                await _uow.SaveChangesAsync();

                return(Ok());
            }
            return(BadRequest());
        }
コード例 #2
0
        public async Task <IActionResult> UpdatePassword(string id, [FromBody] PS_HSU_THONGTIN_TS thongtin_ts)
        {
            if (this.CurrentUserIsAdmin())
            {
                return(BadRequest());
            }

            var cmnn = this.GetUserId();

            if (id.Equals(cmnn) && thongtin_ts != null)//check token with id querystring
            {
                var ts = await _uow.PS_HSU_THONGTIN_TS_Repository.GetByCMNN(cmnn);

                if (ts != null && thongtin_ts.HSU_PASSWORD_TS != null)
                {
                    if (!ts.HSU_PASSWORD_TS.Equals(thongtin_ts.HSU_PASSWORD_TS, StringComparison.InvariantCultureIgnoreCase))
                    {
                        ts.HSU_PASSWORD_TS = thongtin_ts.HSU_PASSWORD_TS;
                        _uow.PS_HSU_THONGTIN_TS_Repository.Update(ts);
                        await _uow.SaveChangesAsync();
                    }
                    return(Ok());
                }
            }
            return(BadRequest());
        }
コード例 #3
0
        private async Task <bool> IsValidRecord(PS_HSU_THONGTIN_TS thongtin_ts)
        {
            var city = await _uow.HSU_DANHMUC_Repository.IsExist_CITY(thongtin_ts.HSU_MATINHTP);

            var dist = await _uow.HSU_DANHMUC_Repository.IsExist_DISTRICT(thongtin_ts.HSU_MATINHTP, thongtin_ts.HSU_MA_QUAN_HUYEN);

            var doituong = await _uow.HSU_DANHMUC_Repository.IsExit_DOITUONG(thongtin_ts.HSU_NAM, thongtin_ts.HSU_DOITUONG_TS);

            var khuvuc = await _uow.HSU_DANHMUC_Repository.IsExist_KHUVUC(thongtin_ts.HSU_NAM, thongtin_ts.HSU_KHUVUC_TS);

            var dantoc = await _uow.HSU_DANHMUC_Repository.IsExit_DANTOC(thongtin_ts.HSU_MA_DANTOC);

            return(city && dist && doituong && khuvuc && dantoc);
        }
コード例 #4
0
 public static bool IsMapValue(this PS_HSU_THONGTIN_TS fistTS, PS_HSU_THONGTIN_TS secondTS)
 {
     // if (!fistTS.HSU_HOVACHULOT_TS.Equals(secondTS.HSU_HOVACHULOT_TS, StringComparison.InvariantCultureIgnoreCase)) return false;
     //if (!fistTS.HSU_TEN_TS.Equals(secondTS.HSU_TEN_TS, StringComparison.InvariantCultureIgnoreCase)) return false;
     if (fistTS.HSU_NAM != secondTS.HSU_NAM)
     {
         return(false);
     }
     // if (!fistTS.HSU_EMAIL.Equals(secondTS.HSU_EMAIL, StringComparison.InvariantCultureIgnoreCase)) return false;
     if (!fistTS.HSU_SOCMND.Equals(secondTS.HSU_SOCMND, StringComparison.InvariantCultureIgnoreCase))
     {
         return(false);
     }
     if (fistTS.HSU_NGAYDK_TTTS != secondTS.HSU_NGAYDK_TTTS)
     {
         return(false);
     }
     return(true);
 }
コード例 #5
0
        public async Task <IActionResult> CreateAsync([FromBody] PS_HSU_THONGTIN_TS thongtin_ts)
        {
            if (_uow.PS_HSU_THONGTIN_TS_Repository.IsExist(thongtin_ts.HSU_SOCMND, thongtin_ts.HSU_EMAIL))
            {
                return(BadRequest());
            }
            else
            {
                if (this.CurrentUserIsAdmin())
                {
                    thongtin_ts.HSU_NGUOINHAP_TTTS = this.GetUserId();
                }

                if (IsValidRecord(thongtin_ts).Result)
                {
                    _uow.PS_HSU_THONGTIN_TS_Repository.Add(thongtin_ts);
                    await _uow.SaveChangesAsync();

                    return(CreatedAtAction(nameof(CreateAsync), new { cmnn = thongtin_ts.HSU_SOCMND }, thongtin_ts));
                }
                return(BadRequest());
            }
        }