Beispiel #1
0
        public JsonResult Create(CHGSiteModel model)
        {
            if (!HasContextRole(new string[] { "CRO" }))
            {
                return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "Unauthorized." }));
            }


            var ltachId = _dataContext.ServiceTypes.Where(p => p.Name == "LTACH" && p.Deleted == false).Single().ServiceTypeId;


            if (ModelState.IsValid)
            {
                using (var transaction = _dataContext.Database.BeginTransaction())
                {
                    using (var changeSet = new ChangeSetTracking(_dataContext))
                    {
                        if (model.ServiceTypeId == ltachId && (model.PreScreenUpdateTypeId == null || model.PreScreenUpdateTypeId <= 0))
                        {
                            return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "One or more fields failed validation." }));
                        }
                        if (model.ServiceTypeId != ltachId)
                        {
                            model.PreScreenUpdateTypeId = null;
                        }

                        if (_dataContext.CHGSites.Where(p => p.FullName == model.FullName && p.Deleted == false).Count() <= 0)
                        {
                            CHGSite entity = new CHGSite()
                            {
                                FullName               = model.FullName,
                                RegionTypeId           = model.RegionTypeId,
                                ShortName              = model.ShortName,
                                Address                = model.Address,
                                BedCount               = model.BedCount,
                                OperationalICUBedCount = model.OperationalICUBedCount,
                                PreScreenUpdateTypeId  = model.PreScreenUpdateTypeId,
                                ServiceTypeId          = model.ServiceTypeId
                            };

                            _dataContext.CHGSites.Add(entity);
                            _dataContext.SaveChanges();
                            transaction.Commit();

                            return(Json(new { Status = Constant.RESPONSE_OK, Description = "Site created successfully." }));
                        }
                        else
                        {
                            return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "The site with the same full name already exists. Please enter a different name." }));
                        }
                    }
                }
            }

            return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "One or more fields failed validation." }));
        }
Beispiel #2
0
        public JsonResult DetailEntity(long?id)
        {
            if (!HasContextRole(new string[] { "CRO" }))
            {
                return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "Unauthorized." }));
            }
            if (id == null || id == 0)
            {
                return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "Invalid ID Specification." }));
            }

            var entity = _dataContext.CHGSites.Where(p => p.CHGSiteId == id && p.Deleted == false).SingleOrDefault();

            if (entity == null)
            {
                return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "CHG site not found. Invalid CHG site." }));
            }

            CHGSiteModel model = new CHGSiteModel()
            {
                CHGSiteId = entity.CHGSiteId,
                Address   = entity.Address,
                BedCount  = entity.BedCount,
                FullName  = entity.FullName,
                OperationalICUBedCount = entity.OperationalICUBedCount,
                PreScreenUpdateTypeId  = entity.PreScreenUpdateTypeId,
                RegionName             = entity.RegionType.Name,
                ServiceName            = entity.ServiceType.Name,
                RegionTypeId           = entity.RegionTypeId,
                ServiceTypeId          = entity.ServiceTypeId,
                ShortName = entity.ShortName,
                PreScreenUpdateTypeName = entity.PreScreenUpdateTypeId != null ? entity.PreScreenUpdateType.Name : null
            };

            return(Json(new { Status = Constant.RESPONSE_OK, Data = model }, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        public JsonResult Edit(long?id, CHGSiteModel model)
        {
            if (!HasContextRole(new string[] { "CRO" }))
            {
                return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "Unauthorized." }));
            }
            if (id == null || id == 0)
            {
                return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "Invalid ID Specification." }));
            }

            var ltachId = _dataContext.ServiceTypes.Where(p => p.Name == "LTACH" && p.Deleted == false).Single().ServiceTypeId;

            if (ModelState.IsValid)
            {
                using (var transaction = _dataContext.Database.BeginTransaction())
                {
                    using (var changeSetTracking = new ChangeSetTracking(_dataContext))
                    {
                        if (model.ServiceTypeId == ltachId && (model.PreScreenUpdateTypeId == null || model.PreScreenUpdateTypeId <= 0))
                        {
                            return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "One or more fields failed validation." }));
                        }

                        if (model.ServiceTypeId != ltachId)
                        {
                            model.PreScreenUpdateTypeId = null;
                        }


                        if (_dataContext.CHGSites.Where(p => p.FullName == model.FullName && p.CHGSiteId != id && p.Deleted == false).Count() <= 0)
                        {
                            var entity = _dataContext.CHGSites.Where(p => p.CHGSiteId == id && p.Deleted == false).SingleOrDefault();
                            if (entity == null)
                            {
                                return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "CHG site not found. Invalid CHG site." }));
                            }


                            entity.FullName               = model.FullName;
                            entity.ShortName              = model.ShortName;
                            entity.RegionTypeId           = model.RegionTypeId;
                            entity.ServiceTypeId          = model.ServiceTypeId;
                            entity.Address                = model.Address;
                            entity.OperationalICUBedCount = model.OperationalICUBedCount;
                            entity.BedCount               = model.BedCount;
                            entity.PreScreenUpdateTypeId  = model.PreScreenUpdateTypeId;
                            _dataContext.SaveChanges();
                            transaction.Commit();
                            return(Json(new { Status = Constant.RESPONSE_OK, Description = "Site saved successfully." }));
                        }
                        else
                        {
                            return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "The site with the same full name already exists. Please enter a different name." }));
                        }
                    }
                }
            }

            return(Json(new { Status = Constant.RESPONSE_ERROR, Description = "One or more fields failed validation." }));
        }