Esempio n. 1
0
 public UserPhonesModel(UserPhone mobile, UserPhone work, UserPhone home, UserPhone additional)
 {
     Mobile     = mobile;
     Work       = work;
     Home       = home;
     Additional = additional;
 }
        public void Post([FromBody] UserPhone phone)
        {
            RegisterUsers registerUsers = new RegisterUsers();

            registerUsers.Name                      = phone.Name;
            registerUsers.Surname                   = phone.Surname;
            registerUsers.RegisterUsersPhones       = new RegisterUsersPhones();
            registerUsers.RegisterUsersPhones.Phone = phone.Phone;

            databaseBTCContext.RegisterUsers.Add(registerUsers);
            databaseBTCContext.SaveChanges();

            ValidationCodes validationCodes = new ValidationCodes();

            validationCodes.IdUser = registerUsers.IdUser;

            databaseBTCContext.ValidationCodes.Add(validationCodes);
            databaseBTCContext.SaveChanges();

            Wallet wallet = new Wallet();

            wallet.AdressName = string.Format("Wallet adress for: {0}", validationCodes.IdCode);
            wallet.IdCode     = validationCodes.IdCode;

            databaseBTCContext.Wallet.Add(wallet);
            databaseBTCContext.SaveChanges();

            sendSms(registerUsers, validationCodes);
        }
Esempio n. 3
0
        /// <inheritdoc />
        public async Task <UserPhone> CreateUserPhoneAsync(UserPhone userPhone)
        {
            using (var connection = new SqlConnection(_connectionString))
            {
                connection.Open();

                var command = connection.CreateCommand();

                command.CommandType = System.Data.CommandType.Text;
                command.CommandText = @"INSERT INTO [dbo].[UserPhone] 
                                            (UserId, AreaCode, PhoneNumber)
                                        VALUES
                                            (@UserId, @AreaCode, @PhoneNumber)
                                        SELECT SCOPE_IDENTITY();";

                command.Parameters.AddWithValue("UserId", userPhone.UserId);
                command.Parameters.AddWithValue("AreaCode", userPhone.AreaCode);
                command.Parameters.AddWithValue("PhoneNumber", userPhone.PhoneNumber);

                var commandResult = await command.ExecuteScalarAsync();

                userPhone.Id = long.Parse(commandResult.ToString());

                connection.Close();
            }

            return(userPhone);
        }
Esempio n. 4
0
        public async Task <IActionResult> PutUserPhone([FromRoute] string id, [FromBody] UserPhone userPhone)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userPhone.UserName)
            {
                return(BadRequest());
            }

            _context.Entry(userPhone).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserPhoneExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 5
0
 private void btnDelete2_Click(object sender, EventArgs e)
 {
     try
     {
         if (cbxList2.SelectedIndex == 0)
         {
             int id = Convert.ToInt32(dgwAddPart.CurrentRow.Cells[0].Value);
             _userPhone = _wrt.UserPhones.FirstOrDefault(p => p.Id == id);
             _wrt.UserPhones.DeleteOnSubmit(_userPhone);
             _wrt.SubmitChanges();
             GetUserPhoneTable();
             MessageBox.Show("Entity deleted successfully");
             tbxNameIki.Text = "";
         }
         else if (cbxList2.SelectedIndex == 1)
         {
             int id = Convert.ToInt32(dgwAddPart.CurrentRow.Cells[0].Value);
             _ManagementPhone = _wrt.ManagementPhones.FirstOrDefault(p => p.Id == id);
             _wrt.ManagementPhones.DeleteOnSubmit(_ManagementPhone);
             _wrt.SubmitChanges();
             GetManagementPhoneTable();
             MessageBox.Show("Entity deleted successfully");
             tbxNameIki.Text = "";
         }
         else if (cbxList2.SelectedIndex == 2)
         {
             int id = Convert.ToInt32(dgwAddPart.CurrentRow.Cells[0].Value);
             _ManagementShelter = _wrt.ManagementShelters.FirstOrDefault(p => p.Id == id);
             _wrt.ManagementShelters.DeleteOnSubmit(_ManagementShelter);
             _wrt.SubmitChanges();
             GetManagementShelterTable();
             MessageBox.Show("Entity deleted successfully");
             tbxNameIki.Text = "";
         }
         else if (cbxList2.SelectedIndex == 3)
         {
             int id = Convert.ToInt32(dgwAddPart.CurrentRow.Cells[0].Value);
             _rOf = _wrt.ResponsibleOfManagements.FirstOrDefault(p => p.Id == id);
             _wrt.ResponsibleOfManagements.DeleteOnSubmit(_rOf);
             _wrt.SubmitChanges();
             GetResponsibleOfManagementTable();
             MessageBox.Show("Entity deleted successfully");
             tbxNameIki.Text = "";
         }
         else if (cbxList2.SelectedIndex == 4)
         {
             int id = Convert.ToInt32(dgwAddPart.CurrentRow.Cells[0].Value);
             _sOu = _wrt.ShelterOfUsers.FirstOrDefault(p => p.Id == id);
             _wrt.ShelterOfUsers.DeleteOnSubmit(_sOu);
             _wrt.SubmitChanges();
             GetShelterOfUserTable();
             MessageBox.Show("Entity deleted successfully");
             tbxNameIki.Text = "";
         }
     }
     catch
     {
         MessageBox.Show("We got a problem on the system.Try it another time.");
     }
 }
        public async Task <ActionResult> Reset(ResetViewData model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            UserPhone phone =
                _db.UserPhones.SingleOrDefault(x => x.UserID == model.Item.ID && x.ConfirmCode == model.Item.ConfirmCode);

            if (phone == null)
            {
                ModelState.AddModelError("ConfirmCode", "Не верный код подтверждения");
                return(View(model));
            }

            phone.Confirm = true;

            UserInformation entity = phone.User;

            _userManager.RemovePassword(entity.User.Id);

            IdentityResult result = await _userManager.AddPasswordAsync(entity.User.Id, model.Item.Password);

            await SignInAsync(entity.User, true);

            await _db.SaveChangesAsync();

            return(RedirectToAction("Index", "Home"));
        }
 public void Save(UserPhone phone, string currentUser, string userId)
 {
     if (phone.Id == 0)
     {
         phone.DateCreated = DateTime.UtcNow;
         phone.DateUpdated = DateTime.UtcNow;
         phone.CreatedBy   = currentUser;
         phone.UpdatedBy   = currentUser;
         context.Phones.Add(phone);
     }
     else
     {
         UserPhone dbEntry = context.Phones.Find(phone.Id);
         if (dbEntry != null)
         {
             dbEntry.Name        = phone.Name;
             dbEntry.Description = phone.Description;
             dbEntry.UserId      = userId;
             dbEntry.DateUpdated = DateTime.UtcNow;
             dbEntry.UpdatedBy   = currentUser;
             dbEntry.Phone       = phone.Phone;
         }
     }
     context.SaveChanges();
 }
Esempio n. 8
0
        public UserPhone CreateUserPhone(UserPhone userPhone)
        {
            db.UserPhones.Add(userPhone);
            db.SaveChanges();

            return(userPhone);
        }
Esempio n. 9
0
        public async Task <PhoneDto> AddPhone(AddPhoneDto addPhoneDto)
        {
            var user = await _repository.GetById(addPhoneDto.objectId);

            if (user == null)
            {
                return(null);
            }
            await _repository.LoadCollection(user, c => c.UserPhones);

            if (user.UserPhones.All(c => c.Phone == addPhoneDto.Phone))
            {
                return(null);
            }
            var phone = new UserPhone()
            {
                UserId = user.Id,
                Phone  = addPhoneDto.Phone
            };

            user.UserPhones.Add(phone);
            await _repository.Update(user);

            if (user.CanWorkAsAgent)
            {
                RemoveCash();
            }
            return(_mapper.Map <PhoneDto>(phone));
        }
Esempio n. 10
0
        public IHttpActionResult PutUserPhone(int id, UserPhone userPhone)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userPhone.UserPhoneID)
            {
                return(BadRequest());
            }

            db.Entry(userPhone).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserPhoneExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 11
0
        public async Task <IActionResult> PostUserPhone([FromBody] UserPhone userPhone)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.UserPhone.Add(userPhone);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (UserPhoneExists(userPhone.UserName))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetUserPhone", new { id = userPhone.UserName }, userPhone));
        }
 /// <summary>
 /// Invoked when <see cref="ToDTO"/> operation is about to return.
 /// </summary>
 /// <param name="dto"><see cref="UserPhoneDTO"/> converted from <see cref="UserPhone"/>.</param>
 static partial void OnDTO(this UserPhone entity, UserPhoneDTO dto)
 {
     if (entity != null && entity.Phone != null)
     {
         dto.Phone = PhoneAssembler.ToDTO(entity.Phone);
     }
 }
Esempio n. 13
0
        public UserPhone Create(UserPhone oUserPhone)
        {
            if (oUserPhone != null)
            {
                return(oUserPhoneRepo.CreateUserPhone(oUserPhone));
            }

            return(null);
        }
Esempio n. 14
0
        public async Task <Result> SavePhoneAsync(string newNumber, string?verificationCode)
        {
            if (_me.IsAnonymous)
            {
                return(new Failure("需要先登录"));
            }

            if (newNumber.StartsWith('+'))
            {
                newNumber = newNumber.Substring(1);
            }
            if (newNumber.StartsWith("86"))
            {
                newNumber = newNumber.Substring(2);
            }

            if (!newNumber.IsMobileNumber())
            {
                return(new Failure("格式错误"));
            }
            if (_db.UserPhones.Any(x => x.UserId != _me.Id && x.Number == newNumber))
            {
                return(new Failure($"{newNumber.Mask()} 已被其它帐号使用"));
            }

            if (verificationCode != null)
            {
                var twoFactor    = _me.ServiceProvider.GetRequiredService <ITwoFactorManager>();
                var verifyResult = await twoFactor.VerifyCodeAsync(newNumber, verificationCode, true);

                if (!verifyResult.Ok)
                {
                    return(verifyResult);
                }
            }

            var userPhone = await _db.UserPhones.FindAsync(_me.Id);

            if (userPhone == null)
            {
                userPhone = new UserPhone {
                    UserId = _me.Id
                };
                _db.UserPhones.Add(userPhone);
            }
            else if (userPhone.Number != newNumber)
            {
                userPhone.Number     = newNumber;
                userPhone.IsVerified = verificationCode != null;
            }

            await _db.Normalize().SaveChangesAsync();

            return(new Success());
        }
        public ActionResult Delete(int phoneId)
        {
            UserPhone deletedPhone = repository.Delete(phoneId);

            if (deletedPhone != null)
            {
                TempData["message"] = string.Format("{0} was deleted",
                                                    deletedPhone.Name);
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 16
0
        public IHttpActionResult GetUserPhone(int id)
        {
            UserPhone userPhone = db.UserPhones.Find(id);

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

            return(Ok(userPhone));
        }
        public UserPhone Delete(int phoneId)
        {
            UserPhone dbEntry = context.Phones.Find(phoneId);

            if (dbEntry != null)
            {
                context.Phones.Remove(dbEntry);
                context.SaveChanges();
            }
            return(dbEntry);
        }
Esempio n. 18
0
        public IHttpActionResult PostUserPhone(UserPhone userPhone)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.CreateUserPhone(userPhone);

            return(CreatedAtRoute("DefaultApi", new { id = userPhone.UserPhoneID }, userPhone));
        }
Esempio n. 19
0
        public UserPhoneDTO Get(int UserPhoneID)
        {
            UserPhoneDTO oUserPhoneDTO = null;

            if (UserPhoneID > 0)
            {
                UserPhone oUserPhone = oUserPhoneRepo.GetUserPhone(UserPhoneID);
            }

            return(oUserPhoneDTO);
        }
Esempio n. 20
0
 private async Task ChangePhone(UserPhone oldPhone, PhoneViewModel newPhone, PhoneType phoneType)
 {
     if ((oldPhone == null && newPhone != null) ||
         (oldPhone != null && newPhone != null))
     {
         await _userProvider.UpsertUserPhone(phoneType, _mapper.Map <UserPhone>(newPhone));
     }
     else if (oldPhone != null)
     {
         await _userProvider.DeleteUserPhone(phoneType, oldPhone);
     }
 }
Esempio n. 21
0
 public void SaveUserPhone(UserPhone entity)
 {
     if (entity.Id == default)
     {
         context.Entry(entity).State = EntityState.Added;
     }
     else
     {
         context.Entry(entity).State = EntityState.Modified;
     }
     context.SaveChanges();
 }
Esempio n. 22
0
        public async Task <Result> UsePhone(string newNumber, string verificationCode)
        {
            if (_me.IsAnonymous)
            {
                return(new Failure("需要先登录"));
            }

            if (newNumber.StartsWith('+'))
            {
                newNumber = newNumber.Substring(1);
            }
            if (newNumber.StartsWith("86"))
            {
                newNumber = newNumber.Substring(2);
            }

            if (!newNumber.IsMainlandMobile())
            {
                return(new Failure("格式错误"));
            }
            if (_db.UserPhones.Any(x => x.UserId != _me.Id && x.Number == newNumber))
            {
                return(new Failure($"{newNumber.Mask()} 已被其它帐号使用"));
            }

            var verifyModel = new TwoFactorModel {
                SendTo = newNumber, Code = verificationCode
            };
            var verifyResult = await _me.TwoFactor().VerifyTwoFactorCode(verifyModel, true);

            if (!verifyResult.Ok)
            {
                return(verifyResult);
            }

            var userPhone = _db.UserPhones.Find(_me.Id);

            if (userPhone == null)
            {
                userPhone = new UserPhone {
                    UserId = _me.Id
                };
                _db.UserPhones.Add(userPhone);
            }

            userPhone.Number     = newNumber;
            userPhone.IsVerified = true;

            await _db.Normalize().SaveChangesAsync();

            return(new Success());
        }
Esempio n. 23
0
        public void UpdateUserPhone(int id, UserPhone userPhone)
        {
            db.Entry(userPhone).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
        }
Esempio n. 24
0
        public IHttpActionResult DeleteUserPhone(int id)
        {
            UserPhone userPhone = db.UserPhones.Find(id);

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

            db.UserPhones.Remove(userPhone);
            db.SaveChanges();

            return(Ok(userPhone));
        }
Esempio n. 25
0
        public UserPhone DeleteUserPhone(int id)
        {
            UserPhone userPhone = db.UserPhones.Find(id);

            if (userPhone == null)
            {
                return(null);
            }

            db.UserPhones.Remove(userPhone);
            db.SaveChanges();

            return(userPhone);
        }
Esempio n. 26
0
        public async void ResetSecurityCode_Should_Call_All_Require_Parameters()
        {
            _userPhoneRepositoryMock = new Mock <IUserPhoneRepository>();
            var userPhone = new UserPhone();

            _userPhoneRepositoryMock.Setup(c => c.GetAsync(1234)).ReturnsAsync(userPhone);
            _userPhoneRepositoryMock.Setup(c => c.UpdateAsync(It.IsAny <UserPhone>())).ReturnsAsync(userPhone);
            _userPhoneRepositoryMock.Setup(c => c.SaveChangesAsync()).ReturnsAsync(1);
            _phoneService = new PhoneService(_userManager, _mapperFixture.MapperInstance, _userPhoneRepositoryMock.Object);

            await _phoneService.InsertSecurityCodeAsync(1234, "code");

            _userPhoneRepositoryMock.VerifyAll();
        }
Esempio n. 27
0
        public void CheckUserPhone(Guid id)
        {
            UserPhone Ch = GetUserPhoneById(id);

            if (Ch.Checked == true)
            {
                Ch.Checked = false;
            }
            else
            {
                Ch.Checked = true;
            }

            context.SaveChanges();
        }
Esempio n. 28
0
        public void UpdateUserPhone(int id, UserPhone userPhone)
        {
            var user = db.UserPhones.FirstOrDefault(p => p.UserID == id);

            user = userPhone;
            db.Entry(user).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
        }
        public ActionResult Edit(EditViewData model)
        {
            if (ModelState.IsValid)
            {
                UserPhone phone =
                    _db.UserPhones.SingleOrDefault(x => x.UserID == model.Item.ID && x.ConfirmCode == model.Item.ConfirmCode);

                if (phone == null)
                {
                    ModelState.AddModelError("ConfirmCode", "Не верный код подтверждения");
                    return(View(model));
                }


                if (_db.Users.Any(x => x.UserName == model.Item.UserName))
                {
                    ModelState.AddModelError("UserName", "Такой пользователь уже есть.");
                    return(View(model));
                }

                phone.Confirm = true;

                UserInformation entity = phone.User;

                entity.FirstName = model.Item.FirstName;
                entity.LastName  = model.Item.LastName;

                var user = new User {
                    UserName = model.Item.UserName, UserInformation = entity
                };
                IdentityResult result = _userManager.Create(user, model.Item.Password);
                if (result.Succeeded)
                {
                    SignIn(user, true);

                    _db.SaveChanges();

                    return(RedirectToAction("Index", "Help"));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("UserError", error);
                }
            }

            return(View(model));
        }
 public ActionResult Edit(UserPhone phone)
 {
     if (ModelState.IsValid)
     {
         phone.CreatedBy = User.Identity.GetUserName();
         phone.UpdatedBy = User.Identity.GetUserName();
         phone.UserId    = User.Identity.GetUserId(); // dinei poianou xristi to uid??????
         repository.Save(phone, phone.CreatedBy, phone.UserId);
         TempData["message"] = string.Format("{0} has been saved", phone.Name);
         return(RedirectToAction("Index"));
     }
     else
     {
         // there is something wrong with the data values
         return(View(phone));
     }
 }