Ejemplo n.º 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();
        }
Ejemplo n.º 2
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);
 }