public async Task<ActionResult> Create(Area area, HttpPostedFileBase upload)
        {
            try
            {                
                area.Id = Guid.NewGuid();

                var formData = new MultipartFormDataContent();
                var json = JsonConvert.SerializeObject(area);

                formData.Add(new StringContent(json, Encoding.Unicode, "application/json"));

                if (upload != null && upload.ContentLength > 0)
                {
                    formData.Add(new StreamContent(upload.InputStream), upload.FileName, upload.FileName);
                }

                var response = await saguClient.PostAsync("api/areas", formData);

                if (response.IsSuccessStatusCode)
                {
                    return RedirectToAction("Index");
                }
                else
                    return Content("An error occurred, status code " + response.ReasonPhrase);
            }
            catch
            {
                return Content("An error occurred.");
            }
        }
Example #2
0
        public Area SaveImage(Area area, string fileName, byte[] data)
        {
            var existingImage = GetImage(area.Id).Get(i => i.AsDTO());

            area.Image = existingImage ?? new AreaImage() { Id = area.Id };
            area.Image.FileName = fileName;

            File.WriteAllBytes(GetFilePath(area.Image), data);

            return area;
        }
Example #3
0
        public IHttpActionResult Post(Area area)
        {
            if (area == null)
                return BadRequest();

            try
            {
                var newArea = AreaService.CreateArea(area);

                return Created(string.Format("{0}/{1}", Request.RequestUri, newArea.Id), newArea);
            }
            catch (Exception)
            {
                return InternalServerError();
            }
        }