public long Add(EventUUIDRecord eur) { _ctx.EventRecords.Add(eur); long id = _ctx.SaveChanges(); return(id); }
public IActionResult GenerateUUID([FromBody] EventUUIDRequestObject requestObject) { if (requestObject == null) { return(BadRequest()); } if (ModelState.IsValid) { var name = requestObject.Name; //check if name already exists in database //and create a new Guid if necessary string guid; var record = _manager.GetByName(name); if (record == null) { guid = Guid.NewGuid().ToString(); //create a new record var newRecord = new EventUUIDRecord() { Name = name, UUID = guid }; _manager.Add(newRecord); } else { guid = record.UUID; } var responseObject = new UUIDResponseObject() { UUID = guid }; return(Ok(responseObject)); } else { return(BadRequest(ModelState)); } }