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();
        }
        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();
        }
        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));
            }
        }
 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);
 }
Beispiel #5
0
 public Question CreateQuestion(Model.User user, Question question)
 {
     throw new NotImplementedException();
 }
Beispiel #6
0
 public Feedback CreateFeedback(Model.User user, Feedback feedback)
 {
     throw new NotImplementedException();
 }
Beispiel #7
0
 public List <Notification> GetNotifications(Model.User user)
 {
     throw new NotImplementedException();
 }
Beispiel #8
0
 public Boolean ChangePassword(Model.User user, string newPassword)
 {
     throw new NotImplementedException();
 }