Beispiel #1
0
        private JsonResult UpdateVisit(VisitViewModel model)
        {
            using (var adminUow = DependencyResolver.Current.GetService <IAdminUnitOfWork>())
            {
                var visit = model.ToEntity();
                visit.UpdatedOn = DateTime.UtcNow;
                visit.UpdatedBy = Thread.CurrentPrincipal.Identity.Name;
                visit.Status    = (int)EntityStatusType.Current;
                if (model.ParentVisitId > 0)
                {
                    var parent = adminUow.VisitRepository.GetById(model.ParentVisitId);
                    if (parent != null)
                    {
                        parent.HasChild = true;
                    }
                }
                else
                {
                    visit.ParentVisitId = null;
                }
                adminUow.VisitRepository.Update(visit);
                adminUow.Commit();

                return(Json("vis.vm.loadVisits(" + model.StudyId + ");", JsonRequestBehavior.DenyGet));
            }
        }
Beispiel #2
0
        public JsonResult CreateVisit(VisitViewModel model)
        {
            //ModelState.Remove("StudyId");
            //model.StudyId = GlobalVariables.CurrentStudyId;

            if (model.Id == 0)
            {
                ModelState.Remove("Id");
                TryValidateModel(model);
            }

            if (!ModelState.IsValid)
            {
                return(Json("alert('Error!');", JsonRequestBehavior.DenyGet));
            }

            if (model.ParentVisitId < 1)
            {
                model.ParentVisitId = null;
            }

            if (model.Id > 0)
            {
                return(UpdateVisit(model));
            }

            var visit = model.ToEntity();

            visit.CreatedOn = DateTime.UtcNow;
            visit.CreatedBy = Thread.CurrentPrincipal.Identity.Name;
            visit.Status    = (int)EntityStatusType.Current;

            using (var adminUow = DependencyResolver.Current.GetService <IAdminUnitOfWork>())
            {
                adminUow.VisitRepository.Insert(visit);
                adminUow.Commit();
            }
            return(Json("vis.vm.loadVisits(" + model.StudyId + ");", JsonRequestBehavior.DenyGet));
        }