예제 #1
0
 public async Task <APIResult> Get(int id)
 {
     return(new APIResult()
     {
         Result = 0,
         Data = await cultivationQueries.GetById(id)
     });
 }
예제 #2
0
        public override async Task <int> HandleCommand(DeleteCommand request, CancellationToken cancellationToken)
        {
            var cultivation = await cultivationQueries.GetById(request.Id);

            if (cultivation == null)
            {
                throw new BusinessException("Cultivation.NotExisted");
            }
            var rs = -1;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        cultivation.IsDeleted = true;
                        cultivation           = UpdateBuild(cultivation, request.LoginSession);

                        if (await cultivationRepository.Update(cultivation) > 0)
                        {
                            rs = 0;
                        }
                    }
                    finally
                    {
                        if (rs == 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try
                            {
                                trans.Rollback();
                            }
                            catch { }
                        }
                    }
                }
            }

            return(rs);
        }
예제 #3
0
        public override async Task <int> HandleCommand(UpdateCommand request, CancellationToken cancellationToken)
        {
            if (request.Cultivation == null || request.Cultivation.Id == 0)
            {
                throw new BusinessException("Cultivation.NotExisted");
            }

            var cultivation = await cultivationQueries.GetById(request.Cultivation.Id);

            if (cultivation == null)
            {
                throw new BusinessException("Cultivation.NotExisted");
            }

            if (request.Cultivation.PlotId > 0)
            {
                var plot = await WebHelper.HttpGet <Plot>(GlobalConfiguration.APIGateWayURI,
                                                          $"{PlotUrl.ApiGet}?id={request.Cultivation.PlotId}",
                                                          request.LoginSession.AccessToken, request.LoginSession.LanguageCode);

                if (plot == null)
                {
                    throw new BusinessException("Plot.NotExisted");
                }
            }
            else
            {
                throw new BusinessException("Plot.NotExisted");
            }

            if (request.Cultivation.SeedId > 0)
            {
                var seed = await WebHelper.HttpGet <Seed>(GlobalConfiguration.APIGateWayURI,
                                                          $"{SeedUrl.ApiGet}?id={request.Cultivation.SeedId}",
                                                          request.LoginSession.AccessToken, request.LoginSession.LanguageCode);

                if (seed == null)
                {
                    throw new BusinessException("Seed.NotExisted");
                }
            }
            else
            {
                throw new BusinessException("Seed.NotExisted");
            }

            if ((request.Cultivation.MethodId ?? 0) > 0)
            {
                var method = await WebHelper.HttpGet <Method>(GlobalConfiguration.APIGateWayURI,
                                                              $"{SeedUrl.ApiGet}?id={request.Cultivation.SeedId}",
                                                              request.LoginSession.AccessToken, request.LoginSession.LanguageCode);

                if (method == null)
                {
                    throw new BusinessException("Method.NotExisted");
                }
            }
            else if (request.Cultivation.MethodId != null)
            {
                throw new BusinessException("Method.NotExisted");
            }

            var rs = -1;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        request.Cultivation.CreatedDate = cultivation.CreatedDate;
                        request.Cultivation.CreatedBy   = cultivation.CreatedBy;
                        request.Cultivation             = UpdateBuild(request.Cultivation, request.LoginSession);
                        request.Cultivation.Code        = string.IsNullOrWhiteSpace(cultivation.Code)
                            ? (await storageQueries.GenarateCodeAsync(StorageKeys.CultivationCode))
                            : cultivation.Code;

                        rs = await cultivationRepository.Update(request.Cultivation);

                        if (rs == 0)
                        {
                            return(-1);
                        }

                        rs = 0;
                    }
                    finally
                    {
                        if (rs == 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try
                            {
                                trans.Rollback();
                            }
                            catch { }
                        }
                    }
                }
            }

            return(rs);
        }