private void existingEventTypesListBox_MouseDoubleClick(object sender, MouseEventArgs e) { DialogResult res = MessageBox.Show("Do you want to delete this event type?", "Confirm deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (res == DialogResult.Yes) { EventTypeModel p = (EventTypeModel)existingEventTypesListBox.SelectedItem; //Check if this EventType is in use List <EventModel> eventModel = GlobalConfig.Connection.GetEvent_ByEventTypeId(p.Id); if (eventModel.Count > 0) { //If it is in use then tell user it cannot be delete MessageBox.Show("I am not going to delete this Event Type because it is in use", $"{ p.EventType } NOT Removed", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { //Else - delete from SQL and updated form GlobalConfig.Connection.DeleteEventTypes_ById(p.Id); existingEventTypes.Remove(p); WireUpListBox(); MessageBox.Show("This Event Type has been deleted", $"{ p.EventType } Removed", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
public void MapEventType_EntityWithNoAssociated_SomeMapped() { var entity = new EventType { Id = 1, EventGroupId = 1, EventParentId = 1, UserId = "foo", Name = "bar", Description = "baz" }; var expected = new EventTypeModel { Id = 1, EventGroupId = 1, EventParentId = 1, Name = "bar", Description = "baz" }; var actual = target.Map <EventTypeModel>(entity); Assert.AreEqual(expected.Id, actual.Id); Assert.AreEqual(expected.EventGroupId, actual.EventGroupId); Assert.AreEqual(expected.EventGroupName, actual.EventGroupName); Assert.AreEqual(expected.EventParentId, actual.EventParentId); Assert.AreEqual(expected.EventParentName, actual.EventParentName); Assert.AreEqual(expected.Name, actual.Name); Assert.AreEqual(expected.Description, actual.Description); }
private void RefreshEventTypeListViewAndKeepExistingSelections() { //Record all selected event types List <EventTypeModel> selectedEvents = new List <EventTypeModel>(); if (eventTypeCheckedListBox.SelectedItems.Count > 0) { foreach (object item in eventTypeCheckedListBox.CheckedItems) { selectedEvents.Add((EventTypeModel)item); } } //Reset eventTypesCheckListBox EventTypeSetUp(); //Reselect the event types for (int x = 0; x < eventTypeCheckedListBox.Items.Count; x++) { EventTypeModel ev = (EventTypeModel)eventTypeCheckedListBox.Items[x]; if (selectedEvents.Count(s => s.Id == ev.Id) == 1) { eventTypeCheckedListBox.SetItemChecked(x, true); } } }
public IHttpActionResult Put(int id, EventTypeModel eventTypeModel) { var result = new Result <string>(); using (var db = new jupiterEntities()) { var a = db.EventTypes.Where(x => x.TypeId == id).Select(x => x).FirstOrDefault(); if (a == null) { return(Json(DataNotFound(result))); } Type type = typeof(EventType); UpdateTable(eventTypeModel, type, a); try { db.SaveChanges(); } catch (Exception e) { result.ErrorMessage = e.Message; result.IsSuccess = false; return(Json(result)); } } return(Json(result)); }
public ActionResult AddEventType(EventTypeModel scvm) { if (ModelState.IsValid) { var existingcat = _context.Eventtypes.Where(sc => sc.Name == scvm.Type.Trim()).FirstOrDefault(); if (existingcat != null) { ModelState.AddModelError("", "This Category name exist before"); return(View(scvm)); } var cat = new EventType { Name = scvm.Type, Events = new List <Event>(), Description = scvm.Description }; _context.Eventtypes.Add(cat); _context.SaveChanges(); TempData["message"] = string.Format("{0} has been saved.", scvm.Type); return(RedirectToAction("EventTypeList")); } else { return(View(scvm)); } }
private void listBox1_DragDrop(object sender, DragEventArgs e) { EventTypeModel et = (EventTypeModel)e.Data.GetData(typeof(EventTypeModel)); listBox1.Items.Add(et); listBox1.DisplayMember = "EventType"; }
private void createEventButton_Click(object sender, EventArgs e) { if (ValidBasicInputDataInput()) { eventModel.EventName = eventNameTextBox.Text; DateTime eventDateValue = new DateTime(1900, 1, 1); DateTime.TryParse(eventDateTimeDatePicker.Value.ToShortDateString(), out eventDateValue); eventModel.EventDate = eventDateValue; eventModel.EventDescription = eventDescriptionTextBox.Text; //### set start and end date ### DateTime dt = new DateTime(); TimeSpan ts = new TimeSpan(); dt = startTimeDateTimePicker.Value; ts = dt.TimeOfDay; eventModel.StartTime = new TimeSpan(ts.Hours, ts.Minutes, 0); //This last bit removes the seconds dt = endTimeDateTimePicker.Value; ts = dt.TimeOfDay; eventModel.EndTime = new TimeSpan(ts.Hours, ts.Minutes, 0); //### set start and end date ### eventModel.MaxNumberOfGuests = (int)maxNumberOfGuestsNumericUpDown.Value; eventModel.EstimatedCost = (decimal)eventCostEstimateNumericUpDown.Value; eventModel.EventOwners = new List <EventOwnerModel>(); foreach (DataGridViewRow dgvRow in eventOwnerDataGridView.Rows) { EventOwnerModel eventOwner = new EventOwnerModel(); eventOwner.StaffId = (int)dgvRow.Cells[0].Value; eventOwner.Staff = GlobalConfig.Connection.GetStaff_ById(eventOwner.StaffId); eventOwner.CostPercentage = Convert.ToInt32(dgvRow.Cells[2].Value.ToString()); eventModel.EventOwners.Add(eventOwner); } eventModel.EventType = new List <EventTypeModel>(); foreach (object ev in eventTypeCheckedListBox.CheckedItems) { EventTypeModel eventType = new EventTypeModel(); eventType = (EventTypeModel)ev; eventModel.EventType.Add(eventType); } GlobalConfig.Connection.UpSertEvent(eventModel); RefreshAllInvitesListView(); callingForm.EventComplete(eventModel); saveEventButton.Text = "Update Event"; this.Text = "View / Edit Event"; } }
public void PopulateEventForm(EventModel model) { //This is called if the form is being updated //I need to pass an existing Event into the form and populate the fields eventModel = model; eventNameTextBox.Text = eventModel.EventName; eventDateTimeDatePicker.Value = eventModel.EventDate; startTimeDateTimePicker.Value = DateTime.Today.Add(eventModel.StartTime); endTimeDateTimePicker.Value = DateTime.Today.Add(eventModel.EndTime); //Refresh the address in the unlikely event that the address this links to has been edited eventModel.EventLocation = GlobalConfig.Connection.GetEventLocation_ByLocationId(model.EventLocationId); eventVenueTextBox.Text = eventModel.EventLocation.Venue.VenueName; eventAddressTextBox.Text = eventModel.EventLocation.VenueAddress.FullMultiLineAddress; eventDescriptionTextBox.Text = eventModel.EventDescription; maxNumberOfGuestsNumericUpDown.Value = eventModel.MaxNumberOfGuests; eventCostEstimateNumericUpDown.Value = eventModel.EstimatedCost; //Populate CheckListBox with Event Types foreach (EventTypeModel item in model.EventType) { for (int x = 0; x < eventTypeCheckedListBox.Items.Count; x++) { EventTypeModel ev = (EventTypeModel)eventTypeCheckedListBox.Items[x]; if (ev.Id == item.Id) { eventTypeCheckedListBox.SetItemChecked(x, true); } } } //Populate DataGridView with the owners List <EventOwnerModel> owners = GlobalConfig.Connection.GetEventOwners_ByEventId(model.Id); foreach (EventOwnerModel owner in owners) { int rowIndex = eventOwnerDataGridView.Rows.Add(); DataGridViewRow row = eventOwnerDataGridView.Rows[rowIndex]; row.Cells[0].Value = owner.StaffId; row.Cells[1].Value = owner.Staff.FullName; row.Cells[2].Value = owner.CostPercentage; selectableStaff.RemoveAll(x => x.Id == owner.Staff.Id); } PopulateSelectableStaffListBox(); RefreshAllInvitesListView(); saveEventButton.Text = "Update Event"; }
public AddDefaultEventTypeTODOView(EventTypeModel eventTypeModel, EventTypeToDoModel eventTypeToDoModel = null) { InitializeComponent(); DataContext = ViewModel = new AddDefaultEventTypeTODOViewModel(eventTypeModel, eventTypeToDoModel); if (eventTypeModel != null) this.Header = "Edit Default To Do"; Owner = Application.Current.MainWindow; Loaded += OnViewLoaded; }
public IActionResult Create([FromBody][CustomizeValidator(RuleSet = Constants.RuleSetNameForInsert)] EventTypeModel model) { if (ModelState.IsValid) { service.Insert(model); return(CreatedAtRoute("GetEventType", new { id = model.Id }, model)); } return(BadRequest(ModelState)); }
public void Insert_ThrowsException_HandledByCatchBlock() { var model = new EventTypeModel(); var contextMock = new Mock <IOnTaskDbContext>(); contextMock.Setup(x => x.InsertEventType(It.IsAny <EventType>())).Throws <Exception>(); var target = InitializeTarget(contextMock.Object); target.Insert(model); }
public AddDefaultEventTypeTODOViewModel(EventTypeModel eventTypeModel, EventTypeToDoModel eventTypeToDoModel) { EventType = eventTypeModel; var dataUnitLocator = ContainerAccessor.Instance.GetContainer().Resolve <IDataUnitLocator>(); _adminDataUnit = dataUnitLocator.ResolveDataUnit <IAdminDataUnit>(); SaveCommand = new RelayCommand(SaveCommandExecuted, SaveCommandCanExecute); ProcessEventTypeToDo(eventTypeToDoModel); }
public AddDefaultEventTypeTODOView(EventTypeModel eventTypeModel, EventTypeToDoModel eventTypeToDoModel = null) { InitializeComponent(); DataContext = ViewModel = new AddDefaultEventTypeTODOViewModel(eventTypeModel, eventTypeToDoModel); if (eventTypeModel != null) { this.Header = "Edit Default To Do"; } Owner = Application.Current.MainWindow; Loaded += OnViewLoaded; }
public async Task <IActionResult> Edit(EventTypeModel eventType) { if (ModelState.IsValid) { _db.Update(eventType); await _db.SaveChangesAsync(); return(RedirectToAction("ManageEventType")); } return(View(eventType)); }
public void Update_ThrowsException_HandledByCatchBlock() { var model = new EventTypeModel { Id = 1 }; var contextMock = new Mock <IOnTaskDbContext>(); contextMock.Setup(x => x.GetEventTypeByIdTracked(It.IsAny <int>())).Throws <Exception>(); var target = InitializeTarget(contextMock.Object); target.Update(model); }
private void createEventTypeButton_Click(object sender, EventArgs e) { if (ValidNewEventType()) { EventTypeModel m = new EventTypeModel(newEventTypeTextBox.Text); GlobalConfig.Connection.CreateEventType(m); newEventTypeTextBox.Text = ""; existingEventTypes.Add(m); WireUpListBox(); } }
public EventTypeModel CreateEventType(EventTypeModel model) { using (IDbConnection connection = new MySqlConnection(GlobalConfig.CnnString("OrganizerDB"))) { var p = new DynamicParameters(); p.Add("Name_", model.EventTypeName); p.Add("ID", 0, dbType: DbType.Int32, direction: ParameterDirection.Output); connection.Execute("insert_eventtype", p, commandType: CommandType.StoredProcedure); model.EventTypeId = p.Get <int>("ID"); return(model); } }
private void AddNewButton_Click(object sender, EventArgs e) { var new_model = new EventTypeModel(); new_model.EventTypeName = NameBox.Text; DisplayData.Add(OrganizerLibrary.GlobalConfig.Connections[0].CreateEventType(new_model)); List <EventTypeModel> temp = DisplayData.OrderByDescending(t => t.EventTypeName).ToList(); DisplayData = new BindingList <EventTypeModel>(temp); WireUpListBox(); }
public ActionResult EditEventType(int id) { var evntType = _context.Eventtypes.Find(id); // var eventtype = _event.GetEventById(id); var scvm = new EventTypeModel { ETId = evntType.ETId, Type = evntType.Name, Description = evntType.Description }; return(View(scvm)); }
public IActionResult Update(int id, [FromBody][CustomizeValidator(RuleSet = Constants.RuleSetNameForUpdate)] EventTypeModel model) { if (ModelState.IsValid) { if (id == model.Id) { service.Update(model); return(NoContent()); } return(BadRequest()); } return(BadRequest(ModelState)); }
public void UpdateEventType(EventTypeModel model) { using (IDbConnection connection = new MySqlConnection(GlobalConfig.CnnString("OrganizerDB"))) { // initializes dynamic parameters used for calling stored procedure var p = new DynamicParameters(); p.Add("Id", model.EventTypeId); p.Add("Name_", model.EventTypeName); // executes stored procedure connection.Execute("update_eventtype", p, commandType: CommandType.StoredProcedure); } }
public void CreateEventType(EventTypeModel model) { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db))) { var p = new DynamicParameters(); //Add Parameters p.Add("@NewEventType", model.EventType); p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output); connection.Execute("dbo.spCreateEventType", p, commandType: CommandType.StoredProcedure); model.Id = p.Get <int>("@id"); } }
public void Update_InvalidId_ContextSaveChangesNotCalled() { var model = new EventTypeModel { Id = 1 }; var contextMock = new Mock <IOnTaskDbContext>(); contextMock.Setup(x => x.GetEventTypeByIdTracked(It.Is <int>(y => y == model.Id))).Returns <EventType>(null).Verifiable(); var target = InitializeTarget(contextMock.Object); target.Update(model); contextMock.Verify(); contextMock.Verify(x => x.SaveChanges(), Times.Never()); }
private void existingEventTypesListBox_MouseDown(object sender, MouseEventArgs e) { if (existingEventTypesListBox.Items.Count == 0) { return; } int index = existingEventTypesListBox.IndexFromPoint(e.X, e.Y); if (index != -1) { EventTypeModel s = (EventTypeModel)existingEventTypesListBox.Items[index]; DragDropEffects dde1 = DoDragDrop(s, DragDropEffects.All); } }
private void LoadEventTypeOptions(EventTypeModel eventTypeModel) { eventTypeModel.Options = new ObservableCollection <EventOptionModel>(); var eventTypeOptions = eventTypeModel.EventType.EventTypeOptions.Select(x => x.EventOption); foreach (EventOption eventOption in EventOptions) { var eventOptionModel = new EventOptionModel(eventOption) { IsChecked = eventTypeOptions.Contains(eventOption) }; eventOptionModel.PropertyChanged += EventTypeOptionOnPropertyChanged; eventTypeModel.Options.Add(eventOptionModel); } }
// GET: api/EventType/5 public IHttpActionResult Get(int id) { var result = new Result <EventTypeModel>(); using (var db = new jupiterEntities()) { EventType eventType = db.EventTypes.Find(id); EventTypeModel eventTypeModel = new EventTypeModel(); if (eventType == null) { return(Json(DataNotFound(result))); } Mapper.Map(eventType, eventTypeModel); result.Data = eventTypeModel; } return(Json(result)); }
/// <summary> /// Inserts an <see cref="EventTypeModel"/> class. /// </summary> /// <param name="model">The <see cref="EventTypeModel"/> class to insert.</param> public void Insert(EventTypeModel model) { try { var entity = (EventType) new EventType { UserId = ApplicationUser.Id, CreatedOn = DateTime.Now }.InjectFrom <SmartInjection>(model); context.InsertEventType(entity); model.InjectFrom <SmartInjection>(GetById(entity.Id)); } catch (Exception) { throw; } }
public void Validate_ValidModel(int?id, int eventGroupId, int eventParentId, string name, string ruleSet) { var model = new EventTypeModel { Id = id, EventGroupId = eventGroupId, EventParentId = eventParentId, Name = name }; var result = target.Validate(model, ruleSet); Assert.IsTrue(result.IsValid); target.ShouldNotHaveValidationErrorFor(x => x.Id, model, ruleSet); target.ShouldNotHaveValidationErrorFor(x => x.EventGroupId, model, ruleSet); target.ShouldNotHaveValidationErrorFor(x => x.EventParentId, model, ruleSet); target.ShouldNotHaveValidationErrorFor(x => x.Name, model, ruleSet); }
public ActionResult EditEventType(EventTypeModel scvm) { if (ModelState.IsValid) { var eventtype = _context.Eventtypes.Where(sc => scvm.ETId == scvm.ETId).FirstOrDefault(); if (eventtype != null) { eventtype.Name = scvm.Type; eventtype.Description = scvm.Description; _context.SaveChanges(); TempData["message"] = $"{eventtype.Name} was successfully edited."; } return(RedirectToAction("EventTypeList")); } else { return(View(scvm)); } }
/// <summary> /// Updates an <see cref="EventTypeModel"/> class. /// </summary> /// <param name="model">The <see cref="EventTypeModel"/> class to update.</param> public void Update(EventTypeModel model) { try { var entity = context.GetEventTypeByIdTracked(model.Id.Value); if (entity != null && entity.UserId == ApplicationUser.Id) { entity.InjectFrom <SmartInjection>(model); entity.UpdatedOn = DateTime.Now; context.SaveChanges(); model.InjectFrom <SmartInjection>(GetById(entity.Id)); } } catch (Exception) { throw; } }
public async Task <ActionResult <EventType> > PostEventType(EventTypeModel eventTypeModel) { var result = new Result <EventType>(); EventType eventType = new EventType(); _mapper.Map(eventTypeModel, eventType); try { result.Data = eventType; await _context.EventType.AddAsync(eventType); await _context.SaveChangesAsync(); } catch (Exception e) { result.ErrorMessage = e.Message; result.IsFound = false; } return(Ok(result)); }
private void AddEventTypeCommandExecuted() { var type = new EventType { ID = Guid.NewGuid(), Name = "New Event Type", Colour = "#808080", PreferredName = "", Abbreviation = "" }; _adminDataUnit.EventTypesRepository.Add(type); _adminDataUnit.SaveChanges(); var typeModel = new EventTypeModel(type); LoadEventTypeOptions(typeModel); EventTypes.Add(typeModel); SelectedObject = typeModel; }
public AddDefaultEventTypeTODOViewModel(EventTypeModel eventTypeModel, EventTypeToDoModel eventTypeToDoModel) { EventType = eventTypeModel; var dataUnitLocator = ContainerAccessor.Instance.GetContainer().Resolve<IDataUnitLocator>(); _adminDataUnit = dataUnitLocator.ResolveDataUnit<IAdminDataUnit>(); SaveCommand = new RelayCommand(SaveCommandExecuted, SaveCommandCanExecute); ProcessEventTypeToDo(eventTypeToDoModel); }
public JsonResult SaveEventType(EventTypeModel model) { tbl_EventTypes eventType = ECommerceService.SaveEventType(model.Title, model.Description, model.EventTypeID); return Json((eventType != null) ? new { success = true, eventTypeID = eventType.EventTypeID } : new { success = false, eventTypeID = 0 } ); }
private void LoadEventTypeOptions(EventTypeModel eventTypeModel) { eventTypeModel.Options = new ObservableCollection<EventOptionModel>(); var eventTypeOptions = eventTypeModel.EventType.EventTypeOptions.Select(x => x.EventOption); foreach (EventOption eventOption in EventOptions) { var eventOptionModel = new EventOptionModel(eventOption) { IsChecked = eventTypeOptions.Contains(eventOption) }; eventOptionModel.PropertyChanged += EventTypeOptionOnPropertyChanged; eventTypeModel.Options.Add(eventOptionModel); } }