public ActionResult Edit(MedicamentViewModel medicamentView)
 {
     if (!ModelState.IsValid)
     {
         return(View(medicamentView));
     }
     try
     {
         var entityFromDb = _medicamentManager.GetByPrimaryKey(medicamentView.Id);
         entityFromDb.Name         = medicamentView.Name;
         entityFromDb.Description  = medicamentView.Description;
         entityFromDb.SerialNumber = medicamentView.SerialNumber;
         entityFromDb.Price        = medicamentView.Price;
         //пока что не проверил эту часть
         var history = new MedicamentPriceHistory()
         {
             Medicament   = entityFromDb,
             MedicamentId = entityFromDb.Id,
             ModifiedDate = DateTime.Now,
             Price        = entityFromDb.Price
         };
         entityFromDb.MedicamentPriceHistories.Add(history);
         _medicamentManager.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         ModelState.AddModelError("", "Возникла ошибка при изменении сущьности!");
         return(View(medicamentView));
     }
 }
 public ActionResult Create(MedicamentViewModel medicamentView)
 {
     if (!ModelState.IsValid)
     {
         return(View(medicamentView));
     }
     try
     {
         var entity  = Mapper.Map <MedicamentViewModel, Medicament>(medicamentView);
         var history = new MedicamentPriceHistory()
         {
             Medicament   = entity,
             MedicamentId = entity.Id,
             ModifiedDate = DateTime.Now,
             Price        = entity.Price
         };
         entity.MedicamentPriceHistories.Add(history);
         _medicamentManager.Add(entity);
         _medicamentManager.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         ModelState.AddModelError("", "Возникла ошибка при добавлении сущьности!");
         return(View(medicamentView));
     }
 }
Пример #3
0
        public async Task <MedicamentViewModel> ReturnDescription(MedicamentViewModel model)
        {
            if (!string.IsNullOrEmpty(model.Section))
            {
                model.Section = (await _dbContext.Sections.FindAsync(model.Section)).Description;
            }

            if (!string.IsNullOrEmpty(model.PharmacologicalGroup))
            {
                model.PharmacologicalGroup = (await _dbContext.PharmacologicalGroups.FindAsync(model.PharmacologicalGroup)).Description;
            }

            if (!string.IsNullOrEmpty(model.FirstSubGroup))
            {
                model.FirstSubGroup = (await _dbContext.FirstSubGroups.FindAsync(model.FirstSubGroup)).Description;
            }

            if (!string.IsNullOrEmpty(model.SecondSubGroup))
            {
                model.SecondSubGroup = (await _dbContext.SecondSubGroups.FindAsync(model.SecondSubGroup)).Description;
            }

            if (!string.IsNullOrEmpty(model.ThirdSubGroup))
            {
                model.ThirdSubGroup = (await _dbContext.ThirdSubGroups.FindAsync(model.ThirdSubGroup)).Description;
            }

            return(model);
        }
Пример #4
0
        public async Task <IActionResult> Create(MedicamentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userID     = _userManager.GetUserId(User);
                var newProduct = new Medicament
                {
                    Name = model.Name,
                    PharmaceuticalForm   = model.PharmaceuticalForm,
                    Availability         = model.Availability,
                    Section              = _dbContext.Sections.Find(int.Parse(model.Section)).Description,
                    PharmacologicalGroup = _dbContext.PharmacologicalGroups.Find(int.Parse(model.PharmacologicalGroup)).Description,
                    UserID = userID
                };

                if (!string.IsNullOrEmpty(model.FirstSubGroup))
                {
                    newProduct.FirstSubGroup = _dbContext.FirstSubGroups.Find(int.Parse(model.FirstSubGroup)).Description;
                }

                if (!string.IsNullOrEmpty(model.SecondSubGroup))
                {
                    newProduct.SecondSubGroup = _dbContext.SecondSubGroups.Find(int.Parse(model.SecondSubGroup)).Description;
                }

                if (!string.IsNullOrEmpty(model.ThirdSubGroup))
                {
                    newProduct.ThirdSubGroup = _dbContext.ThirdSubGroups.Find(int.Parse(model.ThirdSubGroup)).Description;
                }

                _ = _dbContext.Medicaments.Add(newProduct);
                _ = await _dbContext.SaveChangesAsync();

                var newStockProduct = new StockProduct
                {
                    MedicamentID    = newProduct.ID,
                    StockID         = 1,
                    DateInput       = DateTime.Now,
                    DateOutput      = DateTime.MinValue,
                    UserID          = userID,
                    InputQuantity   = model.Quantity,
                    OutputQuantity  = 0,
                    MissingQuantity = 0,
                    TotalQuantity   = model.Quantity
                };

                _ = _dbContext.StockProducts.Add(newStockProduct);
                _ = await _dbContext.SaveChangesAsync();

                TempData["Message"] = "Produto adicionado ao estoque.";
                return(RedirectToAction("Index", new { stockID = 1 }));
            }

            return(View(model));
        }
        public ActionResult Create(MedicamentViewModel medicamentViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var medicament = Mapper.Map <MedicamentViewModel, Medicament>(medicamentViewModel);

            _manager.Add(medicament);

            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(int id, MedicamentViewModel medicamentViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(medicamentViewModel));
            }

            var medicament = _manager.GetByPrimaryKey(id);

            medicament = Mapper.Map(medicamentViewModel, medicament);

            _manager.Update(medicament);

            return(RedirectToAction("Index"));
        }
 public ActionResult Edit(MedicamentViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     try
     {
         _medicamentManager.Edit(Mapper.Map <MedicamentViewModel, Medicament>(model));
         return(RedirectToAction("Index"));
     }
     catch
     {
         ModelState.AddModelError("", "Adding new reccord error! Please, try again later!");
         return(View(model));
     }
 }
Пример #8
0
        public MainWindow(MainViewModel vm)
        {
            this.DataContext = vm;
            InitializeComponent();

            Employee = vm.currentemployee;

            if (Employee.Post.Name == "Врач")
            {
                diagnosis.Visibility  = Visibility.Collapsed;
                employees.Visibility  = Visibility.Collapsed;
                EditItem.Visibility   = Visibility.Collapsed;
                medicament.Visibility = Visibility.Collapsed;

                medrecords.IsSelected = true;

                MedRecordViewModel medvm = new MedRecordViewModel(Employee);
                UCMedRecord.DataContext = medvm;
            }
            else
            if (Employee.Post.Name == "Сотрудник регистратуры")
            {
                diagnosis.Visibility  = Visibility.Collapsed;
                employees.Visibility  = Visibility.Collapsed;
                EditItem.Visibility   = Visibility.Collapsed;
                medicament.Visibility = Visibility.Collapsed;

                medrecords.IsSelected = true;

                MedRecordViewModel medvm = new MedRecordViewModel(Employee);
                UCMedRecord.DataContext = medvm;
            }
            if (Employee.Post.Name == "Администратор")
            {
                EditItem.Visibility = Visibility.Collapsed;
                MedRecordViewModel medvm = new MedRecordViewModel(Employee);
                UCMedRecord.DataContext = medvm;
                DiagnosisViewModel diavm = new DiagnosisViewModel();
                UCDiagnosis.DataContext = diavm;
                MedicamentViewModel medivm = new MedicamentViewModel();
                UCMedicament.DataContext = medivm;
                EmployeeViewModel empvm = new EmployeeViewModel();
                UCEmployee.DataContext = empvm;
            }
        }
 public ActionResult Create(MedicamentViewModel medicamentView)
 {
     if (!ModelState.IsValid)
     {
         return(View(medicamentView));
     }
     try
     {
         var entity = Mapper.Map <MedicamentViewModel, Medicament>(medicamentView);
         _medicamentManager.Add(entity);
         return(RedirectToAction("Index"));
     }
     catch
     {
         ModelState.AddModelError("", "Возникла ошибка при добавлении сущьности!");
         return(View(medicamentView));
     }
 }
 public ActionResult Create(MedicamentViewModel medicamentView)
 {
     if (!ModelState.IsValid)
     {
         ModelState.AddModelError("", "Validation data error! Please, change input values!");
         return(View(medicamentView));
     }
     try
     {
         var entity = Mapper.Map <MedicamentViewModel, Medicament>(medicamentView);
         _medicamentManager.Add(entity);
         return(RedirectToAction("Index"));
     }
     catch (ValidationException exception)
     {
         ModelState.AddModelError("", "Validation data error! Please, change input values!");
         return(View(medicamentView));
     }
     catch
     {
         ModelState.AddModelError("", "Adding new reccord error! Please, try again later!");
         return(View(medicamentView));
     }
 }