Пример #1
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);
            }
        }