Esempio n. 1
0
        public async Task<ReturnModel<UserModel>> Create (UserModel userModel)
        {
            var result = new ReturnModel<UserModel> { Status = true };
            using(var session = new UnitOfWork<FoodMenuEntities>())
            {
                var userRepository = session.GetRepository<IUserRepository>();

                if(!(await userRepository.ValidateEmail(userModel.Email,userModel.Id)))
                {
                    result.Error = ("כתובת האמייל כבר בשימוש.");
                    result.Status = false;
                    return result;
                }

                var user = new User();
                user.Id = userModel.Id;
                user.Email = userModel.Email;
                user.Password = userModel.Password;
                user.FirstName = userModel.FirstName;
                user.LastName = userModel.LastName;
                user.BusinessId = userModel.BusinessId;
                user.Address = userModel.Address;
                user.IsActive = true;
                userRepository.Add(user);

                await session.SaveChangesAsync();

                userModel.Id = user.Id;
                userModel.Token = Guid.NewGuid().ToString();
                result.Result = userModel;
                return result;
            }
        }
Esempio n. 2
0
        public async Task InserUser_OK ()
        {
            var user = new UserModel();

            var ticks = DateTime.Now.Ticks.ToString().Substring(6);
            user.Email = $"mbearz{ticks}@gmail.com";
            user.Password = "******";
            user.FirstName = "michael";
            user.LastName = "berezin";

            var id = await usersBL.Create(user);
            Assert.AreNotEqual(id,0);
        }
Esempio n. 3
0
        public async Task<ReturnModel<UserModel>> Login (string email,string password,bool refresh = true)
        {
            UserModel model = new UserModel();
            using(var session = new UnitOfWork<FoodMenuEntities>())
            {
                var userRepository = session.GetRepository<IUserRepository>();

                var user = await userRepository.GetUserByEmailAndPassword(email,password);

                var token = refresh ? Guid.NewGuid().ToString() : user.Token;

                user.Token = token;
                await session.SaveChangesAsync();

                var result = new ReturnModel<UserModel>();
                result.Result = user == null ? null : new UserModel()
                {
                    Id = user.Id,
                    Email = user.Email,
                    Password = user.Password,
                    FirstName = user.FirstName,
                    LastName = user.LastName,
                    Token = token
                };

                result.Status = user != null;
                result.Error = "שם משתמש או סיסמה לא נכונים";

                return result;
            }
        }
Esempio n. 4
0
        public async Task<ReturnModel<UserModel>> Authenticate (int userId,string token)
        {
            var res = new ReturnModel<UserModel>();
            UserModel model = new UserModel();
            using(var session = new UnitOfWork<FoodMenuEntities>())
            {
                var userRepository = session.GetRepository<IUserRepository>();

                var user = await userRepository.Authenticate(userId,token);

                res.Result = user == null ? null : new UserModel()
                {
                    Id = user.Id,
                    Email = user.Email,
                    Password = user.Password,
                    FirstName = user.FirstName,
                    LastName = user.LastName,
                    Token = user.Token
                };
                res.Status = user != null;
                return res;
            }
        }
Esempio n. 5
0
        public async Task<ReturnModel<bool>> Update (UserModel userModel)
        {
            using(var session = new UnitOfWork<FoodMenuEntities>())
            {
                var userRepository = session.GetRepository<IUserRepository>();

                var user = await userRepository.GetByID(userModel.Id);

                user.Id = userModel.Id;
                user.Email = userModel.Email;
                user.Password = userModel.Password;
                user.FirstName = userModel.FirstName;
                user.LastName = userModel.LastName;
                user.BusinessId = userModel.BusinessId;
                user.Address = userModel.Address;
                await session.SaveChangesAsync();

                return new ReturnModel<bool> { Status = true };
            }
        }
Esempio n. 6
0
        public async Task<ReturnModel<UserModel>> GetByID (int userID)
        {
            UserModel model = new UserModel();
            using(var session = new UnitOfWork<FoodMenuEntities>())
            {
                var userRepository = session.GetRepository<IUserRepository>();

                var user = await userRepository.GetByID(userID);

                return new ReturnModel<UserModel>
                {
                    Status = true,
                    Result = new UserModel()
                    {
                        Id = user.Id,
                        Email = user.Email,
                        Password = user.Password,
                        FirstName = user.FirstName,
                        LastName = user.LastName,
                        BusinessId = user.BusinessId,
                        Address = user.Address,
                        LogoFile = user.LogoFile
                    }
                };
            };
        }
Esempio n. 7
0
 public async Task<ReturnModel<bool>> Put (int id,UserModel user)
 {
     user.Id = id;
     return await usersBl.Update(user);
 }
Esempio n. 8
0
 //[AllowAnonymous]
 public async Task<ReturnModel<UserModel>> Post (UserModel user)
 {
     return await usersBl.Create(user);
 }