Пример #1
0
        public UserDataModel AddOrUpdate(IDbConnection connection, UserDataModel dataModel)
        {
            var m = _userRepo.AddOrUpdateeModel(connection, dataModel);

            dataModel.Id = m.Id;
            var user = _userCache.UpdateLocalItem(connection, m);

            _userAuthToGameIdCache.AddOrUpdate(connection, user.AuthId, user.Id, _userCache);
            _userNameSercherPkCache.AddOrUpdate(connection, user.Nickname, user.Id, _userCache);
            return(user);
        }
Пример #2
0
        public UserDataEditorWindow(UserDataModel userData)
        {
            this.user        = new UserViewModel(userData);
            this.DataContext = this.viewModel = new UserDataEditorWindowViewModel(userData);

            InitializeComponent();

            this.Initialize(this.StatusBar);

            this.Closed += UserDataEditorWindow_Closed;
        }
        public async Task <IActionResult> Create([Bind("UserId,UserName,NumberOfWins,NumberOfDefeats,NumberOfDraws")] UserDataModel userDataModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userDataModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(userDataModel));
        }
        public HttpResponseMessage DeleteUser([FromBody] UserDataModel model)
        {
            var exists = _userDal.GetUserById(model.UserId) != null;

            if (!exists)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new { Message = "User doesn't exist" }));
            }
            _userDal.DeleteUser(model.UserId);
            return(Request.CreateResponse(HttpStatusCode.OK, new { Message = "User deleted successfully" }));
        }
Пример #5
0
        public IHttpActionResult Get(int id)
        {
            UserDataModel dataModel = _user.GetUser(id);

            if (dataModel == null)
            {
                return(NotFound());
            }

            return(Ok(dataModel));
        }
Пример #6
0
 public NotifyOtherPageViewModel(INavigationService navigationService, ILoggerService loggerService, IUserDataService userDataService, ExposureNotificationService exposureNotificationService) : base(navigationService, exposureNotificationService)
 {
     Title = Resources.AppResources.TitileUserStatusSettings;
     this.loggerService               = loggerService;
     this.userDataService             = userDataService;
     this.exposureNotificationService = exposureNotificationService;
     userData      = this.userDataService.Get();
     errorCount    = 0;
     DiagnosisUid  = "";
     DiagnosisDate = DateTime.Today;
 }
Пример #7
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new UserDataModel
                {
                    UserName    = Input.Email,
                    Email       = Input.Email,
                    FirstName   = Input.FirstName,
                    LastName    = Input.LastName,
                    EGN         = Input.EGN,
                    Address     = Input.Address,
                    PhoneNumber = Input.Phone
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Пример #8
0
        private UserModel ParseUser(UserDataModel user)
        {
            UserType type = UserType.User;

            if (user.Type == "manager")
            {
                type = UserType.Manager;
            }

            return(new UserModel(user.Id, user.Name, user.Surname, user.Email, type));
        }
Пример #9
0
        private async Task <IActionResult> Get(HttpRequest req, ILogger log)
        {
            // get name from query
            string name = req.Query["name"];

            // get UserData from DB
            await Task.CompletedTask;
            var result = new UserDataModel();

            return((ActionResult) new OkObjectResult(result));
        }
Пример #10
0
        public IHttpActionResult GetById(int id)
        {
            var user = this.data.Users.GetById(id);

            if (user == null)
            {
                return(this.BadRequest("Unexisting user."));
            }

            return(this.Ok(UserDataModel.FromUser(user)));
        }
Пример #11
0
        public IEnumerable <User> BulkGive(Guid currencyID, [FromBody] IEnumerable <GiveUserCurrency> giveDatas)
        {
            if (!ChannelSession.Settings.Currency.ContainsKey(currencyID))
            {
                var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new ObjectContent <Error>(new Error {
                        Message = $"Unable to find currency: {currencyID.ToString()}."
                    }, new JsonMediaTypeFormatter(), "application/json"),
                    ReasonPhrase = "Currency ID not found"
                };
                throw new HttpResponseException(resp);
            }

            if (giveDatas == null)
            {
                var resp = new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new ObjectContent <Error>(new Error {
                        Message = $"Unable to parse array of give data from POST body."
                    }, new JsonMediaTypeFormatter(), "application/json"),
                    ReasonPhrase = "Invalid POST Body"
                };
                throw new HttpResponseException(resp);
            }

            CurrencyModel currency = ChannelSession.Settings.Currency[currencyID];

            List <User> users = new List <User>();

            foreach (var giveData in giveDatas)
            {
                UserDataModel user = null;
                if (!string.IsNullOrEmpty(giveData.UsernameOrID))
                {
                    if (Guid.TryParse(giveData.UsernameOrID, out Guid userId))
                    {
                        user = ChannelSession.Settings.GetUserData(userId);
                    }
                    else
                    {
                        user = ChannelSession.Settings.GetUserDataByUsername(StreamingPlatformTypeEnum.All, giveData.UsernameOrID);
                    }
                }

                if (user != null && giveData.Amount > 0)
                {
                    currency.AddAmount(user, giveData.Amount);
                    users.Add(UserController.UserFromUserDataViewModel(user));
                }
            }

            return(users);
        }
Пример #12
0
        public void UpdateUserData(UserDataModel data)
        {
            var dbData = GetDataByPk(data.pk.ToString());

            dbData.name = data.name;
            dbData.age  = data.age;
            dbData.city = data.city;

            repo.Update(dbData);
            repo.SaveChanges();
        }
Пример #13
0
 public virtual void Update(UserDataModel user)
 {
     if (user.ID > 0)
     {
         UserDAL.Update(user);
     }
     else
     {
         throw new Exception("Page not found");
     }
 }
        public override async Task Enable()
        {
            this.DamageTaken = false;
            this.NewBoss     = false;

            if (this.CurrentBossID != Guid.Empty)
            {
                UserDataModel userData = ChannelSession.Settings.GetUserData(this.CurrentBossID);
                if (userData != null)
                {
                    this.CurrentBoss = new UserViewModel(userData);
                }
                else
                {
                    this.CurrentBossID = Guid.Empty;
                }
            }

            if (this.CurrentBoss == null)
            {
                this.CurrentBoss   = ChannelSession.GetCurrentUser();
                this.CurrentHealth = this.CurrentStartingHealth = this.StartingHealth;
            }
            this.CurrentBossID = this.CurrentBoss.ID;

            if (this.FollowBonus > 0.0)
            {
                GlobalEvents.OnFollowOccurred += GlobalEvents_OnFollowOccurred;
            }
            if (this.HostBonus > 0.0)
            {
                GlobalEvents.OnHostOccurred += GlobalEvents_OnHostOccurred;
            }
            if (this.RaidBonus > 0.0)
            {
                GlobalEvents.OnRaidOccurred += GlobalEvents_OnRaidOccurred;
            }
            if (this.SubscriberBonus > 0.0)
            {
                GlobalEvents.OnSubscribeOccurred          += GlobalEvents_OnSubscribeOccurred;
                GlobalEvents.OnResubscribeOccurred        += GlobalEvents_OnResubscribeOccurred;
                GlobalEvents.OnSubscriptionGiftedOccurred += GlobalEvents_OnSubscriptionGiftedOccurred;
            }
            if (this.DonationBonus > 0.0)
            {
                GlobalEvents.OnDonationOccurred += GlobalEvents_OnDonationOccurred;
            }
            if (this.BitsBonus > 0.0)
            {
                GlobalEvents.OnBitsOccurred += GlobalEvents_OnBitsOccurred;
            }

            await base.Enable();
        }
Пример #15
0
        public SettingsPageViewModel(INavigationService navigationService, UserDataService userDataService) : base(navigationService, userDataService)
        {
            Title  = AppResources.SettingsPageTitle;
            AppVer = AppConstants.AppVersion;
            this.userDataService = userDataService;
            userData             = this.userDataService.Get();
            this.userDataService.UserDataChanged += _userDataChanged;

            EnableExposureNotification = userData.LastIsEnabled;
            EnableLocalNotification    = userData.EnableNotifications;
        }
Пример #16
0
        public int AddUser(UserDataModel newUser)
        {
            using (var connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                return(connection.QueryFirst <int>(
                           @"EXEC dbo.User_Add @Name = @Name, @Password = @Password, @State = @State",
                           newUser));
            }
        }
        public UserInventoryEditorControl(UserDataModel user, InventoryModel inventory)
        {
            this.user      = user;
            this.inventory = inventory;

            InitializeComponent();

            this.Loaded += UserInventoryEditorControl_Loaded;

            this.DataContext = this.inventory;
        }
Пример #18
0
        public async Task <IActionResult> Create([Bind("Assignment,Date,Text,Amount")] UserDataModel userDataModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userDataModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(userDataModel));
        }
Пример #19
0
        public IHttpActionResult PostUser([FromBody] UserDataModel user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Create(user);
            EmailService.SendPasswordResetEmail(user.UserName, user.UserName);
            return(CreatedAtRoute("DefaultApi", new { id = user.UserID }, user));
        }
Пример #20
0
        public IHttpActionResult PostUser(UserDataModel user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.CreateUser(user);

            return(CreatedAtRoute("DefaultApi", new { id = user.UserID }, user));
        }
Пример #21
0
        public GenericActionResult <UserDataModel> AuthenticateUser(string userName, string password)
        {
            var identityResult = this.Find(userName, password);

            UserDataModel userDataModel = null;

            if (identityResult != null)
            {
                if (identityResult.EmailConfirmed)
                {
                    userDataModel = _modelFactory.CreateUserDataModel(identityResult);

                    userDataModel.Roles =
                        _roleManager.GetRoleNames(identityResult.Roles.Select(c => c.RoleId).ToList()).ToList();

                    userDataModel.IsAuthenticated = true;

                    var authenticationResult = new GenericActionResult <UserDataModel>
                    {
                        Result    = userDataModel,
                        IsSuccess = true
                    };
                    return(authenticationResult);
                }
                else
                {
                    userDataModel = new UserDataModel {
                        IsAuthenticated = false
                    };
                    return(new GenericActionResult <UserDataModel>
                    {
                        Result = userDataModel,
                        IsSuccess = false,
                        Errors = new List <string> {
                            "Email has not been confirmed!"
                        }
                    });
                }
            }
            else
            {
                userDataModel = new UserDataModel {
                    IsAuthenticated = false
                };
                return(new GenericActionResult <UserDataModel>
                {
                    Result = userDataModel,
                    IsSuccess = false,
                    Errors = new List <string> {
                        "Incorrect username or password!"
                    }
                });
            }
        }
Пример #22
0
        public UserModel Create(UserDOM model)
        {
            var team = TeamRepository.GetByColor(model.Color);
            var user = new UserDataModel {
                Name = model.Name, Email = model.Email, GameCode = model.GameCode, GameNickname = model.GameNickname, Level = model.Level, Password = model.Password, Surname = model.Surname, Username = model.Username, Team = team, RaidsCompleted = 0
            };

            team.Members.Add(user);

            return(new UserModel(UserRepository.Save(user)));
        }
Пример #23
0
        private ClaimsIdentity CreateClaimsIdentity(UserDataModel user)
        {
            var claims = new[] {
                new Claim(ClaimTypes.Name, user.Email),
                new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
                //here you can create custom claim propertyes
                //new Claim("HasApprovedTermsAndConditions", user.HasApprovedTermsAndConditions.ToString())
            };

            return(new ClaimsIdentity(claims));
        }
Пример #24
0
        // GET /api/User/{userUuid}/{major}/{minor} - check user status and user exists
        public async Task <UserDataModel> GetUserAsync(UserDataModel user)
        {
            string url    = AppConstants.ApiBaseUrl + $"/user/{user.UserUuid}/{user.Major}/{user.Minor}";
            var    result = await Get(url);

            if (result != null)
            {
                return(Utils.DeserializeFromJson <UserDataModel>(result));
            }
            return(null);
        }
Пример #25
0
        public IHttpActionResult GetUser(int id)
        {
            UserDataModel user = db.Get(id);

            if (user == null)
            {
                return(NotFound());
            }

            return(Ok(user));
        }
Пример #26
0
        private void LogOffEventHandler(object sender, DialogClosingEventArgs eventArgs)
        {
            if ((bool)eventArgs.Parameter == false)
            {
                return;
            }

            string userFolder   = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, GlobalUser.DATAFOLDER);
            string userDataFile = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, GlobalUser.DATAFOLDER, $"user.dat");

            UserDataModel userDataModel = new UserDataModel
            {
                UserName    = GlobalUser.USER.UserName,
                Phone       = GlobalUser.USER.Moblie,
                AccessToken = "",
                Data        = new UserInfo()
            };

            GlobalUser.USER = null;
            string userEncoded = Base64Provider.AESEncrypt(userDataModel.ToJsonItem(), Base64Provider.KEY, Base64Provider.IV);

            try
            {
                if (!Directory.Exists(userFolder))
                {
                    Directory.CreateDirectory(userFolder);
                }
                if (!File.Exists(userDataFile))
                {
                    var file = File.Create(userDataFile);
                    file.Close();
                }
                using (StreamWriter sw = new StreamWriter(userDataFile, false))
                {
                    sw.Write(userEncoded);
                }
            }
            catch (Exception e)
            {
                Log4NetHelper.Error("写入用户信息异常:", e);
            }

            //Application.Current.Dispatcher.Invoke(() =>
            //{
            //    var cardResult = WebProxy(ApiType.UserLogout, GlobalUser.USER.AccessToken);
            //});

            var winLogin = new MainLogin();

            winLogin.Show();
            winLogin.Focus();
            Hide();
        }
Пример #27
0
        public override void Create(UserDataModel user)
        {
            if (!SecurityManager.SesionStarted())
            {
                throw new Exception("Session not started");
            }

            user.CreatedBy   = SecurityManager.GetLoggedUser().ID;
            user.DateCreated = DateTime.Now;

            base.Create(user);
        }
Пример #28
0
        public ExposureNotificationService(INavigationService navigationService, ILoggerService loggerService, IUserDataService userDataService, IHttpDataService httpDataService, IHttpClientService httpClientService)
        {
            this.httpDataService   = httpDataService;
            this.navigationService = navigationService;
            this.loggerService     = loggerService;
            this.userDataService   = userDataService;
            this.httpClientService = httpClientService;

            _        = this.GetExposureNotificationConfig();
            userData = userDataService.Get();
            userDataService.UserDataChanged += OnUserDataChanged;
        }
Пример #29
0
        public virtual void Update(UserDataModel user)
        {
            if (user.ID > 0)
            {

                UserDAL.Update(user);
            }
            else
            {
                throw new Exception("Page not found");
            }
        }
Пример #30
0
        public MainViewModel()
        {
            _userDataModel = new UserDataModel();

            _userSettingsData = new UserSettingsData();

            _contentControl = new StartingPage {
                DataContext = this
            };

            _appSettings = new AppSettings();
        }
Пример #31
0
        public void Save(User user)
        {
            // ゲッターを利用しデータの詰め替えをしている
            var userDataModel = new UserDataModel
            {
                Id   = user.Id.Value,
                Name = user.Name.Value
            };

            context.Users.Add(userDataModel);
            context.SaveChanges();
        }
Пример #32
0
        public override void Create(UserDataModel user)
        {
            if (!SecurityManager.SesionStarted())
            {
                throw new Exception("Session not started");
            }
            user.CreatedBy = SecurityManager.GetLoggedUser().ID;
            user.DateCreated = DateTime.Now;

            user.Password = EncryptionManager.MD5Encrypt(user.Password);

            base.Create(user);
        }
Пример #33
0
 public ActionResult NextSteps()
 {
     UserDataModel model = new UserDataModel(this);
     try
     {
         // force access to validate current user
         var userData = model.UserData;
     }
     catch
     {
         return RedirectToAction("SignOut", "Account");
     }
     return View(model);
 }
Пример #34
0
 public ActionResult Wizard(string consentStatus = null)
 {
     UserDataModel model = new UserDataModel(this);
     try
     {
         // force access to validate current user
         var userData = model.ClientFolders;
         model.ConsentStatus = consentStatus;
     }
     catch
     {
         return RedirectToAction("SignOut", "Account");
     }
     return View(model);
 }
Пример #35
0
        public static UserDataModel CheckUser(string email, string password)
        {
            UserDataModel user = null;

            MySqlConnection connection = new MySqlConnection(ConfigurationManager.AppSettings[BusinessUtilies.Const.Database.AppSetting]);
            MySqlDataAdapter adapter = new MySqlDataAdapter("CheckUser", connection);
            adapter.SelectCommand.CommandType = CommandType.StoredProcedure;

            MySqlParameter paramID = new MySqlParameter("pEmail", email);
            paramID.Direction = ParameterDirection.Input;
            adapter.SelectCommand.Parameters.Add(paramID);

            MySqlParameter paramPassword = new MySqlParameter("pPassword", password);
            paramPassword.Direction = ParameterDirection.Input;
            adapter.SelectCommand.Parameters.Add(paramPassword);

            DataTable results = new DataTable();

            adapter.Fill(results);

            if (results.Rows.Count > 0)
            {
                DataRow item = results.Rows[0];

                user = new UserDataModel();

                user.ID = Convert.ToInt32(item["ID"]);
                user.FirstName = Convert.ToString(item["FirstName"]);
                user.LastName = Convert.ToString(item["LastName"]);
                user.Email = Convert.ToString(item["Email"]);
                user.Password = Convert.ToString(item["Password"]);
                if (item["DateCreated"].GetType() != typeof(DBNull))
                {
                    user.DateCreated = Convert.ToDateTime(item["DateCreated"]);
                }
                if (item["CreatedBy"].GetType() != typeof(DBNull))
                {
                    user.CreatedBy = Convert.ToInt32(item["CreatedBy"]);
                }
                user.Rol = Convert.ToString(item["Role"]);
            }

            return user;
        }
Пример #36
0
        void CreateDefaultFolders(UserDataModel model)
        {
            try
            {
                List<Folder> folders = UserConstants.DefaultFolders(this.CurrentUser);
                foreach (var folder in folders)
                {
                    // child items must be added AFTER saving parent items
                    // EF cannot determine which items are dependent on eachother
                    List<Item> folderItems = new List<Item>();
                    List<Item> childItems = new List<Item>();
                    foreach (var item in folder.Items)
                    {
                        if (item.ParentID == null) { folderItems.Add(item); }
                        else childItems.Add(item);
                    }
                    folder.Items = folderItems;
                    model.StorageContext.Folders.Add(folder);
                    model.StorageContext.SaveChanges();

                    if (childItems.Count > 0)
                    {
                        foreach (var item in childItems)
                        {
                            model.StorageContext.Items.Add(item);
                        }
                        model.StorageContext.SaveChanges();
                    }
                }

                // create an operation corresponding to the new user creation
                var operation = model.StorageContext.CreateOperation(this.CurrentUser, "POST", (int?)HttpStatusCode.Created, this.CurrentUser, null);

                // kick off the New User workflow
                WorkflowHost.WorkflowHost.InvokeWorkflowForOperation(model.StorageContext, null, operation);
            }
            catch (Exception ex)
            {
                TraceLog.TraceException("CreateDefaultFolders failed", ex);
                throw;
            }
        }
Пример #37
0
 public ActionResult Initialize(int id = 0)
 {
     UserDataModel model = new UserDataModel(this);
     try
     {
         if (model.UserData.Folders.Count == 0)
         {   // only create default folders if no folders exist
             CreateDefaultFolders(model);
         }
     }
     catch (Exception)
     {
         if (id++ < 3)
         {   // retry upto 3 times before giving up
             return RedirectToAction("Initialize", "Dashboard", new { id = id });
         }
     }
     // redirect to profile wizard after registration
     return RedirectToAction("Wizard", "UserInfo");
 }
        public static UserDTO ToUserDTO(UserDataModel datamodel)
        {
            UserDTO dto = new UserDTO();
            if (datamodel != null)
            {
                dto.UserID = datamodel.UserID;
                dto.UserName = datamodel.UserName;
                dto.FirstName = datamodel.FirstName;
                dto.MiddleName = datamodel.MiddleName;
                dto.LastName = datamodel.LastName;
                dto.DOB = datamodel.DOB;
                dto.IsActive = datamodel.IsActive;
                dto.IsDeleted = datamodel.IsDeleted;
                dto.insuser = datamodel.insuser;
                dto.insdt = datamodel.insdt;
                dto.upduser = datamodel.upduser;
                dto.upddt = datamodel.upddt;
            }

            return dto;
        }
Пример #39
0
        public ActionResult Home(bool renewFBToken = false, string consentStatus = null)
        {
            UserDataModel model = new UserDataModel(this);
            try
            {
                // force access to validate current user
                var userData = model.UserData;
                model.RenewFBToken = renewFBToken;
                model.ConsentStatus = consentStatus;
                // TODO: if consent fails, un-Choose the Suggestion

                // if this is a mobile client, redirect to the mobile page
                if (Request.Url.PathAndQuery == "/" && BrowserAgent.IsMobile(Request.UserAgent))
                    return RedirectToAction("Home", "Mobile");
            }
            catch
            {
                return RedirectToAction("SignOut", "Account");
            }
            return View(model);
        }
Пример #40
0
        public void CreateAndLogin(UserDataModel user)
        {
            UserDataModel dbUser = UserDAL.GetUserByEmail(user.Email);
            //if user does not exist, then create him
            if(dbUser == null)
            {
                user.Password = EncryptionManager.MD5Encrypt("12345");
                user.DateCreated = DateTime.Now;
                user.CreatedBy = UserDAL.GetUserByEmail("admin").ID;

                UserDAL.Create(user);

                dbUser = CheckUser(user.Email, EncryptionManager.MD5Encrypt("12345"));
                dbUser.Rol = "";
            }

            SecurityManager.Login(new SecurityUserModel() {
                ID = dbUser.ID,
                Email = dbUser.Email,
                Role = !String.IsNullOrEmpty(dbUser.Rol) && dbUser.Rol == UserRole.Admin.ToString() ? UserRole.Admin : UserRole.Visitor
            });
        }
Пример #41
0
        public override void Update(UserDataModel user)
        {
            if (!String.IsNullOrEmpty(user.NewPassword))
            {
                user.Password = EncryptionManager.MD5Encrypt(user.NewPassword);
            }

            base.Update(user);
        }
Пример #42
0
 public virtual void Create(UserDataModel user)
 {
     UserDAL.Create(user);
 }
        private void RegisterUser()
        {
            List<RoleDataModel> userRoles = new List<RoleDataModel>();
            RoleDataService rService = new RoleDataService();
            GroupDataModel group = null;
            RoleDataModel role;
            UserRole selectedRole;

            if (_ViewModel.IsTeacher)
                selectedRole = UserRole.Teacher;
            else
                selectedRole = UserRole.Student;

            role = rService.GetRole(selectedRole);

            if (role != null)
            {
                userRoles.Add(role);
            }
            // such role not exist in db? - create it!
            else
            {
                role = new RoleDataModel();
                role.Role = selectedRole;

                if (selectedRole == UserRole.Student)
                {
                    role.Name = "Student";

                    GroupDataService gService = new GroupDataService();
                    group = gService.GetGroup(_ViewModel.SelectedGroup);
                    if (group == null)
                    {
                        group = gService.CreateGroup(_ViewModel.SelectedGroup);
                    }
                }
                else
                {
                    role.Name = "Teacher";
                }

                rService.Add(role);
                userRoles.Add(rService.GetRole(selectedRole));
            }

            // adding group to UserDM if registering student
            if (selectedRole == UserRole.Student)
            {
                GroupDataService gService = new GroupDataService();
                group = gService.GetGroup(_ViewModel.SelectedGroup);
                if (group == null)
                {
                    group = gService.CreateGroup(_ViewModel.SelectedGroup);
                }
            }

            // create new user object for write to db
            UserDataModel newUser = new UserDataModel
            {
                Username = _ViewModel.Username,
                Email = _ViewModel.Email,
                Password = Authentication.HashPassword(_ViewModel.Password),
                FirstName = _ViewModel.Name,
                LastName = _ViewModel.Surname,
                MiddleName = _ViewModel.MiddleName,
                Group = group,
                Roles = userRoles
            };

            UserDataService uService = new UserDataService();
            uService.Add(newUser);
            MessageBox.Show(Messages.RegisterSuccessfull, Messages.CaptionRegistered);
            this.Close();
        }
Пример #44
0
        public static UserDataModel ToDataModel(UserDTO oUserDTO, AddressDTO oPrimaryAddressDTO, PhoneDTO oPrimaryPhoneDTO, EmailDTO oPrimaryEmailDTO) {

            UserDataModel oUserDataModel = null;

            if (oUserDTO != null)
            {
                oUserDataModel = new UserDataModel
                {
                    UserID = oUserDTO.UserID,
                    UserName = oUserDTO.UserName,
                    FirstName = oUserDTO.FirstName,
                    MiddleName = oUserDTO.MiddleName,
                    LastName = oUserDTO.LastName,
                    DOB = oUserDTO.DOB,
                    IsActive = oUserDTO.IsActive,
                    IsDeleted = oUserDTO.IsDeleted,
                    insuser = oUserDTO.insuser,
                    insdt = oUserDTO.insdt,
                    upduser = oUserDTO.upduser,
                    upddt = oUserDTO.upddt
                };

                if (oPrimaryAddressDTO != null)
                {
                    oUserDataModel.PrimayAddress_AddressID = oPrimaryAddressDTO.AddressID;
                    oUserDataModel.PrimaryAddressTitle = oPrimaryAddressDTO.Title;
                    oUserDataModel.PrimaryAddressLine1 = oPrimaryAddressDTO.Line1;
                    oUserDataModel.PrimaryAddressLine2 = oPrimaryAddressDTO.Line2;
                    oUserDataModel.PrimaryAddressLine3 = oPrimaryAddressDTO.Line3;
                    oUserDataModel.PrimaryAddressCity = oPrimaryAddressDTO.City;
                    oUserDataModel.PrimaryAddressState = oPrimaryAddressDTO.State;
                    oUserDataModel.PrimaryAddressZipCode = oPrimaryAddressDTO.ZipCode;
                    oUserDataModel.PrimaryAddressCountryID = oPrimaryAddressDTO.CountryID;
                    oUserDataModel.PrimaryAddressCountryName = oPrimaryAddressDTO.Country.Name;
                    oUserDataModel.PrimaryAddressCountryAbbreviation = oPrimaryAddressDTO.Country.Abbreviation;
                    oUserDataModel.PrimaryAddressCountryCode = oPrimaryAddressDTO.Country.Code;
                    oUserDataModel.PrimaryAddressCountryPhoneCode = oPrimaryAddressDTO.Country.PhoneCode;
                    
                    oUserDataModel.PrimaryAddressTypeID = oPrimaryAddressDTO.AddressTypeID;
                    oUserDataModel.PrimaryAddressTypeName = oPrimaryAddressDTO.TypeCode.Name;
                    oUserDataModel.PrimaryAddressTypeCode = oPrimaryAddressDTO.TypeCode.Code;
                    oUserDataModel.PrimaryAddressTypeDescription = oPrimaryAddressDTO.TypeCode.Description;
                    oUserDataModel.PrimaryAddressTypeClassTypeID = oPrimaryAddressDTO.TypeCode.ClassTypeID;

                }

                if (oPrimaryPhoneDTO != null)
                {
                    oUserDataModel.PrimaryPhone_PhoneID = oPrimaryPhoneDTO.PhoneID;
                    oUserDataModel.PrimaryPhoneNumber = oPrimaryPhoneDTO.Number;
                    oUserDataModel.PrimaryPhoneExt = oPrimaryPhoneDTO.Ext;

                    oUserDataModel.PrimaryPhoneTypeID = oPrimaryPhoneDTO.TypeCode.TypeCodeID;
                    oUserDataModel.PrimaryPhoneTypeName = oPrimaryPhoneDTO.TypeCode.Name;
                    oUserDataModel.PrimaryPhoneTypeCode = oPrimaryPhoneDTO.TypeCode.Code;
                    oUserDataModel.PrimaryPhoneTypeDescription = oPrimaryPhoneDTO.TypeCode.Description;
                    oUserDataModel.PrimaryPhoneTypeClassTypeID = oPrimaryPhoneDTO.TypeCode.ClassTypeID;

                }
                
                if (oPrimaryEmailDTO != null)
                {
                    oUserDataModel.PrimaryEmail_EmailID = oPrimaryEmailDTO.EmailID;
                    oUserDataModel.PrimaryEmailAddress = oPrimaryEmailDTO.Address;

                    oUserDataModel.PrimaryEmailTypeID = oPrimaryPhoneDTO.TypeCode.TypeCodeID;
                    oUserDataModel.PrimaryEmailTypeName = oPrimaryEmailDTO.TypeCode.Name;
                    oUserDataModel.PrimaryEmailTypeCode = oPrimaryEmailDTO.TypeCode.Code;
                    oUserDataModel.PrimaryEmailTypeDescription = oPrimaryEmailDTO.TypeCode.Description;
                    oUserDataModel.PrimaryEmailTypeClassTypeID = oPrimaryEmailDTO.TypeCode.ClassTypeID;

                }
            }

            return oUserDataModel;
        }
Пример #45
0
        public HttpResponseMessageWrapper<User> GetCurrentUser(HttpRequestMessage req)
        {
            Operation operation = null;
            HttpStatusCode code = AuthenticateUser(req);
            if (code != HttpStatusCode.OK)
            {   // user not authenticated
                return ReturnResult<User>(req, operation, code);
            }

            try
            {
                UserDataModel model = new UserDataModel(this);
                // make sure the response isn't cached
                var response = ReturnResult<User>(req, operation, model.UserData, HttpStatusCode.OK);
                response.Headers.CacheControl = new CacheControlHeaderValue() { NoCache = true };
                return response;
            }
            catch (Exception)
            {   // no such user account - return 404 Not Found
                return ReturnResult<User>(req, operation, HttpStatusCode.NotFound);
            }
        }
 public static UserAccountDTO ToUserAccountDTO(UserDataModel datamodel)
 {
     UserAccountDTO model=new UserAccountDTO();
     if (datamodel != null)
     {
         model.UserAccountID = datamodel.UserAccountID;
         model.insdt = datamodel.UserAccountinsdt;
         model.insuser = datamodel.UserAccountinsuser;
         model.IsActive = datamodel.UserAccountIsActive;
         model.IsDeleted = datamodel.UserAccountIsDeleted;
         model.Password = datamodel.UserAccountPassword;
         model.upddt = datamodel.UserAccountupddt;
         model.upduser = datamodel.UserAccountupduser;
         model.UserName = datamodel.UserAccountUserName;
     }
     return model;
 }
        public static UserDataModel ToDataModel(UserDTO userDTO, UserAccountDTO accountDTO, AddressDTO addressDTO, PhoneDTO phoneDTO, EmailDTO emailDTO)
        {

            UserDataModel model = null;

            if (userDTO != null)
            {
                model = new UserDataModel
                {
                    UserID = userDTO.UserID,
                    UserName = userDTO.UserName,
                    FirstName = userDTO.FirstName,
                    MiddleName = userDTO.MiddleName,
                    LastName = userDTO.LastName,
                    DOB = userDTO.DOB,
                    IsActive = userDTO.IsActive,
                    IsDeleted = userDTO.IsDeleted,
                    insuser = userDTO.insuser,
                    insdt = userDTO.insdt,
                    upduser = userDTO.upduser,
                    upddt = userDTO.upddt
                };

                if (accountDTO != null)
                {
                    model.UserAccountID = accountDTO.UserAccountID;
                    model.UserAccountinsdt = accountDTO.insdt;
                    model.UserAccountinsuser = accountDTO.insuser;
                    model.UserAccountIsActive = accountDTO.IsActive;
                    model.UserAccountIsDeleted = accountDTO.IsDeleted;
                    model.UserAccountPassword = accountDTO.Password;
                    model.UserAccountupddt = accountDTO.upddt;
                    model.UserAccountupduser = accountDTO.upduser;
                    model.UserAccountUserName = accountDTO.UserName;
                }

                if (addressDTO != null)
                {
                    model.UserAddressAddressTypeID = addressDTO.AddressTypeID;
                    model.UserAddressCity = addressDTO.City;
                    model.UserAddressCountryID = addressDTO.CountryID;
                    model.UserAddressID = addressDTO.AddressID;
                    model.UserAddressLine1 = addressDTO.Line1;
                    model.UserAddressLine2 = addressDTO.Line2;
                    model.UserAddressLine3 = addressDTO.Line3;
                    model.UserAddressState = addressDTO.State;
                    model.UserAddressTitle = addressDTO.Title;
                    model.UserAddressZipCode = addressDTO.ZipCode;

                }

                if (phoneDTO != null)
                {
                    model.UserPhoneCountryID = phoneDTO.CountryID;
                    model.UserPhoneExt = phoneDTO.Ext;
                    model.UserPhoneID = phoneDTO.PhoneID;
                    model.UserPhoneNumber = phoneDTO.Number;
                    model.UserPhoneTypeID = phoneDTO.PhoneTypeID;
                }

                if (emailDTO != null)
                {
                    model.UserEmailAddress = emailDTO.Address;
                    model.UserEmailID = emailDTO.EmailID;
                    model.UserEmailTypeID = emailDTO.EmailTypeID;
                }
            }

            return model;
        }
        public static AddressDTO ToAddressDTO(UserDataModel datamodel)
        {
            AddressDTO dto = new AddressDTO();
            if (datamodel != null)
            {
                dto.AddressID = datamodel.UserAddressID;
                dto.AddressTypeID = datamodel.UserAddressAddressTypeID;
                dto.City = datamodel.UserAddressCity;
                dto.CountryID = datamodel.UserAddressCountryID;
                dto.Line1 = datamodel.UserAddressLine1;
                dto.Line2 = datamodel.UserAddressLine2;
                dto.Line3 = datamodel.UserAddressLine3;
                dto.State = datamodel.UserAddressState;
                dto.Title = datamodel.UserAddressTitle;
                dto.ZipCode = datamodel.UserAddressZipCode;
            }

            return dto;
        }
        public static PhoneDTO ToPhoneDTO(UserDataModel datamodel)
        {
            PhoneDTO dto = new PhoneDTO();
            if (datamodel != null)
            {
                dto.CountryID = datamodel.UserPhoneCountryID;
                dto.Ext = datamodel.UserPhoneExt;
                dto.Number = datamodel.UserPhoneNumber;
                dto.PhoneID = datamodel.UserPhoneID;
                dto.PhoneTypeID = datamodel.UserPhoneTypeID;
            }

            return dto;
        }
        public static EmailDTO ToEmailDTO(UserDataModel datamodel)
        {
            EmailDTO dto = new EmailDTO();
            if (datamodel != null)
            {
                dto.Address = datamodel.UserEmailAddress;
                dto.EmailID = datamodel.UserEmailID;
                dto.EmailTypeID = datamodel.UserEmailTypeID;
            }

            return dto;
        }