public IActionResult Create(User newuser)
        {
            if (ModelState.IsValid)
            {
                ViewBag.User_all = dashboardFactory.AllUsers();
                if (ViewBag.User_all.Count == 0) // Admins
                {
                    dashboardFactory.Add_Admin(newuser);
                    ViewBag.User_Extracting = dashboardFactory.FindByID();
                    int current_id = ViewBag.User_Extracting.id;
                    HttpContext.Session.SetInt32("current_id", (int)current_id);
                    return(RedirectToAction("Dashboard"));
                }
                // Non Admins
                dashboardFactory.Add(newuser);
                ViewBag.User_Extracting = dashboardFactory.FindByID();
                int current_other_id = ViewBag.User_Extracting.id;
                HttpContext.Session.SetInt32("current_id", (int)current_other_id);
                return(RedirectToAction("Dashboard"));
            }
            List <string> temp_errors = new List <string>();

            foreach (var error in ModelState.Values)
            {
                if (error.Errors.Count > 0)
                {
                    temp_errors.Add(error.Errors[0].ErrorMessage);
                }
            }
            TempData["errors"] = temp_errors;
            return(RedirectToAction("Register"));
        }
Exemplo n.º 2
0
    protected void btnCreateDashboard_Click(object sender, EventArgs e)
    {
        if (grdSalemen.SelectedItems.Count > 0)
        {
            try
            {
                var fileName = Session[FileNameSessionKey] as string;

                foreach (GridItem gi in grdSalemen.SelectedItems)
                {
                    string ReceiverPhoneNumber = gi.OwnerTableView.DataKeyValues[gi.ItemIndex]["Phone"].ToString();
                    var repo = new DashboardRepository();
                    ObjLogin adm = (ObjLogin)Session["objLogin"];
                    repo.Add(txtTitle.Text, txtContent.Text, ReceiverPhoneNumber, adm.Phone, fileName);
                    ClearFileSessionInfo();
                }

                lblMessage.Text = "<script type='text/javascript'>returnToParent()</" + "script>";
            }
            catch
            {
                lblMessage.Text = "Create Dashboard Fail";
                RemoveUploadedFile();
            }
        }
        else
        {
            RemoveUploadedFile();
        }
    }
        public void Given_DashboardRepository_When_AddingMoreNewDashboards_Then_TheDashboardsShouldBeProperlyAdded()
        {
            RunOnDatabase(sut =>
            {
                //Arrange
                var repository      = new DashboardRepository(sut);
                var dashboard       = Dashboard.Create(new DateTime(2017, 12, 16), "leisure");
                var secondDashboard = Dashboard.Create(new DateTime(2017, 11, 11), "housework");
                var thirdDashboard  = Dashboard.Create(new DateTime(2017, 5, 5), "study/work");
                //Act
                repository.Add(dashboard);
                repository.Add(secondDashboard);
                repository.Add(thirdDashboard);

                //Assert
                var dashboards = repository.GetAll();
                Assert.AreEqual(3, dashboards.Count);
            });
        }
        public void Given_DashboardRepository_When_GettingDashboardById_Then_ShouldReturnCorrectDashboard()
        {
            RunOnDatabase(sut =>
            {
                //Arrange
                var repository = new DashboardRepository(sut);
                var dashboard  = Dashboard.Create(new DateTime(2017, 12, 16), "leisure");

                //Act
                repository.Add(dashboard);

                //Assert
                var returnedDashboard = repository.GetById(dashboard.Id);
                Assert.AreEqual(dashboard.Id, returnedDashboard.Id);
            });
        }
        public void Given_DashboardRepository_When_AddingNewDashboard_Then_TheDashboardShouldBeProperlyAdded()
        {
            RunOnDatabase(sut =>
            {
                //Arrange
                var repository = new DashboardRepository(sut);
                var dashboard  = Dashboard.Create(new DateTime(2017, 12, 16), "leisure");

                //Act
                repository.Add(dashboard);

                //Assert
                var dashboards = repository.GetAll();
                Assert.AreEqual(1, dashboards.Count);
            });
        }