public void PostAccountsTest() { Account sample = new Account() { contact = "546546", email = "sample_email", empno = 4353, password = "******", defunct = false, access = this.MockAccessLevels[0] }; Account acc = this.MongoBase.PostAccount(sample); Assert.IsNotNull(acc, "we have received a null response post adding the account to the database"); //trying to get the same account here Account identical = this.MongoBase.GetIdenticalAccount(sample); Assert.IsNotNull(identical, "No identical account found submitte in the database"); }
public IHttpActionResult Put(Account[] updates) { return ResponseMessage(this.Worker.PutAccounts(updates)); }
public IHttpActionResult Post(Account newAcc) { return ResponseMessage(this.Worker.PostAccount(newAcc)); }
public IHttpActionResult Patch(Account toPatch) { return ResponseMessage(this.Worker.PatchAccount(toPatch)); }
public HttpResponseMessage PatchAccount(Account toPatch) { if (toPatch !=null) { try { //this is when the account is about to be patched Account newPatched = this.MongoBase.PatchAccount(toPatch); //this would attempt to update the account, but not sure if that woudl succeeed. return newPatched !=null ? this.WebRequest.CreateResponse(HttpStatusCode.OK, newPatched) : this.WebRequest.CreateErrorResponse(HttpStatusCode.InternalServerError, new IOException("failed to update account due to some internal error")); } catch (IOException exception) { return this.WebRequest.CreateErrorResponse(HttpStatusCode.InternalServerError, exception); } } else { //this is whent we have not received the account to be patched return this.WebRequest.CreateErrorResponse(HttpStatusCode.BadRequest, new ArgumentException(Properties.Settings.Default.errBadRequestParam)); } }
public HttpResponseMessage PostAccount(Account newAcc) { if (newAcc!=null) { if (!String.IsNullOrEmpty(newAcc.email) && newAcc.empno !=null && !String.IsNullOrEmpty(newAcc.password)) { try { //trying to get the identical account var identical = this.MongoBase.GetIdenticalAccount(newAcc); if (identical == null) { //this when no identical account was found on the database try { var postAccount = this.MongoBase.PostAccount(newAcc); return this.WebRequest.CreateResponse(HttpStatusCode.Created, postAccount); //account is posted and we can go back to where we came from } catch (IOException exception) { //exception at the databae levell return this.WebRequest.CreateErrorResponse(HttpStatusCode.InternalServerError, exception); } } else { return this.WebRequest.CreateErrorResponse(HttpStatusCode.BadRequest, new ArgumentException(Properties.Settings.Default.errDupRegisteration)); } } catch (IOException exception) { //exception at the databae level return this.WebRequest.CreateErrorResponse(HttpStatusCode.InternalServerError, exception); } } else { //this the case when the account had invalid inputs return this.WebRequest.CreateErrorResponse(HttpStatusCode.BadRequest, new ArgumentException(Properties.Settings.Default.errBadRegistration)); } } else { //this is the case whent this a invalid account return this.WebRequest.CreateErrorResponse(HttpStatusCode.BadRequest, new ArgumentException(Properties.Settings.Default.errBadRequestParam)); } }