/* Create */ public async Task<OpObject> Create(String UserGuid, CModelRequest Request) { /* Lookup user master id */ Int64 uMasterId = 1;// Int64.Parse(UserGuid); Int64 mMasterId = -1; Guid mGuid; /* Lookup model based upon the signature * in the template */ mGuid = GetModelGuidFromTemplate(Request.TemplateWithData); mMasterId = await GetMasterId(mGuid, GuidType.Model); /* Do some basic sanity checks here, * because if mGuid is empty, model was not found * which means the template-data was invalid */ if (mGuid == Guid.Empty || mMasterId == -1) { return new OpObject(StatusCode.InvalidParameters, "The template data you submitted was either invalid or the ID of the template was removed." + " Please redownload the template you've used and try again."); } /* Proxy data */ TransactionRequest tRequest = new TransactionRequest() { Guid = Guid.NewGuid(), UserMasterId = uMasterId, ModelMasterId = mMasterId, Template = Request.TemplateWithData, Parameters = ((int)Request.Parameters).ToString(), Status = 0, Created = DateTime.Now }; /* Create the request in database */ Database.TransactionRequests.Add(tRequest); Database.Entry(tRequest).State = System.Data.Entity.EntityState.Added; /* Save */ await Database.SaveChangesAsync(); /* Done */ return new OpObject(StatusCode.Ok, tRequest.Guid.ToString()); }
/* PARSER - Get next request */ public async Task<CModelRequest> GetNext() { /* Lookup */ var tLookup = await (from Obj in Database.TransactionRequests where Obj.Status == (int)RequestStatus.InQueue select Obj).FirstOrDefaultAsync(); /* Sanity */ if (tLookup == null) return null; /* Proxy */ CModelRequest nRequest = new CModelRequest() { Guid = tLookup.Id.ToString(), Status = (RequestStatus)tLookup.Status, Parameters = (RequestParameters) Enum.Parse(typeof(RequestParameters), tLookup.Parameters, true), TemplateWithData = tLookup.Template, CreatedAt = tLookup.Created, Model = null }; /* Fill in model */ var mLookup = await (from Obj in Database.Models where Obj.MasterId == tLookup.ModelMasterId && Obj.Deleted == false select Obj).FirstOrDefaultAsync(); /* Proxy */ CModel nModel = new CModel() { Guid = mLookup.Guid.ToString(), Name = mLookup.Type, Type = mLookup.SubType, Template = mLookup.Template, Version = mLookup.Version, Country = mLookup.Country }; /* Set */ nRequest.Model = nModel; /* Done */ return nRequest; }