Beispiel #1
0
        public ActionResult Create(SubjectViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Business.SubjectBusiness subject    = new Business.SubjectBusiness();
                    Domain.Subject           newSubject = new Domain.Subject
                    {
                        Name = model.Name,
                        year = model.Year,
                    };
                    subject.Save(newSubject);
                }
                else
                {
                    foreach (var item in ModelState.AsQueryable().ToList())
                    {
                        if (item.Value.Errors.Count > 0)
                        {
                            ModelState.AddModelError("Error", item.Value.Errors.First().ErrorMessage + string.Empty);
                        }
                    }
                }

                return(RedirectToAction("Index", model));
            }
            catch (Exception ex)
            {
                //Code to save the customer data here
                ViewData["error"] = ex.Message;
                return(RedirectToAction("Index", model));
            }
        }
 public EditingSubjectViewModel(Subject instance, IValidator<Subject> validator)
 {
     _subject = instance;
     _nameSnapShot = instance.Name;
     _validator = validator;
     _saveChangesCommand =
             new RelayCommand(
                     () => RaiseEvent(ChangesSavedEvent),
                     () => CanSaveChanges()
                 );
 }
        public bool Update(Domain.Subject subject)
        {
            try
            {
                Subject entity = GetById(subject.Id);
                entity.Name = subject.Name;
                entity.year = subject.year;


                _repository.Update(entity);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(true);
        }
        public AssociatedSubjectViewModel(
            AssociatedSubject associatedSubject,
            IValidator<AssociatedSubject> subjectValidator,
            Subject subject,
            Guid busId)
        {
            if (subject == null)
                throw new ArgumentNullException("subject");

            if (associatedSubject == null)
                throw new ArgumentNullException("associatedSubject");

            this._subjectValidator = subjectValidator;
            this._associatedSubject = associatedSubject;
            this._subject = subject;
            this._busId = busId;

            InitializeCommands();
        }
Beispiel #5
0
 public SubjectViewModel(Subject subject)
 {
     _subject = subject;
 }
        private void RemoveAvailableSubject(Subject subject)
        {

            _availableSubjects.Remove(subject);
            _addAssociatedSubjectCommand.RaiseCanExecuteChanged();
        }
        private void AddAssociatedSubject(Subject subject)
        {
            var viewModel =
                new AssociatedSubjectViewModel(
                    new AssociatedSubject() { SubjectId = subject.Id, Points = 0 },
                    _subjectValidator, 
                    subject, 
                    _busId
                );

            RemoveAvailableSubject(subject);

            AttachEvents(viewModel);
            _associatedSubjects.Add(viewModel);

            RaiseSubjectAdded(viewModel.AssociatedSubject);

            NotifyDirtyHasChanged();
        }