コード例 #1
0
 public ImageModal(string ImageLocalURL, string callingPage, AccidentMediaViewModel photo)
 {
  
     InitializeComponent();
     BindingContext = this;
     theImageToDisplay = ImageLocalURL;
     currentAccidentMedia = photo;
     _callingPage = callingPage;
     Init();
     ImageToDisplay.Source = ImageSource.FromFile(theImageToDisplay);
 }
コード例 #2
0
        public async Task then_it_should_return_201_CREATED()
        {
            //act
            var bytes = File.ReadAllBytes("c:\\test\\test.mp3");
            var media = new AccidentMediaViewModel
            {
                AccidentId = accident.Id,
                Base64EncodedContent = Convert.ToBase64String(bytes),
                Filename = "testFileEndToEndTests",
                MimeType = "mp3",
            };


            result = await client.PostAsJsonAsync("api/accidentmedia", media);

            //assert
            result.IsSuccessStatusCode.ShouldBeTrue();
        }
コード例 #3
0
        /*  [Route("api/v1/accidentmedia", Name = "PostAccidentMedia")]*/
        public async Task<IHttpActionResult> Post(AccidentMediaViewModel accidentMediaViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (accidentMediaViewModel.Base64EncodedContent.IsBase64String())
                    {

                        if (
                            await
                                AuthorisePost(accidentMediaViewModel))
                        {
                            var created = TheModelFactoryV1.Create(await repo.Add(TheModelFactoryV1.Parse(accidentMediaViewModel)));
                            created.Base64EncodedContent = "";

                           
                           GenerateBaseLog(ApiLogType.Information,
                   LogMessageGenerator.Generate(ApiLogggingBaseMessages.Created, __loggingResourceName),
                   GetType(), GetCaller());
                            return CreatedAtRoute("AccidentMedia", new { id = created.Id }, created);
                        }

                       
GenerateBaseLog(ApiLogType.Error,
LogMessageGenerator.Generate(ApiLogggingBaseMessages.UnauthorisedAccess, __loggingResourceName),
GetType(), GetCaller());
                        return ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "You are not authorised to access this resource."));



                    }

                   
GenerateBaseLog(ApiLogType.Error,
LogMessageGenerator.Generate(ApiLogggingBaseMessages.Base64Error, __loggingResourceName),
GetType(), GetCaller());
                    return BadRequest("Your AccidentMedia POST request was malformed - the content was not BASE64 encoded.");

                }

               
               GenerateBaseLog(ApiLogType.Warning,
                  LogMessageGenerator.Generate(ApiLogggingBaseMessages.BadRequestMessage, __loggingResourceName),
                  GetType(), GetCaller());
                return BadRequest(ModelState);
            }
            catch (Exception ex)
            {
               
               GenerateBaseLog(ApiLogType.Error,
LogMessageGenerator.Generate(ApiLogggingBaseMessages.InternalServerErrorMessage, __loggingResourceName),
 GetType(), GetCaller(), ex);
                return InternalServerError(new Exception("An internal server error occurred when trying to update your AccidentMedia. Please contact api support."));
            }
        }
コード例 #4
0
        /*     [Route("api/v1/accidentmedia/{id}", Name = "GetAccidentMedia")]
             [Route("api/v1/accidentmedia", Name = "GetAccidentMediaCollectionRoot")]*/
        public async Task<IHttpActionResult> Get(int id, bool includeMedia = true)
        {
            //todo:implement NO media
            try
            {
                ClaimsPrincipal principal = Request.GetRequestContext().Principal as ClaimsPrincipal;
                var existingObjectInDb = _db.AccidentMedia.Include(x => x.Accident.Customer).FirstOrDefault(x => x.Id == id);

                if (existingObjectInDb == null)
                {
                   
                   GenerateBaseLog(ApiLogType.Warning,
                     LogMessageGenerator.Generate(ApiLogggingBaseMessages.NotFoundMessage, __loggingResourceName),
                     GetType(), GetCaller());
                    return NotFound();
                }

                if (
                    await
                        _dataAccessAuthoriser.AuthoriseAccessToClientData(principal,
                            existingObjectInDb.Accident.Customer))
                {

                    var model = new AccidentMediaViewModel();
                    if (includeMedia)
                    {
                        model = TheModelFactoryV1.Create(await repo.Get(id));
                    }
                    else
                    {

                    }


                    if (model != null)
                    {
                       
                       GenerateBaseLog(ApiLogType.Information,
             LogMessageGenerator.Generate(ApiLogggingBaseMessages.OKMessage, __loggingResourceName),
             GetType(), GetCaller());
                        return Ok(model);
                    }

                   
                   GenerateBaseLog(ApiLogType.Warning,
                LogMessageGenerator.Generate(ApiLogggingBaseMessages.BadRequestMessage, __loggingResourceName),
                GetType(), GetCaller());
                    return BadRequest("Couldn't find your AccidentMedia - please check the id paramater is correct");

                }

               
               GenerateBaseLog(ApiLogType.Error,
                  LogMessageGenerator.Generate(ApiLogggingBaseMessages.UnauthorisedAccess, __loggingResourceName),
                  GetType(), GetCaller());
                return
          ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Unauthorized,
              "You are not authorised to access this resource."));

            }
            catch (Exception)
            {
               
               GenerateBaseLog(ApiLogType.Error,
       LogMessageGenerator.Generate(ApiLogggingBaseMessages.InternalServerErrorMessage, __loggingResourceName),
       GetType(), GetCaller());
                return InternalServerError(new Exception("An internal server error occurred when trying to find your AccidentMedia. Please contact api support."));
            }

        }