public AddEditWindow(string windowName, string selectedMod)
        {
            InitializeComponent();

            addEditViewModel = new AddEditViewModel(windowName, selectedMod, Close);
            DataContext      = addEditViewModel;
        }
Exemplo n.º 2
0
        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            AddEditViewModel addViewmodel = new AddEditViewModel(int.Parse(idTextBox.Text), nameTxtBox.Text);

            MessageBox.Show("It hits");
            DataContext = addViewmodel;
        }
Exemplo n.º 3
0
        public ActionResult Add(AddEditViewModel capsule)
        {
            if (Database.Capsules.Any(p => p.UserId == Username && p.Code == capsule.Code))
            {
                ModelState.AddModelError("Duplicate", "There is another capsule with the same Code");
            }

            var unique = !string.IsNullOrEmpty(ItemsCapsule.Single(q => q.ItemId == capsule.ItemId).UniqueId);

            if (!unique && capsule.Code.Length != 8)
            {
                ModelState.AddModelError("Code", "Code must be 8 characters long.");
            }

            if (ModelState.IsValid)
            {
                Database.Capsules.Add(new Capsules {
                    UserId = Username, Code = capsule.Code.ToUpper(), Name = capsule.Name, ItemId = capsule.ItemId
                });

                Database.SaveChanges();

                return(RedirectToAction("Index"));
            }

            capsule.CapsuleTypes = GetValidNewCapsuleTypes(null);

            return(View(capsule));
        }
Exemplo n.º 4
0
        public void ShowAddEditView(object obj)
        {
            AddEditViewModel addEditVM = (AddEditViewModel)ViewModels.FirstOrDefault(viewModel => viewModel.GetType() == typeof(AddEditViewModel));

            if (obj.GetType().Name == "Task")
            {
                if (obj.GetType() == typeof(Reminder))
                {
                    addEditVM.NewTask = (Reminder)obj;
                }
                else
                {
                    addEditVM.NewTask = (Schedule)obj;
                }
                addEditVM.IsEditing = true;
            }
            else if (obj.GetType() == typeof(bool))
            {
                if ((bool)obj)
                {
                    addEditVM.NewTask = new Reminder();
                }
                else
                {
                    addEditVM.NewTask = new Schedule();
                }
            }
            ChangeViewModel(addEditVM);
        }
Exemplo n.º 5
0
        public ActionResult Add()
        {
            var model = new AddEditViewModel();

            model.ItemId       = "CAPS_RA";
            model.CapsuleTypes = GetValidNewCapsuleTypes(null);

            return(View(model));
        }
Exemplo n.º 6
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            FrmAddEdit       frmAddEdit       = new FrmAddEdit();
            AddEditViewModel addEditViewModel = new AddEditViewModel();

            if
            (frmAddEdit.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
            }
        }
Exemplo n.º 7
0
 public FrmAddEdit(AddEditViewModel addEditViewModel)
 {
     InitializeComponent();
     _addEditViewModel = addEditViewModel;
     txtTitle.DataBindings.Add("Text",
                               _addEditViewModel,
                               "Title",
                               false,
                               DataSourceUpdateMode.OnPropertyChanged);
 }
Exemplo n.º 8
0
        // GET: ClinicController/Edit/5
        public ActionResult Edit(string id)
        {
            var clinic = _repository.Get(id);
            var model  = new AddEditViewModel
            {
                Id   = clinic.Id,
                Name = clinic.Name
            };

            return(View(model));
        }
Exemplo n.º 9
0
        //for editing
        public AddEditWindow(Person person)
        {
            InitializeComponent();
            AddEditViewModel vm = new AddEditViewModel(person);

            DataContext = vm;
            if (vm.Close == null)
            {
                vm.Close = new Action(this.Close);
            }
        }
Exemplo n.º 10
0
        public void Register_IsDisabled_When_Expense_is_not_Valid()
        {
            //Arrange
            var exp      = new Expense();
            var vm       = new AddEditViewModel(exp);
            var expected = false;

            //Act
            var result = vm.RegisterCommand.CanExecute(exp);

            //Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 11
0
        public async Task <IActionResult> AddEdit(PageInteractionType val, int id)
        {
            if (val == PageInteractionType.Add)
            {
                return(View(new AddEditViewModel()));
            }
            else if (val == PageInteractionType.Edit)
            {
                var movie = _db.Movies.Include(x => x.Poster).Where(x => x.Id == id).FirstOrDefault();

                if (movie is null)
                {
                    return(View("NotFound"));
                }
                else
                {
                    var user = await _userManager.GetUserAsync(User);

                    if (movie.UserId == user.Id)
                    {
                        byte[] imageData = null;
                        if (System.IO.File.Exists(_appEnvironment.WebRootPath + movie.Poster.Path))
                        {
                            imageData = await System.IO.File.ReadAllBytesAsync(_appEnvironment.WebRootPath + movie.Poster.Path);
                        }
                        else
                        {
                            imageData = await System.IO.File.ReadAllBytesAsync(_appEnvironment.WebRootPath + "/Files/NotFound.jpeg");
                        }
                        var addEditViewModel = new AddEditViewModel()
                        {
                            Name        = movie.Name,
                            Description = movie.Description,
                            YearOfIssue = movie.YearOfIssue,
                            Director    = movie.Director,
                            PosterArr   = imageData,
                            IsEdit      = true
                        };
                        return(View(addEditViewModel));
                    }
                    else
                    {
                        return(Forbid("Отказано в доступе."));
                    }
                }
            }
            else
            {
                return(BadRequest());
            }
        }
Exemplo n.º 12
0
        private void NewBtn_Click(object sender, RoutedEventArgs e)
        {
            AddEditViewModel addEditViewModel = new AddEditViewModel();
            AddEditUser      frm = new AddEditUser(addEditViewModel);

            frm.ShowDialog();

            if (frm.DialogResult == true)
            {
                var newUser = addEditViewModel.CurrentUser;
                mainViewModel.UserList.Add(newUser);
                mainViewModel.CurrentUser = newUser;
            }
        }
Exemplo n.º 13
0
        public void editBtn_Click(object sender, RoutedEventArgs e)
        {
            var user = mainViewModel.CurrentUser;


            AddEditViewModel addEditViewModel = new AddEditViewModel(user);
            AddEditUser      frm = new AddEditUser(addEditViewModel);

            frm.ShowDialog();


            if (frm.DialogResult == true)
            {
            }
        }
Exemplo n.º 14
0
        public ActionResult Edit(int id)
        {
            var capsuleDB = Database.Capsules.SingleOrDefault(p => p.CapsuleId == id && p.UserId == Username);

            if (capsuleDB == null)
            {
                return(new HttpNotFoundResult());
            }

            var model = new AddEditViewModel();

            LoadCapsule(capsuleDB, model);

            model.ItemId       = capsuleDB.ItemId;
            model.CapsuleTypes = GetValidNewCapsuleTypes(model.ItemId);

            return(View(model));
        }
Exemplo n.º 15
0
        public void Register_IsEnable_When_Expense_IsValid()
        {
            //Arrange
            var exp = new Expense()
            {
                Title     = "Demo",
                Amount    = 1,
                Frecuency = ExpenseFrecuency.Monthly
            };
            var vm       = new AddEditViewModel(exp);
            var expected = true;

            //Act
            var result = vm.RegisterCommand.CanExecute(exp);

            //Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 16
0
        public async Task <IActionResult> Add(AddEditViewModel model)
        {
            var allClinics = _clinicRepository.GetAll()
                             .Select(a => new SelectListItem
            {
                Text = a.Name, Value = a.Id.ToString()
            }
                                     ).ToList();

            try
            {
                if (ModelState.IsValid)
                {
                    var user = new Models.User
                    {
                        UserName       = model.Email,
                        Email          = model.Email,
                        EmailConfirmed = model.EmailConfirmed,
                        ClinicId       = model.ClinicId,
                    };
                    var errors = await _doctorRepository.Add(user, model.Password);

                    if (errors == null)
                    {
                        _logger.LogInformation("Doctor added");
                        return(RedirectToAction(nameof(List)));
                    }
                    else
                    {
                        AddErrors(errors);
                    }
                }
                return(View(new AddEditViewModel {
                    Clinics = allClinics
                }));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(View(new AddEditViewModel {
                    Clinics = allClinics
                }));
            }
        }
Exemplo n.º 17
0
        public ActionResult Edit(AddEditViewModel capsule)
        {
            var unique = !string.IsNullOrEmpty(ItemsCapsule.Single(q => q.ItemId == capsule.ItemId).UniqueId);

            if (!unique && capsule.Code.Length != 8)
            {
                ModelState.AddModelError("Code", "Code must be 8 characters long.");
            }

            var capsuleDB = Database.Capsules.SingleOrDefault(p => p.CapsuleId == capsule.CapsuleId && p.UserId == Username);

            if (capsuleDB == null)
            {
                return(new HttpNotFoundResult());
            }

            if (capsuleDB.Code != capsule.Code && Database.Capsules.Any(p => p.UserId == Username && p.Code == capsule.Code))
            {
                ModelState.AddModelError("Duplicate", "There is another capsule with the same Code");
            }

            if (ModelState.IsValid)
            {
                capsuleDB.Code   = capsule.Code;
                capsuleDB.Name   = capsule.Name;
                capsuleDB.ItemId = capsule.ItemId;

                Database.SaveChanges();

                return(RedirectToAction("Index"));
            }

            capsule.CapsuleTypes = GetValidNewCapsuleTypes(capsuleDB.ItemId);

            return(View(capsule));
        }
Exemplo n.º 18
0
        public async Task <IActionResult> AddEdit(AddEditViewModel model)
        {
            var user = await _userManager.GetUserAsync(User);

            if (ModelState.IsValid && user != null)
            {
                Poster file      = new Poster();
                byte[] imageData = null;
                if (model?.Poster != null)
                {
                    imageData = FormFileExtensions.GetImageByteArr(model.Poster);
                    if (FormFileExtensions.ValidateImageSize(model.Poster, _fileSize))
                    {
                        ModelState.AddModelError("Poster", $"Размер файла не должен превышать {_fileSize} МБ.");
                        return(View(model));
                    }
                    if (FormFileExtensions.ValidateImageExtension(model.Poster))
                    {
                        ModelState.AddModelError("Poster", $"Неправильный тип файла.");
                        return(View(model));
                    }
                    if (FormFileExtensions.ValidatePictureData(model.Poster))
                    {
                        ModelState.AddModelError("Poster", $"Не получается прочитать файл.");
                        return(View(model));
                    }
                    string path = "/Files/" + Guid.NewGuid() + model.Poster.FileName;
                    using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
                    {
                        await model.Poster.CopyToAsync(fileStream);
                    }
                    file.Name = model.Poster.FileName;
                    file.Path = path;
                }
                else
                {
                    string name = "NotFound.jpeg";
                    string path = $"{_appEnvironment.WebRootPath}/Files/{name}";
                    if (System.IO.File.Exists(path))
                    {
                        file.Name = name;
                        file.Path = $"/Files/{name}";
                    }
                    else
                    {
                        file.Name = string.Empty;
                        file.Path = string.Empty;
                    }
                }

                if (model.IsEdit)
                {
                    var movie = _db.Movies.Include(x => x.Poster).FirstOrDefault(x => x.Id == model.Id);
                    if (movie is null)
                    {
                        return(BadRequest());
                    }
                    else if (movie.User.Id == user.Id)
                    {
                        movie.Name        = model.Name;
                        movie.Description = model.Description;
                        movie.YearOfIssue = model.YearOfIssue;
                        movie.Director    = model.Director;
                        movie.User        = user;
                        if (!string.IsNullOrEmpty(file.Name) && file.Name != "NotFound.jpeg")
                        {
                            if (System.IO.File.Exists(_appEnvironment.WebRootPath + movie.Poster.Path))
                            {
                                System.IO.File.Delete(_appEnvironment.WebRootPath + movie.Poster.Path);
                            }
                            movie.Poster = file;
                        }
                        _db.Movies.Update(movie);
                    }
                    else
                    {
                        return(Forbid("Отказано в доступе."));
                    }
                }
                else
                {
                    _db.Movies.Add(new Movie()
                    {
                        Name        = model.Name,
                        Description = model.Description,
                        YearOfIssue = model.YearOfIssue,
                        Director    = model.Director,
                        User        = user,
                        Poster      = file
                    });
                }
                await _db.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(View(model));
            }
        }
Exemplo n.º 19
0
 public AddEditUser(AddEditViewModel _addEditViewModel)
 {
     InitializeComponent();
     this.grdMainGrid.DataContext = _addEditViewModel;
 }
Exemplo n.º 20
0
 public AddEditView()
 {
     InitializeComponent();
     ViewModel = new AddEditViewModel();
 }
Exemplo n.º 21
0
 public AddEditView(AddEditViewModel context)
 {
     InitializeComponent();
     DataContext = context;
 }
Exemplo n.º 22
0
 public AddEditPersonView()
 {
     InitializeComponent();
     DataContext = new AddEditViewModel();
 }
Exemplo n.º 23
0
 public AddEditUserControl()
 {
     DataContext = new AddEditViewModel();
     InitializeComponent();
 }