public ActionResult Edit(int?ID)
        {
            ViewBag.StatusList = GetStatusList();         //Not sure how else to do this, getting an error when posting this
                                                          //didnt want to duplicate code so moved to a method but doesnt feel
                                                          //like a good solution.
                                                          //(error)there is no status list object, need to look at tempdata maybe?

            using (var context = new CustomerDbContext()) //uses the db context to add the customer sub to the db
            {
                if (ID == null)
                {
                    var result = new HttpNotFoundResult("No User ID associated with this customer");
                    return(result);
                }

                var customerToUpdate = context.Customers.Find(ID);
                TryUpdateModel(customerToUpdate);
                if (ModelState.IsValid)
                {
                    try
                    {
                        context.SaveChanges();
                        return(View("Index", context.Customers.ToList()));
                    }
                    catch (Exception)
                    {
                        ModelState.AddModelError("", "Unable to edit the customer");
                    }
                }
                return(View(customerToUpdate));
            }
        }
示例#2
0
        public ActionResult Update(int Id, string Name, string Email)
        {
            ActionResult result = null;

            User user = new User {
                Id = Id, Name = Name, Email = Email
            };

            switch (Users.Update(user))
            {
            case UserUpdateResult.Updated:
                result = Json(Users.GetById(Id));
                break;

            case UserUpdateResult.NoSuchUser:
                result = new HttpNotFoundResult();
                break;

            case UserUpdateResult.EmailInvalid:
                result = new HttpStatusCodeResult(400);
                break;

            case UserUpdateResult.NameOrEmailAlreadyTaken:
                result = new HttpStatusCodeResult(409);
                break;
            }

            return(result);
        }
示例#3
0
        public void DetailsView404Error()
        {
            //Act
            HttpNotFoundResult result = controller.Details(04) as HttpNotFoundResult;

            //Assert
            Assert.AreEqual(404, result.StatusCode);
        }
        public void Employee_Details_WithUnavailableId()
        {
            var controller = new EmployeeController();

            HttpNotFoundResult result = controller.Details(int.MaxValue) as HttpNotFoundResult;

            Assert.AreEqual((int)HttpStatusCode.NotFound, result.StatusCode);
        }
        public void DeleteViewNullBook()
        {
            //Act
            HttpNotFoundResult result = controller.Delete(0) as HttpNotFoundResult;

            //Assert
            Assert.AreEqual(404, result.StatusCode);
        }
        public void TestEditHttpNotFound()
        {
            //Act
            HttpNotFoundResult result = controller.Edit(1) as HttpNotFoundResult;

            //Assert
            Assert.AreEqual(404, result.StatusCode);
        }
        public void TestDeleteMessageHttpNotFound()
        {
            //Act
            HttpNotFoundResult result = controller.DeleteMessage(-9) as HttpNotFoundResult;

            //Assert
            Assert.AreEqual(404, result.StatusCode);
        }
示例#8
0
        public async Task <ActionResult> AnuncioDetalles(int?id, ConsultarDetalles consulta, string query)
        {
            if (id == null)
            {
                return(HttpNotFound("Parámetro inválido se espera un id de un anuncio"));
            }

            HttpNotFoundResult             result = null;
            PortalDetallesAnuncioViewModel model  = null;

            await Task.Run(() =>
            {
                using (var _dbContext = new MercampoEntities())
                {
                    Startup.OpenDatabaseConnection(_dbContext);
                    if (_dbContext.Database.Connection.State != ConnectionState.Open)
                    {
                        result = HttpNotFound("Error en la base de datos");
                    }
                    else
                    {
                        var anuncio = _dbContext.Anuncios.Where(a => a.id == id).FirstOrDefault();
                        if (anuncio == null)
                        {
                            result = HttpNotFound("No se encontro el anuncio con el id solicitado");
                        }
                        else
                        {
                            anuncio.clicks += 1;
                            _dbContext.SaveChanges();
                            var anuncioViewModel = new PortalAnuncioViewModel(anuncio.id, anuncio.titulo, anuncio.precio, anuncio.Subcategoria.Categoria.nombre, anuncio.Subcategoria.nombre,
                                                                              anuncio.Estado1.nombre, anuncio.Fotos_Anuncio.Where(f => f.principal == true).FirstOrDefault()?.ruta);

                            List <PaginaFotoViewModel> fotos = new List <PaginaFotoViewModel>();

                            var rutaVideo = anuncio.Videos_Anuncio.Where(v => v.idAnuncio == id).FirstOrDefault()?.ruta;

                            string nombre = anuncio.Usuario.nombre + " " + anuncio.Usuario.apellidos;
                            var owner     = new PaginaOwnerAnuncioViewModel(anuncio.Usuario.id, nombre, anuncio.Usuario.telefono, anuncio.Usuario.email);

                            foreach (var foto in anuncio.Fotos_Anuncio)
                            {
                                fotos.Add(new PaginaFotoViewModel(foto.principal, foto.ruta));
                            }

                            model = new PortalDetallesAnuncioViewModel(anuncioViewModel, anuncio.descripcion, fotos, rutaVideo, owner, anuncio.clicks, consulta, query);
                        }
                    }
                }
            });

            if (result != null)
            {
                return(result);
            }

            return(View(model));
        }
示例#9
0
        public void DetailsViewNullArea()

        {
            //Act
            HttpNotFoundResult p = controller.Details(0) as HttpNotFoundResult;

            //Assert
            Assert.AreEqual(404, p.StatusCode);
        }
示例#10
0
        public void Setup()
        {
            var playersRepository = Ioc.Get <IPlayersRepository>() as PlayersRepositoryStub;

            playersRepository.Players.Clear();

            _player             = null;
            _httpNotFoundResult = null;
        }
        public async Task <ActionResult> DetallesPago(int?id, double total)
        {
            if (Startup.GetAplicacionUsuariosManager().VerificarPortalSesion() == LoginStatus.Incorrecto)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (id == null)
            {
                return(HttpNotFound("Parámetro inválido se espera un id de un pago"));
            }

            HttpNotFoundResult    result = null;
            DetallesPagoViewModel model  = null;
            await Task.Run(() =>
            {
                using (var _dbContext = new MercampoEntities())
                {
                    Startup.OpenDatabaseConnection(_dbContext);
                    if (_dbContext.Database.Connection.State != ConnectionState.Open)
                    {
                        result = HttpNotFound("Error en la base de datos");
                    }
                    else
                    {
                        var conceptos = _dbContext.Pago_Concepto.Where(p => p.idPago == id);
                        if (conceptos == null)
                        {
                            result = HttpNotFound("No se encontro el pago con el id solicitado");
                        }
                        else
                        {
                            List <PagoConceptoViewModel> listaConceptos = new List <PagoConceptoViewModel>();
                            foreach (var concepto in conceptos)
                            {
                                if (concepto.descripcionBeneficio == null)
                                {
                                    listaConceptos.Add(new PagoConceptoViewModel(concepto.tipo, concepto.nombrePaquete, concepto.mesesPaquete, concepto.precioPaquete));
                                    continue;
                                }
                                listaConceptos.Add(new PagoConceptoViewModel(concepto.tipo, concepto.nombrePaquete, concepto.mesesPaquete, concepto.precioPaquete, concepto.descripcionBeneficio, concepto.precioBeneficio));
                            }

                            model = new DetallesPagoViewModel(total, listaConceptos);
                        }
                    }
                }
            });

            if (result != null)
            {
                return(result);
            }

            return(View(model));
        }
        public void FlightsDeleteHttpNotFouond()
        {
            //Arrange

            //Act
            HttpNotFoundResult viewresult = controller.Delete(1001) as HttpNotFoundResult;

            //Assert
            Assert.AreEqual(404, viewresult.StatusCode);
        }
示例#13
0
        public void EditViewNotFound()
        {
            //Act

            HttpNotFoundResult result = pc.Edit(25) as HttpNotFoundResult;

            //Assert

            Assert.AreEqual(404, result.StatusCode);
        }
        public void DetailsViewWrongId()
        {
            //Assest

            //Act
            HttpNotFoundResult result = controller.Details(4) as HttpNotFoundResult;

            //assert
            Assert.AreEqual(404, result.StatusCode);
        }
示例#15
0
        public void GetDelete_IncorrectId_404NotFound()
        {
            // Arrange
            EmployeeController controller = new EmployeeController(mock.Object);
            // Act
            HttpNotFoundResult result = (HttpNotFoundResult)controller.Delete(1000);

            // Assert
            Assert.IsTrue(result.StatusCode == 404);
        }
示例#16
0
        public void DownloadFile_NotFound()
        {
            // Arrange
            FrmNoteController controller = new FrmNoteController();

            // Act
            HttpNotFoundResult result = controller.DownloadFile("0", "test.txt") as HttpNotFoundResult;

            // Assert
            Assert.IsNotNull(result);
        }
示例#17
0
        public ViewResult NotFound()
        {
            var httpNotFound = new HttpNotFoundResult();

            Response.Clear();
            Response.StatusCode             = httpNotFound.StatusCode;
            Response.StatusDescription      = httpNotFound.StatusDescription;
            Response.TrySkipIisCustomErrors = true;

            return(View("~/Views/Error/NotFound.cshtml"));
        }
        public void DetailsIndexNullSubject()

        {
            //Act

            HttpNotFoundResult value = controller.Details(004) as HttpNotFoundResult;

            //Assert

            Assert.AreEqual(404, value.StatusCode);
        }
        public void GetDelete_IncorrectID_Error()
        {
            //Arrange

            DepartmentController target = new DepartmentController(mock.Object);
            //   Act
            HttpNotFoundResult result = (HttpNotFoundResult)target.Delete(100);

            // Assert
            Assert.IsTrue(result.StatusCode == 404);
        }
        public void DetailsIcecreamNotFound()
        {
            // Arrange
            // handled in TestInitialize

            // Act
            HttpNotFoundResult result = controller.Details(500) as HttpNotFoundResult;

            // Assert
            Assert.AreEqual(404, result.StatusCode);
        }
示例#21
0
        public ActionResult Details(int?id)
        {
            Customer cust = _context.Customers.Include("MembershipType").SingleOrDefault(c => c.id == id);

            if (cust == null)
            {
                HttpNotFoundResult noresult = new HttpNotFoundResult();
                return(noresult);
            }
            return(View(cust));
        }
示例#22
0
        public void GetEdit_NotExistingEmployee_Error()
        {
            // Arrange
            EmployeeController controller = new EmployeeController(mock.Object);

            // Act
            HttpNotFoundResult result = controller.Edit(1000) as HttpNotFoundResult;

            // Assert
            Assert.IsTrue(result.StatusCode == 404);
        }
        public void EditInvalidId()
        {
            // Arrange
            //Handled in TestInitiliaze

            // Act
            HttpNotFoundResult result = controller.Edit(500) as HttpNotFoundResult;

            // Assert
            Assert.AreEqual(404, result.StatusCode);
        }
示例#24
0
        public void SubcategoryControllerDetailsActionModelDoesntExist()
        {
            //arrange
            var subcategory = Constants.SubcategoriesNotInDatabase[0];

            //act
            HttpNotFoundResult result = _subcategoryController.Details(subcategory.Id) as HttpNotFoundResult;

            //assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult));
        }
        public void CategoryControllerEditCategoryGetActionCategoryDoesntExist()
        {
            //arrange
            var category = Constants.CategoriesNotInDatabase[0];

            //act
            HttpNotFoundResult result = _categoryController.Edit(category.Id) as HttpNotFoundResult;

            //assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult));
        }
        public void ItemControllerDeleteActionGetActionItemDoesNotExist()
        {
            //arrange
            var item = Constants.ItemsNotInDatabase[0];

            //act
            HttpNotFoundResult result = _controller.Delete(item.Id) as HttpNotFoundResult;

            //assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult));
        }
        public void GivenExceptionIsEntityNotFoundException_WhenOnException_ThenHttpNotFound()
        {
            EntityNotFoundException exception = new EntityNotFoundException();
            ExceptionContext        context   = ControllerContextFactory.CreateExceptionContext(MockHttpContext, exception);

            Target.OnException(context);

            HttpNotFoundResult actual = context.Result as HttpNotFoundResult;

            Assert.IsNotNull(actual);
            MockHttpContext.Response.AssertWasCalled(m => m.StatusCode = 404);
        }
示例#28
0
        public void DetailsCars()

        {

            //Act

            HttpNotFoundResult res = controller.Details(200) as HttpNotFoundResult;

            //Assert

            Assert.AreEqual(004, res.StatusCode);

        }
        public void TableControllerDeleteActionGetActionTableNotFound()
        {
            //arrange
            TableController tableController = ControllerFactory.GetTableController();
            var             table           = Constants.TablesNotInDatabase[0];

            //act
            HttpNotFoundResult result = tableController.Delete(table.Id) as HttpNotFoundResult;

            //assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult));
        }
示例#30
0
        public async Task <ActionResult> GaleriaAnuncio(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound("Parámetro inválido se espera un id de un anuncio"));
            }

            HttpNotFoundResult      result = null;
            GaleriaAnuncioViewModel model  = null;

            await Task.Run(() =>
            {
                using (var _dbContext = new MercampoEntities())
                {
                    Startup.OpenDatabaseConnection(_dbContext);
                    if (_dbContext.Database.Connection.State != ConnectionState.Open)
                    {
                        result = HttpNotFound("Error en la base de datos");
                    }
                    else
                    {
                        var anuncio = _dbContext.Anuncios.Where(a => a.id == id).FirstOrDefault();
                        if (anuncio == null)
                        {
                            result = HttpNotFound("No se encontro el anuncio con el id solicitado");
                        }
                        else
                        {
                            anuncio.clicks += 1;
                            _dbContext.SaveChanges();

                            List <PaginaFotoViewModel> fotos = new List <PaginaFotoViewModel>();

                            foreach (var foto in anuncio.Fotos_Anuncio)
                            {
                                fotos.Add(new PaginaFotoViewModel(foto.principal, foto.ruta));
                            }

                            model = new GaleriaAnuncioViewModel(fotos);
                        }
                    }
                }
            });

            if (result != null)
            {
                return(result);
            }

            return(PartialView("GaleriaAnuncio", model));
        }
        public void ExecuteResult() {
            // Arrange
            Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>();
            mockControllerContext.SetupSet(c => c.HttpContext.Response.StatusCode = 404).Verifiable();
            mockControllerContext.SetupSet(c => c.HttpContext.Response.StatusDescription = "Some description").Verifiable();

            HttpNotFoundResult result = new HttpNotFoundResult("Some description");

            // Act
            result.ExecuteResult(mockControllerContext.Object);

            // Assert
            mockControllerContext.Verify();
        }