public void Delete(IndustrialSector sectorToDelete) { var originalIndustrialSector = Get(sectorToDelete.Id); _entities.DeleteObject(originalIndustrialSector); _entities.SaveChanges(); }
public IndustrialSector Create(IndustrialSector sectorToCreate) { _entities.AddToIndustrialSectorSet(sectorToCreate); _entities.SaveChanges(); return sectorToCreate; }
public IndustrialSector Update(IndustrialSector sectorToUpdate) { var originalIndustrialSector = Get(sectorToUpdate.Id); _entities.ApplyCurrentValues(originalIndustrialSector.EntityKey.EntitySetName, sectorToUpdate); _entities.SaveChanges(); return sectorToUpdate; }
public bool ValidateIndustrialSector(IndustrialSector sectorToValidate) { //convert null values to empty strings sectorToValidate.Sector = sectorToValidate.Sector ?? ""; if (sectorToValidate.Sector.Trim().Length == 0) _validationDictionary.AddError("Sector", "Sector is required."); return _validationDictionary.IsValid; }
public bool DeleteIndustrialSector(IndustrialSector sectorToDelete) { try { _repository.Delete(sectorToDelete); } catch { return false; } return true; }
public ActionResult Edit(IndustrialSector industrialSector) { // normaly we should have those parameters : "Edit(int id, FormCollection values)" // Then we would retrieve the existing sector from db (by his id) and then update the // fields with the form posted values.But in this specific case we can directly // pass an "IndustrialSector" instance, the binder has automatically bound the "id" // field from the request(/Sector/Edit/{id}) and the "sector" field from the form. // ... if (!_sectorService.EditIndustrialSector(industrialSector)) { return View(industrialSector); } return RedirectToAction("Index"); }
public bool EditIndustrialSector(IndustrialSector sectorToEdit) { // Validation logic if (!ValidateIndustrialSector(sectorToEdit)) return false; // Database logic try { _repository.Update(sectorToEdit); } catch { return false; } return true; }
public CreateEditSectorForm(IndustrialSector sector, bool editMode) { InitializeComponent(); _sector = sector; _editMode = editMode; _modelState = new Dictionary<string, string>(); _sectorService = new IndustrialSectorService(new SimpleModelStateWrapper(_modelState)); if (_editMode) { this.Text = "Edit Sector"; this.createEditButton.Text = "Save"; } this.sectorBindingSource.DataSource = _sector; }
/// <summary> /// Create a new IndustrialSector object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="sector">Initial value of the Sector property.</param> public static IndustrialSector CreateIndustrialSector(global::System.Int32 id, global::System.String sector) { IndustrialSector industrialSector = new IndustrialSector(); industrialSector.Id = id; industrialSector.Sector = sector; return industrialSector; }
/// <summary> /// Deprecated Method for adding a new object to the IndustrialSectorSet EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToIndustrialSectorSet(IndustrialSector industrialSector) { base.AddObject("IndustrialSectorSet", industrialSector); }
public ActionResult Delete(IndustrialSector industrialSector) { if (!_sectorService.DeleteIndustrialSector(industrialSector)) return View(industrialSector); return RedirectToAction("Index"); }