Ejemplo n.º 1
0
        public IActionResult Edit(RobotEditModel model)
        {
            bool imageNotNull = model.Image != null;
            bool wrongType    = false;

            if (imageNotNull)
            {
                var fileType = model.Image.ContentType.Split('/')[1];

                wrongType = GlobalConstants.ImageExtensions.Contains(fileType);
            }

            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            if (!wrongType && imageNotNull)
            {
                this.ViewData[GlobalConstants.Error] = GlobalConstants.WrongFileType;
                return(this.View(model));
            }

            this.robotService.EditRobot(model);

            return(RedirectToAction("Details", "Robots", new { id = model.Id }));
        }
Ejemplo n.º 2
0
        public void EditRobot_Should_Succeed()
        {
            var robot = new Robot()
            {
                Id           = "1",
                UserId       = "123",
                Axes         = 2,
                Name         = "myRobot",
                SerialNumber = "2323"
            };

            this.Context.Robots.Add(robot);
            this.Context.SaveChanges();

            var robotEditModel = new RobotEditModel()
            {
                Id           = "1",
                Name         = "changed",
                Axes         = 4,
                SerialNumber = "3333",
                Image        = null
            };

            this.robotService.EditRobot(robotEditModel);

            var result = this.Context.Robots.Find(robot.Id);

            result.Should().NotBeNull()
            .And.Subject.As <Robot>()
            .Name.Should().BeEquivalentTo(robotEditModel.Name);
        }
Ejemplo n.º 3
0
        public void EditRobot(RobotEditModel model)
        {
            var robot = this.Context.Robots
                        .Include(x => x.User)
                        .First(x => x.Id == model.Id);

            var cloudinary = SetCloudinary();

            var url = UploadImage(cloudinary, model.Image, model.Name).GetAwaiter().GetResult();

            robot.Name         = model.Name;
            robot.SerialNumber = model.SerialNumber;
            robot.Axes         = model.Axes;
            if (url != null)
            {
                robot.ImageUrl = url;
            }


            this.Context.Robots.Update(robot);
            this.Context.SaveChanges();
        }