public string MakePortReplace(DCIMModel info) { string base64String = string.Empty; ServerPortDtl port = _dbContext.ServerPortDtl.Where(a => a.Id == info.SPort).FirstOrDefault(); PortMaster portMaster = _dbContext.PortMaster.Where(e => e.Id == info.DPort).FirstOrDefault(); Server server = _dbContext.Server.Where(e => e.Id == info.SServer).FirstOrDefault(); Bitmap src = System.Drawing.Image.FromFile(_hostingEnvironment.ContentRootPath + server.ImagePath) as Bitmap; Bitmap dest = System.Drawing.Image.FromFile(_hostingEnvironment.ContentRootPath + portMaster.ImagePath) as Bitmap; var target = new Bitmap(src.Width, src.Height, PixelFormat.Format32bppArgb); using (Graphics graphics = Graphics.FromImage(target)) { graphics.DrawImage(src, new Rectangle(new Point(), src.Size), new Rectangle(new Point(), src.Size), GraphicsUnit.Pixel); graphics.DrawImage(dest, new Rectangle(new Point(port.Xcoordinate, port.Ycoordinate), new Size(port.RectangleXcoordinate, port.RectangleYcoordinate)), new Rectangle(0, 0, dest.Width, dest.Height), GraphicsUnit.Pixel); } string filePath = server.ImagePath; src.Dispose(); target.Save(_hostingEnvironment.ContentRootPath + filePath); dest.Dispose(); base64String = Convert.ToBase64String(System.IO.File.ReadAllBytes(_hostingEnvironment.ContentRootPath + filePath)); port.Port = portMaster.PortName; _dbContext.ServerPortDtl.Update(port); _dbContext.SaveChanges(); return(base64String); }
public (int, string) InsertSlotDetails(DCIMModel dCIMModel) { var dSlot = _dbContext.SlotMaster .Where(a => a.Id == dCIMModel.DSlot).FirstOrDefault(); var dSlotPorts = _dbContext.SlotPort .Where(a => a.SlotId == dCIMModel.DSlot).ToList(); var sSlot = _dbContext.ServerSlotDtl .Where(a => a.Id == dCIMModel.SSlot).FirstOrDefault(); var sPortDtl = _dbContext.ServerPortDtl .Where(a => a.ServerSlotDtlId == dCIMModel.SSlot).ToList(); var Server = _dbContext.Server .Where(a => a.Id == dCIMModel.SServer).FirstOrDefault(); //this needs to be revisited float maxWidth = dSlot.RectangleXcoordinate; float minWidth = sSlot.RectangleXcoordinate; float maxHeight = dSlot.RectangleYcoordinate; float minHeight = sSlot.RectangleYcoordinate; float widthDiv = maxWidth / minWidth; float heightDiv = maxHeight / minHeight; if (sPortDtl.Count > 0) { _dbContext.RemoveRange(sPortDtl); dSlotPorts.ForEach(a => { ServerPortDtl ServerPortDtl = new ServerPortDtl(); ServerPortDtl.Xcoordinate = Convert.ToInt32(a.Xcoordinate / widthDiv) + sSlot.Xcoordinate; ServerPortDtl.Ycoordinate = Convert.ToInt32(a.Ycoordinate / heightDiv) + sSlot.Ycoordinate; ServerPortDtl.RectangleXcoordinate = Convert.ToInt32(a.RectangleXcoordinate.Value / widthDiv); ServerPortDtl.RectangleYcoordinate = Convert.ToInt32(a.RectangleYcoordinate.Value / heightDiv); ServerPortDtl.Port = a.PortName; ServerPortDtl.ServerId = sSlot.ServerId.Value; ServerPortDtl.ServerSlotDtlId = sSlot.Id; ServerPortDtl.Description = "desc"; _dbContext.Add(ServerPortDtl); }); } else { dSlotPorts.ForEach(a => { ServerPortDtl ServerPortDtl = new ServerPortDtl(); ServerPortDtl.Xcoordinate = Convert.ToInt32(a.Xcoordinate / widthDiv) + sSlot.Xcoordinate; ServerPortDtl.Ycoordinate = Convert.ToInt32(a.Ycoordinate / heightDiv) + sSlot.Ycoordinate; ServerPortDtl.RectangleXcoordinate = Convert.ToInt32(a.RectangleXcoordinate.Value / widthDiv); ServerPortDtl.RectangleYcoordinate = Convert.ToInt32(a.RectangleYcoordinate.Value / heightDiv); ServerPortDtl.Port = a.PortName; ServerPortDtl.ServerId = sSlot.ServerId.Value; ServerPortDtl.ServerSlotDtlId = sSlot.Id; ServerPortDtl.Description = "desc"; _dbContext.Add(ServerPortDtl); }); } Bitmap src1 = System.Drawing.Image.FromFile(_hostingEnvironment.ContentRootPath + Server.ImagePath) as Bitmap; Bitmap dest1 = System.Drawing.Image.FromFile(_hostingEnvironment.ContentRootPath + dSlot.ImagePath) as Bitmap; var target1 = new Bitmap(src1.Width, src1.Height, PixelFormat.Format32bppArgb); using (Graphics graphics = Graphics.FromImage(target1)) { graphics.DrawImage(src1, new Rectangle(new Point(), src1.Size), new Rectangle(new Point(), src1.Size), GraphicsUnit.Pixel); graphics.DrawImage(dest1, new Rectangle(new Point(sSlot.Xcoordinate, sSlot.Ycoordinate), new Size(sSlot.RectangleXcoordinate, sSlot.RectangleYcoordinate)), new Rectangle(0, 0, dest1.Width, dest1.Height), GraphicsUnit.Pixel); graphics.Dispose(); src1.Dispose(); } string filePath1 = Server.ImagePath; int success = 0; success = _dbContext.SaveChanges(); target1.Save(_hostingEnvironment.ContentRootPath + filePath1); dest1.Dispose(); string base64String = Convert.ToBase64String(System.IO.File.ReadAllBytes(_hostingEnvironment.ContentRootPath + filePath1)); return(success, base64String); }