Exemple #1
0
        public IHttpActionResult SaveResidentShift(int residentId, [FromBody] ResidentShiftModel shift)
        {
            try
            {
                HttpRequires.IsNotNull(shift, "Shift Data Required");

                var response = _residentSvc.SaveShift(shift);

                HttpAssert.Success(response);

                // NOTE: THIS SECTION CONTAINS CHANGES ADDED AFTER THE
                //    DEADLINE, TO RESOLVE BUG PERSISTING TIME ENTRIES
                return(Ok(new
                {
                    Shift = response.Result.Item1,
                    Shifts = response.Result.Item2
                }));
            }
            catch (ShiftConflictException ex)
            {
                return(this.BadRequest(new
                {
                    Type = "ShiftConflict",
                    Data = ex.Conflicts
                }));
            }
            catch (Exception ex)
            {
                if (_logger != null)
                {
                    _logger.Write(ex);
                }
                return(InternalServerError());
            }
        }
        public IHttpActionResult GetTableProperties(long tableId)
        {
            try
            {
                var connectionString = Request.Headers.GetValues("connectionString").FirstOrDefault();

                HttpRequires.IsNotNull(connectionString, "Ivnalid Connection");
                HttpRequires.IsTrue(tableId >= 0, "Invalid Table Id");

                var response = _propertyDal.RetrieveByTableId(tableId, connectionString);

                HttpAssert.Success(response);
                HttpAssert.NotNull(response, "Unable to find property results for table");
                return(Ok(response.Result));
            }
            catch (NotFoundException)
            {
                return(NotFound());
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public void IsNotNull_NullNullableInt()
        {
            //Arrange
            int?i = null;

            //Act
            HttpRequires.IsNotNull(i, "");
        }
        public void IsNotNull_ValidNullableInt()
        {
            //Arrange
            int?i = 1;

            //Act
            HttpRequires.IsNotNull(i, "");
        }
        /// <summary>
        /// Method to add an extended property to a table or table column
        /// </summary>
        /// <param name="model"></param>
        private void Add(ExtendedPropertyModel model)
        {
            var connectionString = Request.Headers["connectionString"].FirstOrDefault();

            HttpRequires.IsNotNull(connectionString, "Invalid Connection");
            HttpRequires.IsNotNull(model, "Invalid Properties");

            var response = _propertyDal.AddProperty(model, connectionString);

            HttpAssert.Success(response);
        }
Exemple #6
0
        public PatientTrackingReport GetTracking(int id, DateTime?startDate, DateTime?endDate)
        {
            HttpRequires.IsNotNull(startDate, "Start Date is required.");
            HttpRequires.IsNotNull(endDate, "End Date is required.");
            HttpRequires.IsTrue(endDate >= startDate, "End Date must be greater than or equal to the Start Date");

            var response = PatientService.GetTrackingReport(id, startDate.Value, endDate.Value);

            HttpAssert.Success(response);
            HttpAssert.IsNotNull(response);

            return(response.Result);
        }
        /// <summary>
        /// Method to get the properties for a table (includes the properties for the
        /// table's columns)
        /// </summary>
        /// <param name="tableId"></param>
        /// <returns></returns>
        private List <ExtendedPropertyModel> GetProperties(long tableId)
        {
            var connectionString = Request.Headers["connectionString"].FirstOrDefault();

            HttpRequires.IsNotNull(connectionString, "Ivnalid Connection");
            HttpRequires.IsTrue(tableId >= 0, "Invalid Table Id");

            var dalResp = _propertyDal.RetrieveByTableId(tableId, connectionString);

            HttpAssert.Success(dalResp);
            HttpAssert.NotNull(dalResp, "Unable to find property results for table");

            return(dalResp.Result.ToList());
        }
        /// <summary>
        /// Method to get a collection of columns for the user's selected table.
        /// </summary>
        /// <param name="tableId"></param>
        /// <returns></returns>
        private List <ColumnModel> GetColumns(long tableId)
        {
            var connectionString = Request.Headers["connectionString"].FirstOrDefault();

            HttpRequires.IsNotNull(connectionString, "Invalid Connection");
            HttpRequires.IsTrue(tableId > 0, "Invalid Table Id");

            //var dalResp = ColumnDal.GetColumns(tableId, connectionString);
            var dalResp = _columnDal.GetColumns(tableId, connectionString);

            HttpAssert.Success(dalResp);
            HttpAssert.NotNull(dalResp, "Unable to find column results for table");
            return(dalResp.Result.ToList());
        }
        /// <summary>
        /// Method to get the database connections setup to be accessible using the nancy api. These are
        /// evaluated for matches with the connections found using Web API. Where they match, the user
        /// is able to select to use the Nancy Api instead of Web API
        /// </summary>
        /// <returns></returns>
        private List <DatabaseModel> GetDatabases()
        {
            HttpRequires.IsTrue(ConfigurationManager.ConnectionStrings.Count > 0, "No connections");
            var connections = new List <DatabaseModel>();

            foreach (ConnectionStringSettings connection in ConfigurationManager.ConnectionStrings)
            {
                connections.Add(new DatabaseModel
                {
                    Name             = connection.Name,
                    ConnectionString = connection.ConnectionString
                });
            }
            return(connections);
        }
        /// <summary>
        /// Method to get a collection of tables in the database selected by the user.
        /// </summary>
        /// <returns></returns>
        private List <TableModel> GetTables()
        {
            var connectionString = Request.Headers["connectionString"].FirstOrDefault();

            //connectionString = connectionString.Replace("|DataDirectory|", "..\\..\\SqlServerDocumenterUtility\\App_Data");

            HttpRequires.IsNotNull(connectionString, "Invalid connection");

            //var dalResp = TableDal.GetTables(connectionString);
            var dalResp = _tableDal.GetTables(connectionString);

            HttpAssert.Success(dalResp);
            HttpAssert.NotNull(dalResp, "Unable to find results for table");

            return(dalResp.Result.ToList());
        }
Exemple #11
0
        public IHttpActionResult GetTables()
        {
            try
            {
                var connectionString = Request.Headers.GetValues("connectionString").FirstOrDefault();

                HttpRequires.IsNotNull(connectionString, "Invalid connection");

                var response = _tableDal.GetTables(connectionString);

                HttpAssert.Success(response);
                HttpAssert.NotNull(response, "Unable to find results for table");
                return(Ok(response.Result));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        /// <summary>
        /// Method to update an extended property of a table or column
        /// </summary>
        /// <param name="model"></param>
        private void Update(ExtendedPropertyModel model)
        {
            var connectionString = Request.Headers["connectionString"].FirstOrDefault();

            HttpRequires.IsNotNull(connectionString, "Invalid Connection");
            HttpRequires.IsNotNull(model, "Invalid Properties");

            //Using the sql server system procedures I had (for add and delete). Instead of an in
            // place update, the process is to first delete the existing property, and then add
            // the new values. To avoid a situation where the delete succeeds but the add fails,
            // we use a transaction scope.
            using (var scope = new TransactionScope())
            {
                var deleteResp = _propertyDal.DeleteProperty(model, connectionString);
                var addResp    = _propertyDal.AddProperty(model, connectionString);
                HttpAssert.Success(deleteResp);
                HttpAssert.Success(addResp);
                scope.Complete();
            }
        }
Exemple #13
0
        public IHttpActionResult GetResidentShifts(int residentId)
        {
            try
            {
                HttpRequires.IsTrue(residentId > 0, "A valid resident identifier is required");

                var response = _residentRepo.FindShiftsByResidentId(residentId);

                HttpAssert.Success(response);
                HttpAssert.NotNull(response, String.Format("Unable to find shifts for resident with id [{0}]", residentId));

                return(Ok(response.Result));
            }
            catch (Exception ex)
            {
                if (_logger != null)
                {
                    _logger.Write(ex);
                }
                return(InternalServerError());
            }
        }
        public IHttpActionResult Get(int institutionId)
        {
            try
            {
                HttpRequires.IsTrue(institutionId > 0, "A valid institution identifier is required");

                var response = _institutionRepo.Find(institutionId);

                HttpAssert.Success(response);
                HttpAssert.NotNull(response, String.Format("Unable to find an institution with id [{0}]", institutionId));

                return(Ok(response.Result));
            }
            catch (Exception ex)
            {
                if (_logger != null)
                {
                    _logger.Write(ex);
                }
                return(InternalServerError());
            }
        }
Exemple #15
0
        public IHttpActionResult GetDatabases()
        {
            try
            {
                var connections = new List <DatabaseModel>();

                HttpRequires.IsTrue(ConfigurationManager.ConnectionStrings.Count > 0, "No connections");

                foreach (ConnectionStringSettings connection in ConfigurationManager.ConnectionStrings)
                {
                    if (connection.Name.Contains("LocalSqlServer"))
                    {
                        continue;
                    }

                    //Since the nancy api is also using the same data base connections, "|DataDirectory|" cannot be used, because within
                    // the nancy api project, it has a different context. Therefore, we replace it with the server path to the web app's
                    // App_Data folder containing the database mdf's included. This only applies to database connection strings that
                    // attach to a file system path
                    var connectionString = connection.ConnectionString;
                    if (connectionString.Contains("|DataDirectory|"))
                    {
                        connectionString = connectionString.Replace("|DataDirectory|", System.Web.HttpContext.Current.Server.MapPath("\\Databases"));
                    }

                    connections.Add(new DatabaseModel {
                        Name             = connection.Name,
                        ConnectionString = connectionString
                    });
                }

                return(Ok(connections));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult GetInstitutionResidents(int institutionId)
        {
            try
            {
                HttpRequires.IsTrue(institutionId > 0, "A valid instituion identifier is required");

                var response = _institutionRepo.FindResidentsByInstitutionId(institutionId);

                HttpAssert.Success(response);
                HttpAssert.NotNull(response, "Unable to find residents for the institution");

                return(Ok(response.Result));
            }
            catch (Exception ex)
            {
                //TODO: Server side logging/notification here
                if (_logger != null)
                {
                    _logger.Write(ex);
                }
                return(InternalServerError());
            }
        }
        public IHttpActionResult AddProperty([FromBody] ExtendedPropertyModel propertyModel)
        {
            try
            {
                var connectionString = Request.Headers.GetValues("connectionString").FirstOrDefault();

                HttpRequires.IsNotNull(connectionString, "Invalid Connection");
                HttpRequires.IsNotNull(propertyModel, "Invalid Properties");
                ValidatePropertyModel(propertyModel);

                var response = _propertyDal.AddProperty(propertyModel, connectionString);

                HttpAssert.Success(response);
                return(Ok());
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult UpdateProperty([FromBody] ExtendedPropertyModel propertyModel)
        {
            try
            {
                var connectionString = Request.Headers.GetValues("connectionString").FirstOrDefault();

                HttpRequires.IsNotNull(connectionString, "Invalid Connection");
                HttpRequires.IsNotNull(propertyModel, "Invalid Properties");
                ValidatePropertyModel(propertyModel);

                DalResponseModel deletionResponse, addResponse;

                //Using the sql server system procedures I had (for add and delete). Instead of an in
                // place update, the process is to first delete the existing property, and then add
                // the new values. To avoid a situation where the delete succeeds but the add fails,
                // we use a transaction scope.
                using (var scope = new TransactionScope())
                {
                    deletionResponse = _propertyDal.DeleteProperty(propertyModel, connectionString);
                    addResponse      = _propertyDal.AddProperty(propertyModel, connectionString);
                    HttpAssert.Success(deletionResponse);
                    HttpAssert.Success(addResponse);
                    scope.Complete();
                }

                return(Ok());
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
 public void IsTrue_Valid()
 {
     //Act
     HttpRequires.IsTrue(0 < 10, "");
 }
 public void IsNotNull_ValidString()
 {
     //Act
     HttpRequires.IsNotNull("Test", String.Empty);
 }
 public void IsNotNull_EmptyString()
 {
     //Act
     HttpRequires.IsNotNull("", "");
 }
 public void IsNotNull_NullString()
 {
     //Act
     HttpRequires.IsNotNull((String)null, "");
 }
 public void IsNotNull_ValidObj()
 {
     //Act
     HttpRequires.IsNotNull(new object(), "");
 }
 public void IsNotNull_NullObj()
 {
     //Act
     HttpRequires.IsNotNull((object)null, "");
 }
 public void IsTrue_Invalid()
 {
     //Act
     HttpRequires.IsTrue(10 < 0, "");
 }