// Method for updating a existing collection(name). public void QnoteListView_UpdateItem(CollectionName collectionName) { try { var collectionNameExists = Service.GetCollectionName(collectionName.CollectionNameID); if (collectionNameExists == null) { // The item wasn't found ModelState.AddModelError("", String.Format("Item with id {0} was not found", collectionName)); return; } if (TryUpdateModel(collectionName)) { // Uppdaterar kontakten samt presenterar ett meddelande om att allt lyckats. Service.CreateCollectionName(collectionName); Session["Success"] = "Samlingen har uppdaterats!"; Response.Redirect(Request.UrlReferrer.ToString()); } } catch (Exception) { ModelState.AddModelError("", "Ett fel inträffade då kontakten skulle uppdateras."); } }
// Method for adding a new collection to the database. public void QnoteListView_InsertItem(CollectionName collectionName) { if (ModelState.IsValid) { try { Service.CreateCollectionName(collectionName); Session["Success"] = "Samlingen har skapats!"; Response.RedirectToRoute("Collections"); Context.ApplicationInstance.CompleteRequest(); } catch (Exception) { ModelState.AddModelError("", "Ett fel inträffade då samlingen skulle läggas till, försök igen om en stund!"); } } }
// Creates or updates a collection(name). public void CreateCollectionName(CollectionName collectionName) { ICollection<ValidationResult> validationResults; if (!collectionName.Validate(out validationResults)) { var ex = new ValidationException("The CollectionName object did not pass the data validation!"); ex.Data.Add("ValidationResults", validationResults); throw ex; } if (collectionName.CollectionNameID == 0) { CollectionNameDAL.CreateCollectionName(collectionName); } else { CollectionNameDAL.UpdateCollectionName(collectionName); } }