Exemplo n.º 1
0
        public async Task <object> Delete(JObject body)
        {
            try
            {
                DetailPanduan        detailPanduanRequest  = body.Value <JObject>("DetailPanduan").ToObject <DetailPanduan>();
                List <DetailPanduan> detailPanduanResponse = await detailPanduanService.GetWithParam(detailPanduanRequest);

                if (detailPanduanResponse == null || (detailPanduanResponse != null && detailPanduanResponse.Count == 0))
                {
                    throw new NotFoundException("Data tidak ditemukan, tidak dapat delete");
                }
                ExecuteResult result = await detailPanduanService.Delete(detailPanduanRequest);

                if (result.ReturnVariable <= 0)
                {
                    throw new InternalServerErrorException("An error has occured");
                }
                return(new
                {
                    Status = Models.APIResult.ResultSuccessStatus,
                    ReturnValue = result.ReturnVariable
                });
            }
            catch (NotFoundException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new InternalServerErrorException(e.Message);
            }
        }
Exemplo n.º 2
0
        public async Task <object> Insert(JObject body)
        {
            try
            {
                DetailPanduan        detailPanduanRequest  = body.Value <JObject>("DetailPanduan").ToObject <DetailPanduan>();
                List <DetailPanduan> detailPanduanResponse = await detailPanduanService.GetWithParam(detailPanduanRequest);

                if (detailPanduanResponse != null && detailPanduanResponse.Count > 0)
                {
                    throw new NotPermittedException("Data yang sama telah tercatat, tidak dapat insert");
                }
                ExecuteResult result = await detailPanduanService.Insert(detailPanduanRequest);

                if (result.ReturnVariable <= 0)
                {
                    throw new InternalServerErrorException("An error has occured");
                }
                return(new
                {
                    Status = Models.APIResult.ResultSuccessStatus,
                    ReturnValue = result.ReturnVariable
                });
            }
            catch (NotPermittedException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new InternalServerErrorException(e.Message);
            }
        }
        public async Task <List <DetailPanduan> > GetWithParam(DetailPanduan detailPanduan)
        {
            var Param = new SqlParameter[] {
                new SqlParameter("@IdPanduan", detailPanduan.IdPanduan),
                new SqlParameter("@IdBahan", detailPanduan.IdBahan)
            };

            return((await detailPanduanRepository.ExecSPToListAsync("DetailPanduan_GetWithParam @IdPanduan, @IdBahan ", Param)).ToList());
        }
        public async Task <ExecuteResult> Delete(DetailPanduan detailPanduan)
        {
            ExecuteResult          ReturnValue = new ExecuteResult();
            List <StoredProcedure> Data        = new List <StoredProcedure>();

            Data.Add(new StoredProcedure
            {
                SPName   = "DetailPanduan_Delete @IdPanduan, @IdBahan",
                SQLParam = new SqlParameter[]
                {
                    new SqlParameter("@IdPanduan", detailPanduan.IdPanduan),
                    new SqlParameter("@IdBahan", detailPanduan.IdBahan),
                }
            });

            ReturnValue = await detailPanduanRepository.ExecMultipleSPWithTransaction(Data);

            return(ReturnValue);
        }
        public async Task <int> Insert(DetailPanduan detailPanduan)
        {
            HttpClient client = new APICall.HttpClientBuilder()
                                .SetBaseURL(ConfigurationManager.AppSettings["API_BASE_URL"])
                                .SetMediaTypeWithQualityHeaderValue(APICall.APPLICATIONJSON)
                                .Build();

            Dictionary <string, dynamic> Body = new Dictionary <string, dynamic>();

            Body.Add("DetailPanduan", detailPanduan);

            var result = (await new APICall().Execute($"DetailPanduan/Insert", client, HttpMethod.Post, Body)).Data.ToString();

            if (result.GetStatusCode() == 200)
            {
                JObject jObj           = JObject.Parse(result);
                string  ReturnValueStr = jObj.SelectToken("ReturnValue").ToString();
                int     status         = JsonConvert.DeserializeObject <int>(ReturnValueStr);
                return(status);
            }
            string errMsg = result.GetStatusCode() + " " + result.GetStatusMessage() + " : " + result.GetMessage();

            throw new Exception(errMsg);
        }