public IActionResult PostResource([FromBody] ResourceCreationModel model) { try { if (model.Data == null || model.Data.Length == 0) { throw new Exception("Resource data is required"); } // Map model to entity var resource = _mapper.Map <Resource>(model); // Create code randomly resource.Code = Guid.NewGuid().ToString("B"); // Create var createdResource = _resourceService.Create(resource); // Upload data Utils.UploadData(model.Data, resource.Code); return(Ok(createdResource)); } catch (Exception ex) { return(BadRequest(new { resource = ex.Message })); } }
public IActionResult CreateResource([FromBody] Resource resource) { try { return(Ok(_service.Create(resource))); } catch (Exception ex) { var e = ex.GetBaseException(); return(BadRequest(new { msg = e.Message })); } }
public override IHttpActionResult Post(Resource model) { if (!ModelState.IsValid) { return(BadRequest()); } model.Id = Guid.NewGuid().ToString(); var add = _service.Create(model); return(Ok(add)); }
public ApiResponse <Domain.Models.Resource> CreateResource([FromBody] Domain.Models.Resource Resource) { return(_ResourceService.Create(Resource)); }
public async Task <HttpResponseMessage> Upload() { var streamProvider = new MultipartMemoryStreamProvider(); await Request.Content.ReadAsMultipartAsync(streamProvider); var fileNames = new List <string>(); foreach (var item in streamProvider.Contents) { if (item.Headers.ContentDisposition.FileName != null) { var ms = item.ReadAsStreamAsync().Result; //double size = ms.Length/1024; //int maxSize = 50; //int maxWidth = 640; //int maxHeight = 200; //if (size > maxSize) //{ //Image img = Image.FromStream(ms); // int imgWidth = img.Width; // int imgHeight = img.Height; // if (imgWidth > imgHeight) // { // if (imgWidth > maxWidth) // { // float toImgWidth = maxWidth; // //float toImgHeight = imgHeight / (imgWidth / toImgWidth); // // float toImgHeight = toImgWidth*imgHeight/imgWidth; // float toImgHeight = imgHeight * (toImgWidth / imgWidth); // // Bitmap newImg=new Bitmap(img,int.Parse(toImgWidth.ToString()),int.Parse(toImgHeight.ToString())); // Bitmap newImg = new Bitmap(img, Convert.ToInt16(toImgWidth), Convert.ToInt16(toImgHeight)); // MemoryStream stream = new MemoryStream(); // //newImg.Save(stream, newImg.RawFormat); // newImg.Save(stream, ImageFormat.Png); // ms = stream; // } // } // else // { // if (imgHeight > maxHeight) // { // float toImgHeight = maxHeight; // float toImgWidth = imgWidth / (imgHeight / toImgHeight); // var newImg = new Bitmap(img, int.Parse(toImgWidth.ToString()), int.Parse(toImgHeight.ToString())); // MemoryStream stream = new MemoryStream(); // newImg.Save(stream, newImg.RawFormat); // ms = stream; // } // } //} var fileLength = ms.Length; var info = new FileInfo(item.Headers.ContentDisposition.FileName.Replace("\"", "")); //var allowFomat = new[] {".png",".jpg",".jepg",".gif"}; //var isImage = allowFomat.Contains(info.Extension.ToLower()); var fileNewName = GetUniquelyString(); //保存至OSS var key = OssHelper.PutObject(ms, fileNewName + info.Extension); //if (isImage) //{ // OssHelper.PutThumbnaiObject(ms, fileNewName + info.Extension); //} var resource = new ResourceEntity { Guid = Guid.NewGuid(), Name = fileNewName, Length = fileLength, Type = info.Extension.Substring(1).ToLower(), // Adduser = ((UserBase)_workContent.CurrentUser).Id, Addtime = DateTime.Now, // UpdUser = _workContent.CurrentUser.Id, UpdTime = DateTime.Now, }; if (_resourceService.Create(resource).Id > 0) { fileNames.Add(key); } } } return(PageHelper.toJson(PageHelper.ReturnValue(true, string.Join("|", fileNames)))); }
public async Task <ActionResult <string> > Create() { return(await _telemetryCollector.WithStopwatch(async() => await _service.Create())); }
public static async Task SeedSampleDataAsync(IResourceService resourceService, ResourceContext context, IConfiguration configuration) { var seedingResources = new List <Domain.Models.Resource> { new Domain.Models.Resource { Id = Guid.NewGuid(), Name = "Oslo", Description = "Meeting room Oslo", TimeSlots = GetTimeSlots() }, new Domain.Models.Resource { Id = Guid.NewGuid(), Name = "Helsinki", Description = "Meeting room Helsinki", TimeSlots = GetTimeSlots() }, new Domain.Models.Resource { Id = Guid.NewGuid(), Name = "Tokyo", Description = "Meeting room Tokyo", TimeSlots = GetTimeSlots() }, new Domain.Models.Resource { Id = Guid.NewGuid(), Name = "Berlin", Description = "Meeting room Berlin", TimeSlots = GetTimeSlots() }, new Domain.Models.Resource { Id = Guid.NewGuid(), Name = "Moscow", Description = "Meeting room Moscow", TimeSlots = GetTimeSlots() }, new Domain.Models.Resource { Id = Guid.NewGuid(), Name = "Nairobi", Description = "Meeting room Nairobi", TimeSlots = GetTimeSlots() }, new Domain.Models.Resource { Id = Guid.NewGuid(), Name = "Rio", Description = "Meeting room Rio", TimeSlots = GetTimeSlots() }, new Domain.Models.Resource { Id = Guid.NewGuid(), Name = "Denver", Description = "Meeting room Denver", TimeSlots = GetTimeSlots() }, new Domain.Models.Resource { Id = Guid.NewGuid(), Name = "Stockholm", Description = "Meeting room Stockholm", TimeSlots = GetTimeSlots() }, }; bool dbContainsSeededResources = !seedingResources.Where(sR => context.Resources.Where(r => r.Name == sR.Name).Any()).Any(); if ((!context.Resources.Any()) || (configuration.GetValue <bool>("SeedDatabase") && dbContainsSeededResources)) //Configuration["Jwt:Issuer"] { seedingResources.ForEach(r => resourceService.Create(r)); //await context.Resources.AddRangeAsync(seedingResources); //await context.SaveChangesAsync(); } }
public IActionResult Create([FromBody] ResourceViewModel resource) { return(Ok(_resourceService.Create(resource))); }