コード例 #1
0
        public void ReturnBook_WhenUserNotFound_ThrowException()
        {
            // Arrange
            var contexInMemory = new DbContextOptionsBuilder <LibrarySystemContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnBook_WhenUserNotFound_ThrowException").Options;

            var validationMock = new Mock <IValidations>();

            string title         = "newBook",
                   author        = "Author",
                   genre         = "Genre",
                   userFirstName = "newUser",
                   userMiddName  = "midd",
                   userLastName  = "Userov";

            var book = new Book
            {
                Id     = new Guid(),
                Title  = title,
                Author = new Author()
                {
                    Name = author
                },
                Genre = new Genre()
                {
                    GenreName = genre
                },
                BooksInStore = 1
            };

            using (var arrangeContext = new LibrarySystemContext(contexInMemory))
            {
                arrangeContext.Books.Add(book);
                arrangeContext.SaveChanges();
            }

            // Act
            using (var actContext = new LibrarySystemContext(contexInMemory))
            {
                var unitOfWork = new UnitOfWork(actContext);
                var services   = new UsersServices(unitOfWork, validationMock.Object);

                services.ReturnBook(userFirstName, userMiddName, userLastName, title);
            }
        }
コード例 #2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            //try
            //{

            if (txtBoxUsername.Text != "")
            {
                // int check=0;

                if (txtBoxUsername.Text == "test")
                {
                    frmMain form = new frmMain();
                    _userName = txtBoxUsername.Text;
                    form.Show();
                    Hide();
                }
                else
                {
                    UsersServices userService = new UsersServices();


                    var result = userService.Login(txtBoxUsername.Text, txtBoxPassword.Text);
                    if (txtBoxPassword.Text == result.Password && txtBoxUsername.Text == result.Username)
                    {
                        frmMain form = new frmMain();
                        _userName = txtBoxUsername.Text;
                        form.Show();
                        Hide();
                    }
                    else
                    {
                        MessageBox.Show("Invalid Username and Password");
                    }
                }
            }
            else
            {
                MessageBox.Show("Please Input Username", "Error");
            }
            //}
            //catch (Exception error)
            //{
            //    MessageBox.Show(error.Message, "System Error");
            //}
        }
コード例 #3
0
        private void InitializeViews(int?type_id)
        {
            FunctionalOrganizationType type;
            SelectList typesList;
            User       user = new UsersServices().GetByUserName(User.Identity.Name.ToString());

            if (type_id != null)
            {
                type      = _typeService.GetById((int)type_id);
                typesList = new SelectList(new FunctionalOrganizationTypesServices().GetFunctionalOrganizationTypesForDropDownList(user.Company_Id), "Key", "Value", type.FOTParent_Id);
            }
            else
            {
                type      = new FunctionalOrganizationType();
                typesList = new SelectList(new FunctionalOrganizationTypesServices().GetFunctionalOrganizationTypesForDropDownList(user.Company_Id), "Key", "Value");
            }
            _typeViewModel = new FunctionalOrganizationTypeViewModel(type, typesList);
        }
コード例 #4
0
 private void loginUser()
 {
     if (TextBoxLogin.Text != "" && PassWordBoxPass.Password != "")
     {
         if (UsersServices.LogUser(TextBoxLogin.Text, PassWordBoxPass.Password))
         {
             ShowOrderMenu();
         }
         else
         {
             ShowMessage("Error", "usuario o contraseña incorrecta");
         }
     }
     else
     {
         ShowMessage("Error", "Ingrese un usuario y contraseña");
     }
 }
コード例 #5
0
        // GET: users/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var userService = new UsersServices();

            UsersDto user = userService.GetOne(id);

            //users users = db.users.Find(id);
            if (user == null)
            {
                return(HttpNotFound());
            }
            return(View(user));
        }
コード例 #6
0
        public void Get_User_FromDatabase_IfUser_Exists()
        {
            //Arrange
            var contextOptions = new DbContextOptionsBuilder <LibrarySystemContext>()
                                 .UseInMemoryDatabase(databaseName: "Get_User_FromDatabase")
                                 .Options;

            string firstName   = "Ivan",
                   middleName  = "Ivanov",
                   lastName    = "Ivanov",
                   phoneNumber = "1234567899";
            DateTime addOnDate = DateTime.Now;
            bool     isDeleted = false;

            string fullName = firstName + " " + middleName + " " + lastName;

            var validationMock = new Mock <CommonValidations>();

            using (var actContext = new LibrarySystemContext(contextOptions))
            {
                var unit = new UnitOfWork(actContext);

                var townService    = new TownService(unit, validationMock.Object);
                var addressService = new AddressService(unit, validationMock.Object);
                var userService    = new UsersServices(unit, validationMock.Object);

                var town    = townService.AddTown("test");
                var address = addressService.AddAddress("test address", town);

                userService.AddUser(firstName, middleName, lastName, phoneNumber, addOnDate, isDeleted, address);
            }
            using (var assertContext = new LibrarySystemContext(contextOptions))
            {
                var unit        = new UnitOfWork(assertContext);
                var userService = new UsersServices(unit, validationMock.Object);

                //Act
                var getUser = userService.GetUser(firstName, middleName, lastName);
                //Assert
                Assert.AreEqual(fullName, getUser.FullName);
            }
        }
コード例 #7
0
        public JsonResult GetFunctionalOrganizationTypesChildrenByType(int?type_id)
        {
            User                     UserLogged = new UsersServices().GetByUserName(User.Identity.Name);
            List <object>            functionalOrganizationTypes = new List <object>();
            Dictionary <int, string> types = type_id.HasValue ?
                                             _typeService.GetFunctionalOrganizationTypesChildrenByTypeForDropDownList(type_id.Value) :
                                             _typeService.GetFunctionalOrganizationTypesForDropDownList(UserLogged.Company_Id);

            foreach (var functionalOrganizationType in types)
            {
                functionalOrganizationTypes.Add(
                    new
                {
                    optionValue   = functionalOrganizationType.Key,
                    optionDisplay = functionalOrganizationType.Value
                });
            }

            return(Json(functionalOrganizationTypes));
        }
コード例 #8
0
        public string GetUserByLogin(string login)
        {
            string username = String.Empty;

            try
            {
                User user = new UsersServices().GetByUserName(login);

                if (user != null)
                {
                    username = user.UserName.ToString();
                }

                return(username);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #9
0
        private async void AddMembre()
        {
            InitError();
            UsersServices  usersServices = new UsersServices();
            ResponseObject response      = await usersServices.AddUser(User);

            if (response.Success)
            {
                _navigationService.NavigateTo("Membres");
                MessengerInstance.Send(new NotificationMessage(NotificationMessageType.ListUser));
            }
            else
            {
                List <Error> errors = (List <Error>)response.Content;
                foreach (Error error in errors)
                {
                    SwitchError(error);
                }
            }
        }
コード例 #10
0
        private void InitializeViews(int?functionalOrganization_id, int?functionalOrganizationType_id)
        {
            FunctionalOrganization functionalOrganization;
            SelectList             typesList;
            SelectList             typesParentList;
            SelectList             fosParentList;
            User user = new UsersServices().GetByUserName(User.Identity.Name.ToString());

            if (functionalOrganization_id != null)
            {
                functionalOrganization = _functionalOrganizationService.GetById((int)functionalOrganization_id);
                if (functionalOrganization.FOParent_Id.HasValue)
                {
                    typesParentList = new SelectList(new FunctionalOrganizationTypesServices().GetFunctionalOrganizationTypesForDropDownList(user.Company_Id), "Key", "Value", functionalOrganization.Parent.Type_Id);
                    typesList       = new SelectList(new FunctionalOrganizationTypesServices().GetFunctionalOrganizationTypesChildrenByTypeForDropDownList(functionalOrganization.Parent.Type_Id), "Key", "Value", functionalOrganization.Type_Id);
                    fosParentList   = new SelectList(_functionalOrganizationService.GetFunctionalOrganizationsByTypeForDropDownList(functionalOrganization.Parent.Type_Id), "Key", "Value", functionalOrganization.FOParent_Id);
                }
                else
                {
                    typesList       = new SelectList(new FunctionalOrganizationTypesServices().GetFunctionalOrganizationTypesForDropDownList(user.Company_Id), "Key", "Value", functionalOrganization.Type_Id);
                    typesParentList = new SelectList(new FunctionalOrganizationTypesServices().GetFunctionalOrganizationTypesForDropDownList(user.Company_Id), "Key", "Value");
                    fosParentList   = new SelectList(new Dictionary <int, string>(), "Key", "Value");
                }
            }
            else
            {
                functionalOrganization = new FunctionalOrganization();
                typesParentList        = new SelectList(new FunctionalOrganizationTypesServices().GetFunctionalOrganizationTypesForDropDownList(user.Company_Id), "Key", "Value");
                fosParentList          = new SelectList(new Dictionary <int, string>(), "Key", "Value");
                if (functionalOrganizationType_id != null)
                {
                    typesList = new SelectList(new FunctionalOrganizationTypesServices().GetFunctionalOrganizationTypesForDropDownList(user.Company_Id), "Key", "Value", functionalOrganizationType_id.Value);
                    functionalOrganization.Type_Id = functionalOrganizationType_id.Value;
                }
                else
                {
                    typesList = new SelectList(new FunctionalOrganizationTypesServices().GetFunctionalOrganizationTypesForDropDownList(user.Company_Id), "Key", "Value");
                }
            }
            _functionalOrganizationViewModel = new FunctionalOrganizationViewModel(functionalOrganization, typesList, typesParentList, fosParentList);
        }
コード例 #11
0
        public ActionResult QueryEmployeeIDs()
        {
            try
            {
                if (!WebCookieHelper.EmployeeCheckLogin())
                {
                    return(RedirectToAction("Admin/Account/Login"));
                }
                JsonHelper json    = new JsonHelper();
                string     strJson = string.Empty;
                json.AddItem("id", "");
                json.AddItem("text", "所有");
                json.ItemOk();

                int    empid = WebCookieHelper.GetEmployeeId();
                string Name  = WebCookieHelper.GetEmployeeInfo((int)WebCookieHelper.EmployeeInfo.Name);
                if (!RightServices.CheckAuthority(SystemContext.RightPoint.ViewAllUsers, empid))
                {
                    json.AddItem("id", empid.ToString());
                    json.AddItem("text", Name);
                    json.ItemOk();
                }
                else
                {
                    var result = UsersServices.GetStaffEmployee(empid);
                    foreach (Employee item in result)
                    {
                        json.AddItem("id", item.ID.ToString());
                        json.AddItem("text", item.Name);
                        json.ItemOk();
                    }
                }
                strJson = json.ToEasyuiListJsonString();
                return(Content(strJson));
            }
            catch (Exception ex)
            {
                GlobalMethod.log.Error(ex);
                throw;
            }
        }
コード例 #12
0
        public bool IsUserInRole(string login, string role)
        {
            try
            {
                var user = new UsersServices().GetByUserName(login);
                if (user != null)
                {
                    return(user.Role.Name == role);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);

                throw ex;
            }
        }
コード例 #13
0
        private void BuyMufflerBT(object arg)
        {
            DateTime      dateTime      = DateTime.Now;
            UsersServices usersServices = new UsersServices {
                ServiceId = 1, Date = dateTime, Status = "not ready", UserId = user.Id
            };

            unitOfWork.Orders.Create(usersServices);
            unitOfWork.Save();
            SendEmail("Вы успешно заказали ремонт глушителя. Администратор скоро свяжется с вами. Подробную информацию можно посмотреть в личном кабинете.", user.Email);
            Service serviceView = new Service(user, res);

            serviceView.Show();
            foreach (Window item in App.Current.Windows)
            {
                if (item != serviceView)
                {
                    item.Close();
                }
            }
        }
コード例 #14
0
 private void BUpdate_Click(object sender, RoutedEventArgs e)
 {
     if (TBName.Text != "" &&
         TBPaterno.Text != "" &&
         TBMaterno.Text != "" &&
         TBlogin.Text != "" &&
         TBPassword.Text != "")
     {
         UsersServices.UpdateThisUser(TBName.Text,
                                      TBPaterno.Text,
                                      TBMaterno.Text,
                                      TBlogin.Text,
                                      TBPassword.Text,
                                      currentSelectedUser);
     }
     else
     {
         ShowMessage("Error", "No se puedo Actualizar al Usuario");
     }
     showAllUser();
 }
コード例 #15
0
        public async Task  ChargeVar()
        {
            UsersServices       usersServices       = new UsersServices();
            TournamentsServices tournamentsServices = new TournamentsServices();
            long idTounrnament     = Tournament.Id;
            bool allRequestSuccess = true;

            try
            {
                List <User> users = await tournamentsServices.GetParticipants(idTounrnament);

                AllUsers = new ObservableCollection <User>(users);
                List <User> arbitres = await usersServices.GetUsersWithAccount();

                AllArbitre = new ObservableCollection <User>(arbitres);
            }
            catch (Exception e)
            {
                allRequestSuccess = false;
                SetGeneralErrorMessage(e);
            }

            if (allRequestSuccess)
            {
                if (Match.Arbitre != null)
                {
                    SelectedArbitre = AllArbitre.Where(a => a.Id == Match.Arbitre.Id).DefaultIfEmpty(null).First();
                }
                if (Match.Player1 != null)
                {
                    SelectedJoueur1 = AllUsers.Where(u => u.Id == Match.Player1.Id).First();
                }
                if (Match.Player2 != null)
                {
                    SelectedJoueur2 = AllUsers.Where(u => u.Id == Match.Player2.Id).First();
                }
                HeurePrevue = Match.Time;
                LieuMatch   = Match.Emplacement;
            }
        }
コード例 #16
0
        public ActionResult GridData(string sidx, string sord, int page, int rows, string filters)
        {
            User   user = new UsersServices().GetByUserName(User.Identity.Name.ToString());
            object resultado;

            if (user.Role.Name == "HRAdministrator")
            {
                if (user.Company.CompaniesType.Name == "Owner")
                {
                    resultado = _questionnaireService.RequestList(sidx, sord, page, rows, filters);
                }
                else
                {
                    resultado = _questionnaireService.RequestList(user, sidx, sord, page, rows, filters);
                }
            }
            else
            {
                resultado = _questionnaireService.RequestList(user, sidx, sord, page, rows, filters);
            }
            return(Json(resultado));
        }
コード例 #17
0
        private void InitializeViews(int?questionnaire_id)
        {
            Questionnaire questionnaire;
            SelectList    templatesList = null;
            User          user          = new UsersServices().GetByUserName(User.Identity.Name);
            string        role          = user.Role.Name;

            if (user.Role.Name == "HRCompany")
            {
                templatesList = new SelectList(_questionnaireService.GetTemplatesByAssociatedForDropDownList(user.Company.CompanyAssociated_Id.Value), "Key", "Value");
            }

            if (questionnaire_id != null)
            {
                questionnaire = _questionnaireService.GetById((int)questionnaire_id);
            }
            else
            {
                questionnaire = new Questionnaire();
            }
            _questionnaireViewModel = new QuestionnaireViewModel(questionnaire, templatesList, role);
        }
コード例 #18
0
        public bool ValidateUser(string login, string password, int attemptsCounter)
        {
            try
            {
                UsersServices userService = new UsersServices();
                User          user        = userService.GetByUserName(login);
                if (user.IsLockedOut)
                {
                    return(false);
                }
                if (ValidatePassword(password, user.Password))
                {
                    user.FailedLoginAttemptsCounter = 0;
                    user.LastLoginDate = DateTime.Now;
                    user.IsOnline      = true;
                    userService.SaveChanges();
                    return(true);
                }
                else
                {
                    int previousLoginAttempts = user.FailedLoginAttemptsCounter;
                    previousLoginAttempts = previousLoginAttempts + 1;

                    if (previousLoginAttempts >= attemptsCounter)
                    {
                        user.IsLockedOut     = true;
                        user.LastLockOutDate = DateTime.Now;
                    }

                    userService.SaveChanges();

                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
コード例 #19
0
        private const string _securityToken = "token"; // Name of the url parameter.

        private bool Authorize(HttpActionContext actionContext)
        {
            try
            {
                var    getParams = actionContext.Request.GetQueryNameValuePairs().ToDictionary(x => x.Key, x => x.Value);
                string token     = getParams[_securityToken];
                var    restoUser = new UsersServices().UserForToken(token);
                HttpContext.Current.Items["token"] = token;
                if (restoUser != null)
                {
                    HttpContext.Current.Items["user"] = restoUser;

                    return(true);
                }

                return(false);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #20
0
        private Feedback GenerateFeedbackObject(FormCollection collection)
        {
            int?user_id;
            int type = GetTypeIdByUserAuthenticated();

            if (User.Identity.IsAuthenticated)
            {
                user_id = new UsersServices().GetByUserName(User.Identity.Name).Id;
            }
            else
            {
                user_id = null;
            }
            Feedback feedback = new Feedback();

            feedback.AddComments     = collection["feedback.AddComments"];
            feedback.Comments        = collection["feedback.Comments"];
            feedback.User_Id         = user_id;
            feedback.FeedbackType_Id = type;
            feedback.Show            = false;
            return(feedback);
        }
コード例 #21
0
        public ActionResult Upload()
        {
            HttpFileCollectionBase files = Request.Files;//这里只能用<input type="file" />才能有效果,因为服务器控件是HttpInputFile类型
            string msg        = string.Empty;
            string error      = string.Empty;
            string imgurl     = string.Empty;
            string szTemplate = Request.Form["TemplateType"] == null ? "研究生考试" : Request.Form["TemplateType"].ToString();

            if (files.Count < 0)
            {
                return(Content(""));
            }
            string res = string.Empty;

            if (files[0].FileName == "")
            {
                error = "未选择文件";
                res   = "{ error:'" + error + "', msg:'" + msg + "',imgurl:'" + imgurl + "'}";
            }
            else
            {
                files[0].SaveAs(Server.MapPath(SystemContext.FilePath.Excel) + System.IO.Path.GetFileName(files[0].FileName));
                msg    = " 导入成功!请关闭窗口查看导入结果";
                imgurl = "/" + files[0].FileName;

                //处理数据导入
                try
                {
                    bool result = UsersServices.Import(Server.MapPath(SystemContext.FilePath.Excel) + System.IO.Path.GetFileName(files[0].FileName), SystemContext.Template.GetTemplate(szTemplate));
                }
                catch (Exception ex)
                {
                    error = "导入失败";
                }
                res = "{ error:'" + error + "', msg:'" + msg + "',imgurl:'" + imgurl + "'}";
            }
            return(Content(res));
        }
コード例 #22
0
        public ActionResult Create(UsersViewModel newUser)
        {
            try
            {
                bool error = false;
                if (newUser.Name.IsEmpty())
                {
                    error = true;
                    ModelState.AddModelError(string.Empty, "User Name cannot be empty");
                }

                if (newUser.City.IsEmpty())
                {
                    error = true;
                    ModelState.AddModelError(string.Empty, "City cannot be empty");
                }


                if (error)
                {
                    return(View("Create", newUser));
                }


                var userService = new UsersServices(db);
                var user        = new User();
                user.Email = newUser.Email;
                user.Name  = newUser.Name;
                user.City  = newUser.City;

                userService.CreateUser(user);
                return(RedirectToAction("Index", "Review"));
            }
            catch
            {
                return(View());
            }
        }
コード例 #23
0
        public string GenerateNewPassword(string username)
        {
            UsersServices userService  = new UsersServices();
            string        randomString = "";
            string        pwd          = "";
            Random        randObj      = new Random();

            randomString = randomString + randObj.Next().ToString();

            User user = userService.GetByUserName(username);

            pwd = EncryptPassword(randomString);

            user.Password = pwd;
            user.LastPasswordChangedDate    = DateTime.Now;
            user.FailedLoginAttemptsCounter = 0;
            user.IsApproved  = true;
            user.IsLockedOut = false;
            user.IsOnline    = true;
            userService.SaveChanges();

            return(randomString);
        }
コード例 #24
0
        private async void SignIn_Clicked(object sender, EventArgs e)
        {
            UserInfo userLogin     = new UserInfo();
            var      usersServices = new UsersServices();
            var      data          = new { username = username.Text, password = password.Text };

            userLogin = await usersServices.LoginUserAsync(data);

            if (userLogin is null)
            {
                await DisplayAlert("Thông báo", "Tên đăng nhập hoặc mật khẩu không chính xác!", "ok");
            }
            else
            {
                await DisplayAlert("Thông báo", "Đăng nhập thành công", "ok");

                Application.Current.Properties["userId"] = userLogin.data.id;
                //Application.Current.Properties["accessToken"] = userLogin.data.accessToken;
                await SecureStorage.SetAsync("oauthtoken", userLogin.data.accessToken);

                await Navigation.PushAsync(new MasterDetail());
            }
        }
コード例 #25
0
        public void Add_User_ToDatabase()
        {
            //Arrange
            var contextOptions = new DbContextOptionsBuilder <LibrarySystemContext>()
                                 .UseInMemoryDatabase(databaseName: "Add_User_ToDatabase")
                                 .Options;

            string firstName        = "Ivan",
                   middleName       = "Ivanov",
                   lastName         = "Ivanov",
                   phoneNumber      = "1234567899";
            DateTime addOnDate      = DateTime.Now;
            bool     isDeleted      = false;
            var      validationMock = new Mock <CommonValidations>();

            using (var actContext = new LibrarySystemContext(contextOptions))
            {
                var unit = new UnitOfWork(actContext);

                var townService    = new TownService(unit, validationMock.Object);
                var addressService = new AddressService(unit, validationMock.Object);
                var userService    = new UsersServices(unit, validationMock.Object);

                var town    = townService.AddTown("test");
                var address = addressService.AddAddress("test address", town);

                //Act
                userService.AddUser(firstName, middleName, lastName, phoneNumber, addOnDate, isDeleted, address);
            }
            // Assert
            using (var assertContext = new LibrarySystemContext(contextOptions))
            {
                int count = assertContext.Users.Count();
                Assert.AreEqual(1, count);
                Assert.AreEqual(firstName, assertContext.Users.First().FirstName);
            }
        }
コード例 #26
0
        private async Task InitializeDataAsync()
        {
            var    typeConst         = new TypeMethod();
            var    registersServices = new RegistersServices();
            var    usersServices     = new UsersServices();
            int    HeightList        = 0;
            double Cost   = 0;
            double Income = 0;

            var idUser = Application.Current.Properties["userId"].ToString();

            User = await usersServices.GetUserAsync(idUser);

            RegistersList = await registersServices.GetAllRegisters(idUser);

            foreach (ItemRegister itemRegister in RegistersList.data.items)
            {
                HeightList = (itemRegister.data.Count * 40) + (10 * itemRegister.data.Count) + 30;
                //Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(itemList));
                foreach (ItemDetail itemDetail in itemRegister.data)
                {
                    if (itemDetail.type == typeConst.Cost)
                    {
                        Cost += itemDetail.money;
                    }

                    if (itemDetail.type == typeConst.Income)
                    {
                        Income += itemDetail.money;
                    }
                }

                itemRegister.AddProperty(HeightList, Cost, Income);

                HeightList = 0; Cost = 0; Income = 0;
            }
        }
コード例 #27
0
        private void InitializeViews(int?locaton_id, int?country_id, int?state_id)
        {
            Location   location;
            SelectList statesList;
            SelectList countriesList;
            SelectList regionsList;
            User       user = new UsersServices().GetByUserName(User.Identity.Name.ToString());

            if (locaton_id != null)
            {
                location      = _locationService.GetById((int)locaton_id);
                statesList    = new SelectList(new StatesServices().GetStatesForDropDownList(location.State.Country_Id), "Key", "Value", location.State_Id);
                regionsList   = new SelectList(new RegionsServices().GetRegionsForDropDownList(user.Company_Id), "Key", "Value", location.Region_Id);
                countriesList = new SelectList(new CountriesServices().GetCountriesForDropDownList(), "Key", "Value", location.State.Country_Id);
            }
            else
            {
                location    = new Location();
                regionsList = new SelectList(new RegionsServices().GetRegionsForDropDownList(user.Company_Id), "Key", "Value");
                statesList  = new SelectList(new StatesServices().GetEmptyDictionary(), "Key", "Value");
                if (country_id != null)
                {
                    countriesList = new SelectList(new CountriesServices().GetCountriesForDropDownList(), "Key", "Value", country_id);
                    if (state_id != null)
                    {
                        location.State_Id = state_id.Value;
                        statesList        = new SelectList(new StatesServices().GetStatesForDropDownList(country_id.Value), "Key", "Value", state_id);
                    }
                }
                else
                {
                    countriesList = new SelectList(new CountriesServices().GetCountriesForDropDownList(), "Key", "Value");
                }
            }

            _locationViewModel = new LocationViewModel(location, statesList, countriesList, regionsList);
        }
コード例 #28
0
        private void InitializeViews(int?demo_id, string action)
        {
            Demo demo;
            User user = new UsersServices().GetByUserName(User.Identity.Name.ToString());

            switch (action)
            {
            case "Create":
                SelectList languageList = new SelectList(GetLanguages(), "Key", "Value");
                SelectList countryList  = new SelectList(new CountriesServices().GetCountriesForDropDownList(), "Key", "Value");
                demo          = new Demo();
                demoViewModel = new DemoViewModel(countryList, languageList, 1, 10);
                break;

            case "Edit":
                demo          = demoService.GetById((demo_id.Value));
                demoViewModel = new DemoViewModel(demo.Weeks, demo.Company.Tests.FirstOrDefault().EvaluationNumber);
                break;

            case "Details":
                demo = demoService.GetById((demo_id.Value));
                Test test      = demo.Company.Tests.FirstOrDefault();
                User user_test = demo.Company.Users.FirstOrDefault();
                demoViewModel = new DemoViewModel(demo.Company.Name, demo.Weeks,
                                                  test.EvaluationNumber, test.CurrentEvaluations, test.Code,
                                                  user_test.Email, user_test.UserName, test.CreationDate.ToString("ddHmmss"),
                                                  test.StartDate.ToString(ViewRes.Views.Shared.Shared.Date),
                                                  test.EndDate.ToString(ViewRes.Views.Shared.Shared.Date));
                break;

            case "Index":
                demo          = new Demo();
                demoViewModel = new DemoViewModel(demo);
                break;
            }
        }
コード例 #29
0
        private void InitializeViews(int?company_id)
        {
            Company    company;
            SelectList companiesTypesList;
            SelectList companySectorList;
            string     companyType = new UsersServices().GetByUserName(User.Identity.Name).Company.CompaniesType.Name;

            if (company_id != null)
            {
                company           = _companyService.GetById((int)company_id);
                companySectorList = new SelectList(new CompanySectorsServices().GetCompanySectorsForDropDownList(), "Key", "Value", company.CompanySector_Id);
                if (companyType == "Owner")
                {
                    companiesTypesList = new SelectList(new CompaniesTypesServices().GetCompaniesTypesForOwner(), "Key", "Value", company.CompanyType_Id);
                }
                else
                {
                    companiesTypesList = new SelectList(new CompaniesTypesServices().GetEmptyDictionary(), "Key", "Value");
                }
            }
            else
            {
                company           = new Company();
                companySectorList = new SelectList(new CompanySectorsServices().GetCompanySectorsForDropDownList(), "Key", "Value");
                if (companyType == "Owner")
                {
                    companiesTypesList = new SelectList(new CompaniesTypesServices().GetCompaniesTypesForOwner(), "Key", "Value");
                }
                else
                {
                    companiesTypesList = new SelectList(new CompaniesTypesServices().GetEmptyDictionary(), "Key", "Value");
                }
            }

            _companyViewModel = new CompanyViewModel(company, companiesTypesList, companySectorList, companyType);
        }
コード例 #30
0
 public UsersController(UsersServices usersService)
 {
     this.usersService = usersService;
 }