Ejemplo n.º 1
0
        public bool UpdateAward(string userId, AwardDto award)
        {
            try
            {
                //Validate user
                if (_userRepository.IsAuthenticated(userId))
                {
                    var record = _awardRepository.GetAwardById(award.Id.ToString());
                    if (record != null)
                    {
                        //Validate Model
                        ICollection <ValidationResult> results;
                        if (IsValidModel(award, out results))
                        {
                            if (ModelCompareChecker.Compare(award, record))
                            {
                                return(true);
                            }

                            record.Title      = award.Title;
                            record.Level      = award.Level;
                            record.IssuedBy   = award.IssuedBy;
                            record.IssuedDate = award.IssuedDate;

                            return(_awardRepository.UpdateAward(record));
                        }
                        _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);
        }
Ejemplo n.º 2
0
        public ActionResult Edit(AwardEditView awardView)
        {
            Award award = null;

            try
            {
                if (ModelState.IsValid)
                {
                    award = Repository.GetAwardByID(awardView.Id);

                    award.Title       = awardView.Title;
                    award.Description = awardView.Description;

                    if (awardView.Image != null)
                    {
                        if (awardView.ExistingPath != null)
                        {
                            string oldPath = Path
                                             .Combine(@"C:\Users\Brother\Desktop\Epam\module8\SimpleApp\SimpleApp\wwwroot\img", Path.GetFileName(awardView.Image.FileName));
                            System.IO.File.Delete(oldPath);
                        }
                        string filePath = SetPhotoPath(awardView);
                        string path     = "/img/" + Path.GetFileName(awardView.Image.FileName);
                        award.ImagePath = path;
                    }

                    Repository.UpdateAward(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));
        }