Ejemplo n.º 1
0
        protected void DeleteButton_Click(object sender, System.EventArgs e)
        {
            int manufacturerId = AlwaysConvert.ToInt(ManufacturerList.SelectedValue);

            if (manufacturerId > 0)
            {
                _Manufacturer.Delete(manufacturerId);
            }
            else
            {
                _Manufacturer.Delete();
            }
            Response.Redirect("Default.aspx");
        }
Ejemplo n.º 2
0
Archivo: Basics.cs Proyecto: bazer/Modl
        public void CRUDExplicitId()
        {
            Manufacturer m1 = Modl <Manufacturer> .New(Guid.NewGuid());

            Assert.False(m1.IsModified());
            m1.Name = "BMW";
            Assert.True(m1.IsModified());
            m1.Save();
            Assert.False(m1.IsNew());
            Assert.False(m1.IsModified());

            Manufacturer m2 = Modl <Manufacturer> .Get(m1.ManufacturerID);

            AssertEqual(m1, m2);

            m2.Name = "Mercedes";
            Assert.Equal("Mercedes", m2.Name);
            m2.Save();

            Manufacturer m3 = Modl <Manufacturer> .Get(m1.ManufacturerID);

            Assert.Equal("Mercedes", m3.Name);
            m3.Delete();
            Assert.True(m3.IsDeleted());
            Assert.Throws <NotFoundException>(() => Modl <Manufacturer> .Get(m1.ManufacturerID));
        }
        public ActionResult Delete(int ID)
        {
            Manufacturer p = new Manufacturer();

            p.ManufacturerID = ID;
            p.Delete();
            return(RedirectToAction("ShowAll"));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Handles the Click event of the lbDelete control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="T:System.Web.UI.WebControls.CommandEventArgs"/> instance containing the event data.</param>
 protected void lbDelete_Click(object sender, CommandEventArgs e)
 {
     try {
         Manufacturer manufacturer;
         int          manufacturerId = 0;
         int.TryParse(e.CommandArgument.ToString(), out manufacturerId);
         if (manufacturerId > 0)
         {
             manufacturer = new Manufacturer(manufacturerId);
             ProductCollection productCollection = new ProductCollection().Where(Product.Columns.ManufacturerId, Comparison.Equals, manufacturerId).Load();
             if (productCollection.Count > 0)
             {
                 Master.MessageCenter.DisplayFailureMessage(string.Format(LocalizationUtility.GetText("lblUnableToDeleteManufacturers"), manufacturer.Name));
             }
             else
             {
                 Manufacturer.Delete(manufacturerId);
                 LoadManufacturers();
                 Master.MessageCenter.DisplaySuccessMessage(LocalizationUtility.GetText("lblManufacturerDeleted"));
             }
         }
     }
     catch (HttpException) {
         try {
             if (dgManufacturers.PageCount > 1)
             {
                 dgManufacturers.CurrentPageIndex = dgManufacturers.CurrentPageIndex - 1;
             }
             else
             {
                 dgManufacturers.CurrentPageIndex = 0;
             }
             dgManufacturers.DataBind();
             Master.MessageCenter.DisplaySuccessMessage(LocalizationUtility.GetText("lblManufacturerDeleted"));
         }
         catch (Exception exe) {
             Logger.Error(typeof(manufacturers).Name + ".lbDelete_Click", exe);
             Master.MessageCenter.DisplayCriticalMessage(LocalizationUtility.GetCriticalMessageText(exe.Message));
         }
     }
     catch (Exception ex) {
         Logger.Error(typeof(manufacturers).Name + ".lbDelete_Click", ex);
         Master.MessageCenter.DisplayCriticalMessage(ex.Message);
     }
 }
Ejemplo n.º 5
0
        internal void DeleteItem()
        {
            if (grdDataView.SelectedRowsCount <= 0)
            {
                MessageBox.Show("You must select the row you want to delete.",
                                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (MessageBox.Show("Are you sure you want to delete the selected record?",
                                Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.No)
            {
                return;
            }

            // Get the current row
            int[] rows = grdDataView.GetSelectedRows();
            ORMIdentifiableEntity row = grdDataView.GetRow(rows[0]) as ORMIdentifiableEntity;

            if (row == null)
            {
                return;
            }

            if (this.CurrentFileType != FileType.Unknown)
            {
                switch (this.CurrentFileType)
                {
                case FileType.Categories:
                    Category.Delete(row.ID);
                    break;

                case FileType.Manufacturers:
                    Manufacturer.Delete(row.ID);
                    break;

                case FileType.Stores:
                    Store.Delete(row.ID);
                    break;

                case FileType.Gauges:
                    Gauge.Delete(row.ID);
                    break;

                case FileType.Decoders:
                    TrainDecoder.Delete(row.ID);
                    break;

                case FileType.RailwayCompanies:
                    Company.Delete(row.ID);
                    break;

                default:
                    break;
                }
            }
            else if (this.CurrentCategory != null)
            {
                Train.Delete(row.ID);
            }

            this.Refresh();
        }