예제 #1
0
        public async Task <TResponse <bool> > Update(UpdateSiteModel request)
        {
            try
            {
                var response = await HttpService.Send <bool>(BaseUrl + ApiUrl.SITE_UPDATE, request, HttpMethod.Put);

                if (response.IsSuccess)
                {
                    return(await Ok(response.Data));
                }

                return(await Fail <bool>(response.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }
예제 #2
0
        private async Task <TResponse <bool> > CanUpdate(UpdateSiteModel request)
        {
            try
            {
                var checkValidSiteCode = await ReadOnlyRepository.QueryFirstOrDefaultAsync <SiteModel>(SqlQuery.SITE_GET_BY_CODE_AND_ID, new
                {
                    request.SiteCode,
                    request.Id
                });

                if (checkValidSiteCode.IsSuccess)
                {
                    if (checkValidSiteCode.Data != null)
                    {
                        return(await Fail <bool>(ErrorEnum.SiteCodeHasExist.GetStringValue()));
                    }

                    var checkValidSiteName = await ReadOnlyRepository.QueryFirstOrDefaultAsync <SiteModel>(SqlQuery.SITE_GET_BY_NAME_AND_ID, new
                    {
                        request.SiteName,
                        request.Id
                    });

                    if (checkValidSiteName.IsSuccess)
                    {
                        if (checkValidSiteName.Data != null)
                        {
                            return(await Fail <bool>(ErrorEnum.SiteNameHasExist.GetStringValue()));
                        }

                        return(await Ok(true));
                    }
                }

                return(await Fail <bool>(checkValidSiteCode.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }
예제 #3
0
        /// <summary>
        ///     Update Site
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <TResponse <bool> > Update(int userId,
                                                     UpdateSiteModel request)
        {
            try
            {
                var canUpdate = await CanUpdate(request);

                if (canUpdate.IsSuccess)
                {
                    var result = await WriteRepository.ExecuteAsync(SqlQuery.SITE_UPDATE, new
                    {
                        request.Id,
                        request.SiteCode,
                        request.SiteName,
                        UserUpdated = userId
                    });

                    if (result.IsSuccess)
                    {
                        if (result.Data == 0)
                        {
                            return(await Fail <bool>(string.Format(ErrorEnum.SqlQueryCanNotExecute.GetStringValue(), "SITE_UPDATE")));
                        }

                        return(await Ok(true));
                    }

                    return(await Fail <bool>(result.Message));
                }

                return(await Fail <bool>(canUpdate.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }
예제 #4
0
 public async Task <ActionResult <bool> > Update(UpdateSiteModel req)
 {
     return(Ok(await _siteService.Update(UserId,
                                         req)));
 }