public void AddAttribute(DocumentAttribute Attribute) { using (Model.BiblosDS2010Entities db = new Model.BiblosDS2010Entities(BiblosDSConnectionString)) { Model.Attributes entityAttribute = Attribute.TryToConvertTo <Model.Attributes>(false); if (Attribute.Mode != null) { entityAttribute.IdMode = Attribute.Mode.IdMode; } if (Attribute.Archive != null) { entityAttribute.IdArchive = Attribute.Archive.IdArchive; } if (Attribute.AttributeGroup != null) { entityAttribute.IdAttributeGroup = Attribute.AttributeGroup.IdAttributeGroup; } db.AddToAttributes(entityAttribute); db.SaveChanges(); } }
public void UpdateAttribute(DocumentAttribute Attribute) { using (Model.BiblosDS2010Entities db = new Model.BiblosDS2010Entities(BiblosDSConnectionString)) { Model.Attributes entityAttribute = Attribute.TryToConvertTo <Model.Attributes>(false); if (entityAttribute.EntityKey == null) { entityAttribute.EntityKey = db.CreateEntityKey(entityAttribute.GetType().Name, entityAttribute); } var attachedEntity = db.GetObjectByKey(entityAttribute.EntityKey) as Model.Attributes; if (Attribute.Mode != null) { entityAttribute.IdMode = Attribute.Mode.IdMode; } if (Attribute.Archive != null) { entityAttribute.IdArchive = Attribute.Archive.IdArchive; } if (Attribute.AttributeGroup != null) { entityAttribute.IdAttributeGroup = Attribute.AttributeGroup.IdAttributeGroup; } db.ApplyCurrentValues(entityAttribute.EntityKey.EntitySetName, entityAttribute); db.SaveChanges(); } }
public async Task Post([FromBody] Model.Attributes newAttributes) { if (!isValidInput(newAttributes)) { return; } if (!isValidJsonString(newAttributes.Data.ToString())) { return; } if (!await IsAuthorized(newAttributes.URN)) { return; } // start the database Database.Attributes attributesDb = new Database.Attributes(); // this attribute is already there? string existingAttributes = await attributesDb.GetAttributes(newAttributes.URN); if (existingAttributes != null) { // ops, already there base.Response.StatusCode = (int)HttpStatusCode.Conflict; return; } // save await attributesDb.SaveAttributes(newAttributes); }
/// <summary> /// Save attribute information. /// </summary> /// <param name="attributes">Must have, at least, the URN property</param> /// <returns></returns> public async Task <bool> SaveAttributes(Model.Attributes attributes) { ListTablesResponse existingTables = await client.ListTablesAsync(); if (!existingTables.TableNames.Contains(TABLE_NAME)) { await SetupTable(client, TABLE_NAME, "URN"); } try { // create a generic dictionary Dictionary <string, DynamoDBEntry> dic = new Dictionary <string, DynamoDBEntry>(); dic.Add("URN", attributes.URN); dic.Add("Data", attributes.Data.ToString()); // save as a DynamoDB document Table table = Table.LoadTable(client, TABLE_NAME); Document document = new Document(dic); await table.PutItemAsync(document); // all good! return(true); } catch (Exception ex) { Console.WriteLine("Error saving attributes: " + ex.Message); } return(false); }
private bool isValidInput(Model.Attributes input) { if (input == null || string.IsNullOrWhiteSpace(input.URN) || input.Data == null || string.IsNullOrWhiteSpace(input.Data.ToString())) { base.Response.StatusCode = (int)HttpStatusCode.BadRequest; return(false); } return(true); }
public async Task Put(string urn, [FromBody] Model.Attributes updatedAttributes) { if (!isValidInput(updatedAttributes)) { return; } if (!isValidJsonString(updatedAttributes.Data.ToString())) { return; } if (!urn.Equals(updatedAttributes.URN)) { base.Response.StatusCode = (int)HttpStatusCode.BadRequest; return; } if (!await IsAuthorized(urn)) { return; } // start the database Database.Attributes attributesDb = new Database.Attributes(); /* * should we check if the attribute is there or not? * if is not there, let's just create it then... * * // this attribute is already there? * Model.Attributes existingAttributes = await attributesDb.GetAttributes(urn); * if (existingAttributes == null) * { * // ops, not there yet... * base.Response.StatusCode = (int)HttpStatusCode.BadRequest; * return; * } */ await attributesDb.SaveAttributes(updatedAttributes); }