public ActionResult Add(MallMap map, HttpPostedFileBase mapfile) { try { var newFolderName = Utils.GetMd5Hash(mapfile.FileName + DateTime.Now); var filename = Path.GetFileName(mapfile.FileName); var path = Server.MapPath("~/Content/maps/" + newFolderName); var file = Path.Combine(path, filename); var myDirectoryInfo = Directory.CreateDirectory(path); var self = WindowsIdentity.GetCurrent(); var ds = myDirectoryInfo.GetAccessControl(); ds.AddAccessRule(new FileSystemAccessRule(self.Name, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow)); myDirectoryInfo.SetAccessControl(ds); mapfile.SaveAs(file); ZipFile.ExtractToDirectory(file, path); var fi = new FileInfo(file); fi.Delete(); var currentFloor = 1; var sideSize = 256; var files = Directory.GetFiles(path); foreach (var f in files) { var imagePath = path + "\\" + currentFloor + "\\"; Directory.CreateDirectory(imagePath); var bmp = new Bitmap(f); for (var currentRow = 0; currentRow < 3; ++currentRow) { for (var currentColumn = 0; currentColumn < 4; ++currentColumn) { var newBmp = new Bitmap(sideSize, sideSize); for (var i = 0; i < 256; ++i) { for (var j = 0; j < 256; ++j) { newBmp.SetPixel(j, i, bmp.GetPixel((currentColumn * sideSize) + j, (currentRow * sideSize) + i)); } } Directory.CreateDirectory(imagePath + currentRow); newBmp.Save(imagePath + currentRow + "\\" + currentColumn + ".png"); } } ++currentFloor; } map.FloorsCount = files.Length; map.TilesSource = "Content/maps/" + newFolderName + "/"; _mapRepository.Add(map); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } return(RedirectToAction("Index")); }
public HttpResponseMessage PostMap(Map item) { item = Repository.Add(item); var response = Request.CreateResponse(HttpStatusCode.Created, item); var uri = Url.Link("DefaultApi", new { id = item.Id }); response.Headers.Location = new Uri(uri); return(response); }
public IActionResult Post([FromBody] CreateMapRequest newMap) { Player player = (Player)this.HttpContext.Items["Player"]; Map map = new Map(newMap.MapLayout, newMap.Name, player); bool addedToRepo = mapRepo.Add(map); if (addedToRepo) { MapResource mapResource = new MapResource { Id = map.Id }; return(new ObjectResult(mapResource)); } return(new BadRequestResult()); }
public void Post([FromBody] MapSummary map) { if (!ModelState.IsValid) { HttpContext.Response.StatusCode = 400; } else { _maps.Add(new Map(map.Name)); // var url = Url.RouteUrl("GetMapById", new {id = map.Id}, Request.Scheme, // Request.Host.ToUriComponent()); // HttpContext.Response.StatusCode = 201; // HttpContext.Response.Headers["Location"] = url; } }
public async Task <Map> Add(Map entity) { await CheckMapNameDuplicity(entity); return(await _mapRepository.Add(entity)); }