public JsonResultEntity Create([FromBody] PromoEntity promoEntity) { PromoBL promoBL = new PromoBL(); JsonResultEntity response = new JsonResultEntity(); try { var result = promoBL.Create(promoEntity); if (result.HasWarning()) { response.Message = String.Join(",", result.Warning); return(response); } response.Success = true; response.Data = result.Value; } catch (Exception ex) { response.Message = ex.Message; LoggerHelper.Error(ex); } return(response); }
public PromoEntity Create(PromoEntity promoEntity) { var query = @"INSERT INTO ""Promo""(""Title"",""Description"",""StartDate"",""StartTime"",""EndDate"",""EndTime"",""Tag"",""Issuer"",""Days"",""Times"",""Terms"",""Online"",""CreatedDate"",""PromoCategoryID"",""BrandID"",""Priority"",""Slug"") VALUES(@Title,@Description,@StartDate,@StartTime,@EndDate,@EndTime,@Tag,@Issuer,@Days,@Times,@Terms,@Online,@CreatedDate,@PromoCategoryID,@BrandID,@Priority,@Slug) RETURNING ""ID"";"; int id = DbConnection.Query <int>(query, promoEntity).Single(); promoEntity.ID = id; return(promoEntity); }
public int Update(PromoEntity promoEntity) { int affectedRows = 0; if (IsHaveId <PromoEntity>(promoEntity) == false) { var query = @"UPDATE ""Promo"" SET ""Title""=@Title,""Description""=@Description,""StartDate""=@StartDate,""StartTime""=@StartTime,""EndDate""=@EndDate,""EndTime""=@EndTime,""Tag""=@Tag,""Issuer""=@Issuer,""Days""=@Days,""Times""=@Times,""Terms""=@Terms,""Online""=@Online,""ModifiedDate""=@ModifiedDate,""PromoCategoryID""=@PromoCategoryID,""BrandID""=@BrandID,""Priority""=@Priority,""Slug""=@Slug WHERE ""ID""=@ID"; affectedRows = DbConnection.Execute(query, promoEntity); } return(affectedRows); }
public ResultEntity <PromoEntity> Create(PromoEntity promoEntity) { var validationResult = new ResultEntity <PromoEntity>(); promoEntity.CreatedDate = DateTime.Now; using (var promoDA = new PromoDA()) { validationResult.Value = promoDA.Create(promoEntity); } return(validationResult); }
private void btnTambah_Click(object sender, EventArgs e) { try { if (flagperintah == 1) { if (cektxt() == true) { errorProvider1.Clear(); PromoEntity promo = new PromoEntity(comboBox1.SelectedItem.ToString(), (decimal)double.Parse(edHarga.Text), edKeterangan.Text, edPromo.Text); if (ProControl.CekPromoUnik(promo.Jenis_promo) != 0) { MessageBox.Show("Maaf, data sudah ada " + ProControl.CekPromoUnik(promo.Jenis_promo), "Kesalahan", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ProControl.EntriPromo(promo.Jenis_promo, promo.Harga, promo.Keterangan, promo.Nama); cleartxt(); this.Hide(); FormPromo myParent = (FormPromo)this.Parent; myParent.enable(); } } else { if (cektxt() == true) { errorProvider1.Clear(); PromoEntity promo = new PromoEntity(comboBox1.SelectedItem.ToString(), (decimal)double.Parse(edHarga.Text), edKeterangan.Text, edPromo.Text); if (ProControl.CekPromoUnik(promo.Jenis_promo) > 1) { MessageBox.Show("Maaf, data sudah ada " + ProControl.CekPromoUnik(promo.Jenis_promo), "Kesalahan", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DialogResult dr = MessageBox.Show("Apakah Anda yakin akan mengupdate pegawai ini ?", "Pertanyaan", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { ProControl.EditPromo(promo.Jenis_promo, promo.Harga, promo.Keterangan, int.Parse(txtID.Text), promo.Nama); } cleartxt(); this.Hide(); FormPromo myParent = (FormPromo)this.Parent; myParent.EnableEdit(); } } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Kesalahan", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public ResultEntity <PromoEntity> Update(PromoEntity promoEntity) { var validationResult = new ResultEntity <PromoEntity>(); promoEntity.ModifiedDate = DateTime.Now; using (var promoDA = new PromoDA()) { var resultUpdate = promoDA.Update(promoEntity); if (resultUpdate <= 0) { validationResult.Warning.Add("Failed Updating Promo!"); return(validationResult); } validationResult.Value = promoEntity; } return(validationResult); }