Esempio n. 1
0
        public DrawingObjectDTO ReadDrawingObject(int drawingObjectId)
        {
            using (var context = new HomeDrawDbContext())
            {
                DrawingObjectDTO drawingObjectDTO = null;

                try
                {
                    var foundDrawingObject = context.DrawingObjects.Find(drawingObjectId);

                    drawingObjectDTO = new DrawingObjectDTO()
                    {
                        DrawingID         = foundDrawingObject.DrawingID,
                        DrawingObjectID   = foundDrawingObject.DrawingObjectID,
                        DrawingObjectType = foundDrawingObject.DrawingObjectType,
                        PositionLeft      = foundDrawingObject.PositionLeft,
                        PositionTop       = foundDrawingObject.PositionTop
                    };
                }

                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                return(drawingObjectDTO);
            }
        }
Esempio n. 2
0
        public int CreateDrawingObject(DrawingObjectDTO drawingObjectDTO)
        {
            using (var context = new HomeDrawDbContext())
            {
                int returnedId = 0;

                try
                {
                    DrawingObject newDrawingObject = new DrawingObject()
                    {
                        DrawingID         = drawingObjectDTO.DrawingID,
                        DrawingObjectType = drawingObjectDTO.DrawingObjectType,
                        PositionLeft      = drawingObjectDTO.PositionLeft,
                        PositionTop       = drawingObjectDTO.PositionTop
                    };

                    context.DrawingObjects.Add(newDrawingObject);

                    context.SaveChanges();

                    returnedId = newDrawingObject.DrawingObjectID;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                return(returnedId);
            }
        }
Esempio n. 3
0
        public IEnumerable <DrawingObjectDTO> GetAllDrawingObjects()
        {
            using (var context = new HomeDrawDbContext())
            {
                List <DrawingObjectDTO> foundDrawingObjectsDTO = new List <DrawingObjectDTO>();

                try
                {
                    var foundDrawingObjects = context.DrawingObjects.ToList();

                    foreach (var drawingObject in foundDrawingObjects)
                    {
                        DrawingObjectDTO newDrawingObjectDTO = null;

                        newDrawingObjectDTO = new DrawingObjectDTO()
                        {
                            DrawingID         = drawingObject.DrawingID,
                            DrawingObjectID   = drawingObject.DrawingObjectID,
                            DrawingObjectType = drawingObject.DrawingObjectType,
                            PositionLeft      = drawingObject.PositionLeft,
                            PositionTop       = drawingObject.PositionTop
                        };

                        foundDrawingObjectsDTO.Add(newDrawingObjectDTO);
                    }
                }

                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                return(foundDrawingObjectsDTO);
            }
        }
Esempio n. 4
0
        public void UpdateElement(int x, int y, int elementId)
        {
            DrawingObjectDTO elementToUpdate = drawingObjectRepository.ReadDrawingObject(elementId);

            elementToUpdate.PositionLeft = x;
            elementToUpdate.PositionTop  = y;

            drawingObjectRepository.UpdateDrawingObject(elementToUpdate);

            Clients.Group(elementToUpdate.DrawingID.ToString()).createNewMementoCallback(elementToUpdate.DrawingObjectType, elementToUpdate.DrawingObjectID, elementToUpdate.PositionTop, elementToUpdate.PositionLeft);
        }
Esempio n. 5
0
        public IEnumerable <DrawingDTO> GetAllDrawings()
        {
            using (var context = new HomeDrawDbContext())
            {
                List <DrawingDTO> foundDrawingsDTO = new List <DrawingDTO>();

                try
                {
                    List <Drawing> foundDrawings = context.Drawings.Include(dr => dr.DrawingObjects).ToList();

                    foreach (var drawing in foundDrawings)
                    {
                        DrawingDTO newDrawingDTO = null;

                        newDrawingDTO = new DrawingDTO()
                        {
                            DrawingID = drawing.DrawingID,
                            Name      = drawing.Name,
                            Password  = drawing.Password,
                            MasterID  = drawing.MasterID,
                        };

                        foreach (var drawingObject in drawing.DrawingObjects)
                        {
                            DrawingObjectDTO newDrawingObjectDTO = null;

                            newDrawingObjectDTO = new DrawingObjectDTO()
                            {
                                DrawingID         = drawingObject.DrawingID,
                                DrawingObjectID   = drawingObject.DrawingObjectID,
                                DrawingObjectType = drawingObject.DrawingObjectType,
                                PositionLeft      = drawingObject.PositionLeft,
                                PositionTop       = drawingObject.PositionTop
                            };

                            newDrawingDTO.DrawingObjects.Add(newDrawingObjectDTO);
                        }

                        foundDrawingsDTO.Add(newDrawingDTO);
                    }
                }

                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                return(foundDrawingsDTO);
            }
        }
Esempio n. 6
0
        public DrawingDTO ReadDrawingByName(string drawingName)
        {
            using (var context = new HomeDrawDbContext())
            {
                DrawingDTO drawingDto = null;

                try
                {
                    var foundDrawing = context.Drawings.Where(d => d.Name == drawingName).Include(dro => dro.DrawingObjects).FirstOrDefault();

                    drawingDto = new DrawingDTO()
                    {
                        DrawingID = foundDrawing.DrawingID,
                        Name      = foundDrawing.Name,
                        Password  = foundDrawing.Password,
                        MasterID  = foundDrawing.MasterID,
                    };

                    drawingDto.DrawingObjects = new List <DrawingObjectDTO>();

                    foreach (var drawingObject in foundDrawing.DrawingObjects)
                    {
                        DrawingObjectDTO drawingObjectDTO = null;

                        drawingObjectDTO = new DrawingObjectDTO()
                        {
                            DrawingID         = drawingObject.DrawingID,
                            DrawingObjectID   = drawingObject.DrawingObjectID,
                            DrawingObjectType = drawingObject.DrawingObjectType,
                            PositionLeft      = drawingObject.PositionLeft,
                            PositionTop       = drawingObject.PositionTop
                        };

                        drawingDto.DrawingObjects.Add(drawingObjectDTO);
                    }
                }

                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                return(drawingDto);
            }
        }
Esempio n. 7
0
        public void UpdateDrawingObject(DrawingObjectDTO drawingObjectDTO)
        {
            using (var context = new HomeDrawDbContext())
            {
                try
                {
                    var foundDrawingObject = context.DrawingObjects.Where(d => d.DrawingObjectID == drawingObjectDTO.DrawingObjectID).FirstOrDefault();

                    foundDrawingObject.DrawingID         = drawingObjectDTO.DrawingID;
                    foundDrawingObject.DrawingObjectID   = drawingObjectDTO.DrawingObjectID;
                    foundDrawingObject.DrawingObjectType = drawingObjectDTO.DrawingObjectType;
                    foundDrawingObject.PositionLeft      = drawingObjectDTO.PositionLeft;
                    foundDrawingObject.PositionTop       = drawingObjectDTO.PositionTop;

                    context.SaveChanges();
                }

                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
Esempio n. 8
0
        public void DrawElement(string elementType, int containedDrawingId)
        {
            int?elementId = null;

            DrawingDTO drawing = drawingRepository.ReadDrawing(containedDrawingId);

            DrawingObjectDTO newElement = new DrawingObjectDTO();

            if (elementType == "bathElement")
            {
                newElement.DrawingObjectType = Domain.Enums.DrawingObjectTypeEnum.Bath;
            }

            if (elementType == "lavatoryElement")
            {
                newElement.DrawingObjectType = Domain.Enums.DrawingObjectTypeEnum.Lavatory;
            }

            if (elementType == "showerElement")
            {
                newElement.DrawingObjectType = Domain.Enums.DrawingObjectTypeEnum.Shower;
            }

            if (elementType == "doorElement")
            {
                newElement.DrawingObjectType = Domain.Enums.DrawingObjectTypeEnum.Door;
            }

            if (elementType == "wallElement")
            {
                newElement.DrawingObjectType = Domain.Enums.DrawingObjectTypeEnum.Wall;
            }

            if (elementType == "windowElement")
            {
                newElement.DrawingObjectType = Domain.Enums.DrawingObjectTypeEnum.Window;
            }

            if (elementType == "refrigeratorElement")
            {
                newElement.DrawingObjectType = Domain.Enums.DrawingObjectTypeEnum.Refrigerator;
            }

            if (elementType == "sinkElement")
            {
                newElement.DrawingObjectType = Domain.Enums.DrawingObjectTypeEnum.Sink;
            }

            if (elementType == "stoveElement")
            {
                newElement.DrawingObjectType = Domain.Enums.DrawingObjectTypeEnum.Stove;
            }

            if (elementType == "sofaElement")
            {
                newElement.DrawingObjectType = Domain.Enums.DrawingObjectTypeEnum.Sofa;
            }


            if (elementType == "tableElement")
            {
                newElement.DrawingObjectType = Domain.Enums.DrawingObjectTypeEnum.Table;
            }

            newElement.DrawingID = drawing.DrawingID;

            int newElementId = 0;

            newElementId = drawingObjectRepository.CreateDrawingObject(newElement);

            newElement.DrawingObjectID = newElementId;

            drawing.DrawingObjects.Add(newElement);

            elementId = newElement.DrawingObjectID;

            drawingRepository.UpdateDrawing(drawing);

            Clients.Group(containedDrawingId.ToString()).drawElementCallback(elementType, elementId);

            Clients.Group(containedDrawingId.ToString()).createNewMementoCallback(newElement.DrawingObjectType, newElement.DrawingObjectID, newElement.PositionTop, newElement.PositionLeft);
        }