예제 #1
0
        public void Add(string description, DateTime expiryDate, Model.User userModel, Model.Category categoryModel, Model.Subcategory subcategoryModel)
        {
            if (expiryDate.CompareTo(DateTime.Today) < 0)
            {
                throw new ArgumentOutOfRangeException("Invalid expiry date: " + expiryDate + " Today: " + DateTime.Today);
            }

            NullUserModelOrCategory(userModel, categoryModel);

            var userRepo               = unitOfWork.GetRepository <IUserRepository>();
            var userGenericRepo        = unitOfWork.GetGenericRepository <IUserRepository, DAL.Model.User>();
            var categoryGenericRepo    = unitOfWork.GetGenericRepository <ICategoryRepository, DAL.Model.Category>();
            var subcategoryGenericRepo = unitOfWork.GetGenericRepository <ISubcategoryRepository, DAL.Model.Subcategory>();

            var user = userGenericRepo.Get(
                u => u.Login == userModel.Login && u.Password == userModel.Password, null, "Lots")
                       .FirstOrDefault();

            NullUserOrLowPrivilege(userModel, user);

            var category = categoryGenericRepo.Get(c => c.CategoryId == categoryModel.CategoryId).FirstOrDefault();

            if (category == null)
            {
                throw new InvalidOperationException("No category with such id: " + categoryModel.CategoryId);
            }
            var subcategory = subcategoryModel != null?subcategoryGenericRepo.Get(subcategoryModel.SubcategoryId) : null;

            var userIsAdmin =
                user.Privilege.Equals(DAL.Model.User.AdminPrivilege) ||
                user.Privilege.Equals(DAL.Model.User.ManagerPrivilege) ? user : null;

            DAL.Model.Lot lot = CreateLot(
                description,
                user,
                userIsAdmin,
                category,
                subcategory,
                expiryDate
                );

            user.Lots.Add(lot);
            unitOfWork.Update(user);
            unitOfWork.Save();
        }
예제 #2
0
        public void Delete(Model.Lot lotModel, Model.User user)
        {
            if (lotModel == null)
            {
                throw new InvalidOperationException("No lot");
            }

            var lot = genericRepo.Get(l => AuthenticateUser(lotModel, user, l));

            if (lot == null)
            {
                throw new InvalidOperationException("No such lot");
            }

            genericRepo.Delete(lotModel.LotId);

            unitOfWork.Save();
        }
예제 #3
0
        public Model.User Register(string login, string pass)
        {
            lock (Lock)
            {
                if (Authenticate(login))
                {
                    throw new InvalidOperationException("User with login: "******" - Already exist.");
                }

                var user = new Model.User {
                    Login = login, Password = pass, Privilege = DAL.Model.User.UserPrivilege
                };
                genericRepo.Insert(mapper.Map <Model.User, DAL.Model.User>(user));
                unitOfWork.Save();
                var newUser = this.repo.GetByLoginAndPass(login, pass);
                return(mapper.Map <DAL.Model.User, Model.User>(newUser));
            }
        }
예제 #4
0
 private bool AuthenticateUser(Model.Lot lotModel, Model.User user, DAL.Model.Lot lot)
 {
     return(lot.User.Login == user.Login &&
            lot.User.Password == user.Password &&
            lot.LotId == lotModel.LotId);
 }
예제 #5
0
 public Question CreateQuestion(Model.User user, Question question)
 {
     throw new NotImplementedException();
 }
예제 #6
0
 public Feedback CreateFeedback(Model.User user, Feedback feedback)
 {
     throw new NotImplementedException();
 }
예제 #7
0
 public List <Notification> GetNotifications(Model.User user)
 {
     throw new NotImplementedException();
 }
예제 #8
0
 public Boolean ChangePassword(Model.User user, string newPassword)
 {
     throw new NotImplementedException();
 }