コード例 #1
0
        public ActionResult Create(AwardView awardView)
        {
            Award award = null;

            try
            {
                if (ModelState.IsValid && awardView.Image != null)
                {
                    string fileName = SetPhotoPath(awardView);
                    string path     = "/img/" + Path.GetFileName(awardView.Image.FileName);

                    award = new Award()
                    {
                        Title       = awardView.Title,
                        Description = awardView.Description,
                        ImagePath   = path
                    };

                    Repository.AddAward(award);
                    Repository.Save();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }
            return(View(award));
        }
コード例 #2
0
        public ActionResult Create(UserView userView)
        {
            User user = null;

            try
            {
                if (ModelState.IsValid && userView.Photo != null)
                {
                    string fileName = SetPhotoPath(userView);
                    string path     = "/img/" + Path.GetFileName(userView.Photo.FileName);

                    user = new User()
                    {
                        Name      = userView.Name,
                        Birthdate = userView.Birthdate,
                        Age       = userView.Age,
                        PhotoPath = path
                    };

                    Repository.AddUser(user);
                    Repository.Save();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }
            return(View(user));
        }
コード例 #3
0
        public ActionResult RewardUser(IndexViewModel index)
        {
            User  user  = Repository.GetUserByID(index.User.UserID);
            Award award = Repository.GetAwardByID(index.AwardEdit.Id);

            if (user != null && award != null)
            {
                UserAward userAward = new UserAward
                {
                    Users  = user,
                    Awards = award
                };
                Repository.AddUserAward(userAward);
                Repository.Save();
            }
            return(RedirectToAction("Award", new { user.UserID }));
        }
コード例 #4
0
ファイル: AwardService.cs プロジェクト: pobeirne/GradFolio
 public bool InsertAward(string userId, AwardDto award)
 {
     try
     {
         //Validate user
         if (_userRepository.IsAuthenticated(userId))
         {
             //Validate Model
             ICollection <ValidationResult> results;
             if (IsValidModel(award, out results))
             {
                 //Call Repository
                 if (_awardRepository.InsertAward(award))
                 {
                     //Save
                     if (_awardRepository.Save())
                     {
                         //Success
                         return(true);
                     }
                     _loggingService.Info("Failed To Save");
                 }
                 _loggingService.Info("UserRepository Failed Insert");
             }
             _loggingService.Info("Model Validation Failed: " + award);
         }
         _loggingService.Info("UserId Authenticated Failed: " + userId);
     }
     catch (Exception ex)
     {
         //Error
         _loggingService.Error("An error has occurred", ex);
     }
     //Fail
     return(false);
 }
コード例 #5
0
 public void Add(Award award)
 {
     _awardRepository.Add(award);
     _awardRepository.Save();
 }
コード例 #6
0
 public void Save()
 {
     _awardRepository.Save();
 }