public IHttpActionResult Signup(RegisterReqViewModel registerReqViewModel)
        {
            if (registerReqViewModel.Password != registerReqViewModel.ConfirmPassword)
                return BadRequest("Password mismatched");

            var farmer = new Farmer
                             {
                                 Address = registerReqViewModel.Address,
                                 FullName = registerReqViewModel.FullName,
                                 MobileNumber = registerReqViewModel.MobileNumber,
                                 Password = registerReqViewModel.Password,
                                 PhotoUrl = registerReqViewModel.PhotoUrl
                             };
            if (!_accountService.Signup(farmer))
            {
                return BadRequest("User exists");
            }

            var registerResViewModel = new RegisterResViewModel
                                           {
                                               FarmerId = farmer.FarmerId,
                                               TokenValue = new AuthService(new AppContext()).CreateAuthToken(farmer.FarmerId)
                                           };
            return Ok(registerResViewModel);
        }
Пример #2
0
        public String Signin(Farmer farmerSigninInfo)
        {
            var farmer = _farmerRepository.GetFarmer(farmerSigninInfo.MobileNumber);
            if (farmer.Equals(null))
                return null;
            if (!farmer.Password.Equals(Encryption.GetHash(farmerSigninInfo.Password)))
                return null;

            return _authService.CreateAuthToken(farmer.FarmerId);
        }
Пример #3
0
 public bool Signup(Farmer farmer)
 {
     if (_farmerRepository.GetFarmer(farmer.MobileNumber) != null)
     {
         return false;
     }
     farmer.Password = Encryption.GetHash(farmer.Password);
     _farmerRepository.AddFarmer(farmer);
     return true;
 }
 public bool UpdateFarmer(Farmer farmer)
 {
     var oldFarmer = _appContext.Farmers.FirstOrDefault(f => f.FarmerId.Equals(farmer.FarmerId));//GetFarmer(farmer.MobileNumber);
     oldFarmer.FullName = farmer.FullName;
     oldFarmer.Address = farmer.Address;
     oldFarmer.PhotoUrl = farmer.PhotoUrl;
     oldFarmer.Password = Encryption.GetHash(farmer.Password);
     _appContext.Entry(oldFarmer).State = EntityState.Modified;
     return _appContext.SaveChanges() > 0;
 }
 public void Init()
 {
     _farmer = new Farmer()
     {
         Address = "ঢাকা",
         FullName = "রাশেদ",
         MobileNumber = "০১৬৭২৪১৩১৪৬",
         Password = "******",
         PhotoUrl = "Url"
     };
 }
        public IHttpActionResult Signin(LoginReqViewModel loginReqViewModel)
        {
            var farmer = new Farmer
                             {
                                 MobileNumber = loginReqViewModel.MobileNumber,
                                 Password = loginReqViewModel.Password
                             };
            var tokenValue = _accountService.Signin(farmer);

            if (tokenValue == null)
            {
                return BadRequest("Wrong username or password");

            }

            var loginResViewModel = new LoginResViewModel
                                                      {
                                                          FarmerId =
                                                              _farmerService.GetFarmer(loginReqViewModel.MobileNumber).FarmerId,
                                                          TokenValue = tokenValue

                                                      };
            return Ok(loginResViewModel);
        }
Пример #7
0
 public bool UpdateAccount(Farmer farmer)
 {
     return _farmerRepository.UpdateFarmer(farmer);
 }
Пример #8
0
 public bool Signout(Farmer farmer)
 {
     _authService.DeleteToken(farmer.FarmerId);
     return true;
 }
 public bool DeleteFarmer(Farmer farmer)
 {
     _appContext.Farmers.Remove(farmer);
     return _appContext.SaveChanges() > 0;
 }
Пример #10
0
 public int AddFarmer(Farmer farmer)
 {
     _appContext.Farmers.Add(farmer);
     _appContext.SaveChanges();
     return farmer.FarmerId;
 }
        public IHttpActionResult EditAccount(RegisterUpdateReqViewModel registerUpdateReqViewModel)
        {
            var farmer = new Farmer
            {
                FarmerId = registerUpdateReqViewModel.FarmerId,
                Address = registerUpdateReqViewModel.Address,
                FullName = registerUpdateReqViewModel.FullName,
                MobileNumber = registerUpdateReqViewModel.MobileNumber,
                Password = registerUpdateReqViewModel.Password,
                PhotoUrl = registerUpdateReqViewModel.PhotoUrl
            };

            if (_accountService.UpdateAccount(farmer))
            {
                return Ok("updated");
            }
            return BadRequest("Can't update");
        }
 public IHttpActionResult Signout(FarmerIdReqViewModel farmerIdReqViewModel)
 {
     var farmer = new Farmer
                      {
                          FarmerId = farmerIdReqViewModel.FarmerId
                      };
     if (_accountService.Signout(farmer))
     {
         return Ok("Signout");
     }
     return BadRequest("Cannot signout");
 }