Exemple #1
0
        public async Task <object> Update(JObject body)
        {
            try
            {
                Bahan bahanRequest  = body.Value <JObject>("Bahan").ToObject <Bahan>();
                Bahan bahanResponse = await bahanService.GetById(bahanRequest.IdBahan);

                if (bahanResponse == null)
                {
                    throw new NotFoundException("Bahan dengan ID tersebut tidak ditemukan");
                }
                ExecuteResult result = await bahanService.InsertUpdate(bahanRequest);

                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);
            }
        }
Exemple #2
0
        public async Task <object> Insert(JObject body)
        {
            try
            {
                Bahan        bahanRequest = body.Value <JObject>("Bahan").ToObject <Bahan>();
                List <Bahan> listAllBahan = await bahanService.GetAllBahan();

                if (listAllBahan.Any(x => x.NamaBahan.ToLower().Trim() == bahanRequest.NamaBahan.ToLower().Trim()))
                {
                    throw new NotPermittedException("Nama bahan yang sama sudah tersedia");
                }
                ExecuteResult result = await bahanService.InsertUpdate(bahanRequest);

                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);
            }
        }
Exemple #3
0
        public async Task <ActionResult> SelectBahanToEdit(int IdBahan)
        {
            string NamaBahan       = "";
            int    IdKategoriBahan = 0;

            if (IdBahan != 0)
            {
                Bahan bahan = await bahanService.GetById(IdBahan);

                NamaBahan       = bahan.NamaBahan;
                IdKategoriBahan = bahan.IdKategoriBahan;
            }
            return(Json(new { id = IdBahan, name = NamaBahan, idKategori = IdKategoriBahan }));
        }
Exemple #4
0
        public async Task <object> GetById(int id)
        {
            try
            {
                Bahan bahan = await bahanService.GetById(id);

                return(new
                {
                    Status = Models.APIResult.ResultSuccessStatus,
                    Bahan = bahan
                });
            }
            catch (Exception e)
            {
                throw new InternalServerErrorException(e.Message);
            }
        }
        public async Task <Bahan> GetById(int id)
        {
            HttpClient client = new APICall.HttpClientBuilder()
                                .SetBaseURL(ConfigurationManager.AppSettings["API_BASE_URL"])
                                .SetMediaTypeWithQualityHeaderValue(APICall.APPLICATIONJSON)
                                .Build();

            var result = (await new APICall().Execute($"Bahan/{id}", client, HttpMethod.Get)).Data.ToString();

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

            throw new Exception(errMsg);
        }
Exemple #6
0
        public async Task <ExecuteResult> InsertUpdate(Bahan bahan)
        {
            ExecuteResult          ReturnValue = new ExecuteResult();
            List <StoredProcedure> Data        = new List <StoredProcedure>();

            Data.Add(new StoredProcedure
            {
                SPName   = "Bahan_InsertUpdate @IdBahan, @NamaBahan, @IdKategoriBahan",
                SQLParam = new SqlParameter[]
                {
                    new SqlParameter("@IdBahan", bahan.IdBahan),
                    new SqlParameter("@NamaBahan", bahan.NamaBahan),
                    new SqlParameter("@IdKategoriBahan", bahan.IdKategoriBahan)
                }
            });

            ReturnValue = await bahanRepository.ExecMultipleSPWithTransaction(Data);

            return(ReturnValue);
        }
        public async Task <int> Insert(Bahan bahan)
        {
            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("Bahan", bahan);

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

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

            throw new Exception(errMsg);
        }