private void DoUpdate()
        {
            int id   = ParseInt(TxtComodityNo.Text);
            var data = new comoditytbl
            {
                comodityNo   = id,
                comodityName = TxtComodityName.Text,
                derivativeTo = ParseInt(TxtDerivativeTo.SelectedValue),
                description  = TxtDescription.Text,
                modBy        = currentUser,
                modDate      = DatetimeHelper.GetDatetimeNow()
            };

            var ret = comodityControl.UpdateData(id.ToString(), data);

            if (ret.Result)
            {
                ClearFields();
                SetLayout(ModeForm.ViewData);
                Alert("Data berhasil diubah");
            }
            else
            {
                Alert("Gagal mengubah data");
            }
        }
        public async Task <bool> UpdateData(string id, comoditytbl obj)
        {
            try
            {
                if (id != obj.comodityNo.ToString())
                {
                    return(false);
                }

                using (var context = new smlpobDB())
                {
                    context.comoditytbls.Attach(obj);
                    context.Entry(obj).Property(x => x.comodityName).IsModified = true;
                    context.Entry(obj).Property(x => x.derivativeTo).IsModified = true;
                    context.Entry(obj).Property(x => x.description).IsModified  = true;
                    context.Entry(obj).Property(x => x.modBy).IsModified        = true;
                    context.Entry(obj).Property(x => x.modDate).IsModified      = true;
                    await context.SaveChangesAsync();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogHelpers.source  = this.GetType().Name;
                LogHelpers.message = ex.Message;
                LogHelpers.user    = "";
                LogHelpers.WriteLog();
            }

            return(false);
        }
 private void BtnSubmit_Click(object sender, EventArgs e)
 {
     try
     {
         //update
         if (!string.IsNullOrEmpty(TxtID.Value))
         {
             var IDS     = int.Parse(TxtID.Value);
             var NewItem = (from x in context.comoditytbls
                            where x.comodityNo == IDS
                            select x).FirstOrDefault();
             NewItem.modBy        = User.Identity.Name;
             NewItem.modDate      = DateTime.Now;
             NewItem.comodityName = TxtComodityName.Text;
             NewItem.derivativeTo = Convert.ToInt32(DDDerivative.SelectedValue);
             NewItem.description  = TxtDescription.Text;
         }
         else //add new
         {
             var NewItem = new comoditytbl()
             {
             };
             NewItem.creaBy       = "test";
             NewItem.creaDate     = DateTime.Now;
             NewItem.comodityName = TxtComodityName.Text;
             NewItem.derivativeTo = Convert.ToInt32(DDDerivative.SelectedValue);
             NewItem.description  = TxtDescription.Text;
             context.comoditytbls.Add(NewItem);
         }
         context.SaveChanges();
         PanelGrid.Visible  = true;
         PanelInput.Visible = false;
         RefreshGrid();
     }
     catch (Exception ex)
     {
         TxtStatus.Text = "gagal save --> " + ex.Message;
     }
 }
        public async Task <bool> AddData(comoditytbl obj)
        {
            try
            {
                using (var context = new smlpobDB())
                {
                    context.comoditytbls.Add(obj);
                    await context.SaveChangesAsync();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogHelpers.source  = this.GetType().Name;
                LogHelpers.message = ex.Message;
                LogHelpers.user    = "";
                LogHelpers.WriteLog();
            }

            return(false);
        }
        private void DoSave()
        {
            var data = new comoditytbl
            {
                comodityName = TxtComodityName.Text,
                derivativeTo = ParseInt(TxtDerivativeTo.SelectedValue),
                description  = TxtDescription.Text,
                creaBy       = currentUser,
                creaDate     = DatetimeHelper.GetDatetimeNow()
            };

            var ret = comodityControl.AddData(data);

            if (ret.Result)
            {
                ClearFields();
                SetLayout(ModeForm.ViewData);
                Alert("data berhasil disimpan");
            }
            else
            {
                Alert("Gagal menyimpan data");
            }
        }