示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("id,kode_barang,nama_barang,harga_beli,harga_jual,tipe,created_by,created_date")] barang barang)
        {
            if (id != barang.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(barang);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!barangExists(barang.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(barang));
        }
示例#2
0
        public ActionResult AddBarang(barang model)
        {
            barang obj = new barang();

            obj.id          = model.id;
            obj.nama_barang = model.nama_barang;
            obj.jumlah      = model.jumlah;
            obj.harga       = model.harga;
            obj.deskripsi   = model.deskripsi;
            obj.active      = model.active;
            obj.gambar      = model.gambar;
            obj.created_at  = DateTime.Now;

            if (model.id == 0)
            {
                dbModel.barangs.Add(obj);
                dbModel.SaveChanges();
            }
            else
            {
                model.update_at          = DateTime.Now;
                dbModel.Entry(obj).State = EntityState.Modified;
                dbModel.SaveChanges();
            }

            var list = dbModel.barangs.ToList();

            return(View("ListBarang", list));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("id,kode_barang,nama_barang,harga_beli,harga_jual,tipe,created_by,created_date")] barang barang)
        {
            if (ModelState.IsValid)
            {
                _context.Add(barang);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(barang));
        }
        public ActionResult Create(FormCollection fc)
        {
            barang b = new barang();

            b.nama_barang  = fc["nama_barang"];
            b.harga_barang = Convert.ToInt32(fc["harga_barang"]);
            b.total_barang = Convert.ToInt32(fc["total_barang"]);
            context.Create(b);
            TempData["msg"] = "Inserted";
            return(View());
        }
        public ActionResult Edit(int id, FormCollection fc)
        {
            barang b = new barang();

            b.kode_barang  = id;
            b.nama_barang  = fc["nama_barang"];
            b.harga_barang = Convert.ToInt32(fc["harga_barang"]);
            b.total_barang = Convert.ToInt32(fc["total_barang"]);
            context.Edit(b);
            TempData["msg"] = "Updated";
            return(RedirectToAction("Index"));
        }
        public void Create(barang b)
        {
            SqlCommand command = new SqlCommand("SP_Barang_Add", con);

            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.AddWithValue("@nama_barang", b.nama_barang);
            command.Parameters.AddWithValue("@harga_barang", b.harga_barang);
            command.Parameters.AddWithValue("@total_barang", b.total_barang);
            con.Open();
            command.ExecuteNonQuery();
            con.Close();
        }
示例#7
0
 // POST api/values
 public HttpResponseMessage Post([FromBody] barang barang)
 {
     try
     {
         using (apiEntities apiEntities = new apiEntities())
         {
             apiEntities.barangs.Add(barang);
             apiEntities.SaveChanges();
             var           javaScriptSerializer = new JavaScriptSerializer();
             Helper.Status status = new Helper.Status()
             {
                 status = "Success"
             };
             var result = javaScriptSerializer.Serialize(status);
             return(new HttpResponseMessage()
             {
                 Content = new StringContent(result, System.Text.Encoding.UTF8, "application/json")
             });
         }
     } catch (Exception e)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
     }
 }
示例#8
0
 // GET: Barangs
 public ActionResult Barang(barang objek)
 {
     return(View(objek));
 }