Ejemplo n.º 1
0
        public NextOfKinViewModel GetNextOfKin(int PatientId, string UserId, bool isPharmixAdmin)
        {
            var result  = new NextOfKinViewModel();
            var IsAdmin = false;

            if (IsAdminUser(UserId, isPharmixAdmin))
            {
                IsAdmin = true;
            }
            else
            {
                PatientId = _repository.GetContext().Patients.Where(p => p.UserId == UserId).Select(p => p.Id).FirstOrDefault();
            }

            var primaryCareContact = _repository.GetContext().NextOfKin.Include(p => p.Pregnancy).Where(p => p.Pregnancy.PatientId == PatientId).FirstOrDefault();

            if (primaryCareContact == null)
            {
                result = new NextOfKinViewModel();
            }
            else
            {
                result = Mapper.Map <NextOfKinViewModel>(primaryCareContact);
            }

            result.IsAdmin   = IsAdmin;
            result.PatientId = PatientId;

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var nextOfKin = await _context.NextOfKin.SingleOrDefaultAsync(m => m.KinId == id);

            if (nextOfKin == null)
            {
                return(NotFound());
            }

            NextOfKinViewModel viewModel = new NextOfKinViewModel
            {
                KinId            = nextOfKin.KinId,
                UserId           = _userId,
                Name             = nextOfKin.Name,
                Surname          = nextOfKin.Surname,
                PhoneNumber1     = nextOfKin.PhoneNumber,
                WorkNumber1      = nextOfKin.WorkNumber,
                Email1           = nextOfKin.Email,
                RelationshipType = nextOfKin.RelationshipType
            };

            return(View(viewModel));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, [Bind("Name,Surname,RelationshipType,KinId,Email1,PhoneNumber1,WorkNumber1")] NextOfKinViewModel viewModel)
        {
            if (id != viewModel.KinId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    NextOfKin nextOfKin = new NextOfKin
                    {
                        KinId            = viewModel.KinId,
                        UserId           = _userId,
                        Name             = viewModel.Name,
                        Surname          = viewModel.Surname,
                        PhoneNumber      = viewModel.PhoneNumber1,
                        WorkNumber       = viewModel.WorkNumber1,
                        Email            = viewModel.Email1,
                        RelationshipType = viewModel.RelationshipType
                    };

                    _context.Update(nextOfKin);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NextOfKinExists(viewModel.KinId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(viewModel));
        }
Ejemplo n.º 4
0
        public bool SaveNextOfKin(NextOfKinViewModel model, string UserId)
        {
            var result = false;

            try
            {
                var pregnancy = _repository.GetContext().Pregnancy.Where(p => p.PatientId == model.PatientId).FirstOrDefault();
                if (model.Id > 0)
                {
                    //Update Existing
                    var nextOfKin = _repository.GetContext().NextOfKin.Where(p => p.Id == model.Id).FirstOrDefault();
                    Mapper.Map(model, nextOfKin);
                    nextOfKin.SetUpdateDetails(UserId);

                    _repository.SaveExisting(nextOfKin);
                }
                else
                {
                    //Add new Record
                    var nextOfKin = new NextOfKin();
                    Mapper.Map(model, nextOfKin);
                    nextOfKin.PregnancyId = pregnancy.Id;
                    nextOfKin.SetCreateDetails(UserId);

                    var saveNew = _repository.SaveNew(nextOfKin);
                }

                result = true;
            }
            catch (Exception ex)
            {
                result = false;
            }

            return(result);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Name,Surname,RelationshipType,KinId,Email1,PhoneNumber1,WorkNumber1")] NextOfKinViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                NextOfKin nextOfKin = new NextOfKin
                {
                    KinId            = viewModel.KinId,
                    UserId           = _userId,
                    Name             = viewModel.Name,
                    Surname          = viewModel.Surname,
                    PhoneNumber      = viewModel.PhoneNumber1,
                    WorkNumber       = viewModel.WorkNumber1,
                    Email            = viewModel.Email1,
                    RelationshipType = viewModel.RelationshipType
                };

                _context.Add(nextOfKin);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(viewModel));
        }