Ejemplo n.º 1
0
        private void Insert(int id, string name, int age, DateTime?hiringDate, decimal grossSalary)
        {
            try
            {
                using (var employees = new EmployeesBusiness())
                {
                    var entity = new EmployeesEntity();
                    entity.Id          = id;
                    entity.Name        = name;
                    entity.Age         = age;
                    entity.HiringDate  = hiringDate;
                    entity.GrossSalary = grossSalary;
                    var opSuccessful = employees.InsertEmployee(entity);

                    var resultMessage = opSuccessful ? "Done Successfully" : "Error happened!";

                    MessageBox.Show(resultMessage, "Success", MessageBoxButtons.OK);
                }
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                MessageBox.Show("UserInterface:EmployeesForm::Insert::Error occured." +
                                Environment.NewLine + ex.Message, "Error", MessageBoxButtons.OK);
            }
        }
Ejemplo n.º 2
0
        private string RequestWebData(string url)
        {
            try
            {
                var webRequest = (HttpWebRequest)WebRequest.Create(url);

                //All responses are compressed, either with GZIP or DEFLATE.
                webRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
                webRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

                var response = "";

                using (var webResponse = webRequest.GetResponse())
                    using (var sr = new StreamReader(webResponse.GetResponseStream()))
                    {
                        response = sr.ReadToEnd();
                    }

                return(response);
            }
            catch (WebException ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                //Bubble error to caller and encapsulate Exception object
                throw new Exception("QuestionsRequest::RequestWebData::Error occured.", ex);
            }
        }
Ejemplo n.º 3
0
        public ActionResult Create(FormCollection collection)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            try
            {
                InsertPerson(int.Parse(collection["personId"]),
                             collection["Firstname"],
                             collection["Surname"],
                             collection["Gender"],
                             collection["EmailAddress"],
                             collection["PhoneNumber"]);

                return(RedirectToAction("ListAll"));
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);
                ViewBag.Message = Server.HtmlEncode(ex.Message);
                return(View("Error"));
            }
        }
Ejemplo n.º 4
0
        private void Insert(string ownername, int age, string petname, string contactphone)
        {
            try
            {
                using (var owners = new OwnersBusiness())
                {
                    var entity = new OwnersEntity();
                    entity.OwnerName    = ownername;
                    entity.PetName      = petname;
                    entity.PetAge       = age;
                    entity.ContactPhone = contactphone;
                    var opSuccessful = owners.InsertOwner(entity);

                    var resultMessage = opSuccessful ? "Done Successfully" : "Error happened!";

                    MessageBox.Show(resultMessage, "Success", MessageBoxButtons.OK);
                }
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                MessageBox.Show("UserInterface:OwnersForm::Insert::Error occured." +
                                Environment.NewLine + ex.Message, "Error", MessageBoxButtons.OK);
            }
        }
Ejemplo n.º 5
0
        public ActionResult Create(FormCollection collection)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            try
            {
                InsertEmployee(int.Parse(collection["Id"]),
                               collection["Name"],
                               int.Parse(collection["Age"]),
                               collection["HiringDate"].Trim().Length == 0
                                ? (DateTime?)null
                                : DateTime.ParseExact(collection["HiringDate"], "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None),
                               decimal.Parse(collection["GrossSalary"]));

                return(RedirectToAction("ListAll"));
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);
                ViewBag.Message = Server.HtmlEncode(ex.Message);
                return(View("Error"));
            }
        }
Ejemplo n.º 6
0
        private List <QuestionEntity> SelectAllByFactors()
        {
            try
            {
                using (var repository = new QuestionsRepository())
                {
                    repository.Order = OrderType.Descending;
                    repository.Sort  = SortType.Creation;
                    //repository.FromDate =
                    //repository.ToDate =
                    //repository.Min =
                    //repository.Max =
                    repository.Page     = 1;
                    repository.PageSize = 50;
                    return(repository.SelectItemsFiltered());
                }
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                lblOperationResult.Text = "Sorry, loading All Questions operation failed." + Environment.NewLine + ex.Message;
            }

            return(null);
        }
Ejemplo n.º 7
0
        public bool InsertServiceType(ServiceType entity)
        {
            try
            {
                bool bOpDoneSuccessfully;
                using (var repository = new ServiceTypeRepository())
                {
                    bOpDoneSuccessfully = repository.Insert(entity);
                }

                return(bOpDoneSuccessfully);
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                throw new Exception("BusinessLogic:ServiceTypesBusiness::InsertServiceType::Error occured.", ex);
            }
        }
Ejemplo n.º 8
0
        public ActionResult Create(FormCollection collection)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            try
            {
                InsertCountry(int.Parse(collection["CountryID"]),
                              collection["nameCountry"],
                              collection["shortNameCountry"]);

                return(RedirectToAction("ListAll"));
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);
                ViewBag.Message = Server.HtmlEncode(ex.Message);
                return(View("Error"));
            }
        }
Ejemplo n.º 9
0
 private List <EmployeesEntity> ListAllEmployees()
 {
     try
     {
         using (var employees = new EmployeesBusiness())
         {
             return(employees.SelectAllEmployees());
         }
     }
     catch (Exception ex)
     {
         //Log exception error
         _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);
     }
     return(null);
 }
        public ActionResult Create(SuburbEntity obj)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            try
            {
                InsertSuburb(obj.StateId, obj.SuburbName
                             );

                return(RedirectToAction("ListAll"));
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);
                ViewBag.Message = Server.HtmlEncode(ex.Message);
                return(View("Error"));
            }
        }
Ejemplo n.º 11
0
        public override void OnException(ExceptionContext filterContext)
        {
            Exception ex = filterContext.Exception;

            //Log Exception ex
            //GetExceptionMessageFormatted(ex);
            _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

            filterContext.ExceptionHandled = true;

            var controllerName = filterContext.RouteData.Values["controller"].ToString();
            var actionName     = filterContext.RouteData.Values["action"].ToString();

            var model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);

            filterContext.Result = new ViewResult()
            {
                ViewName = "Error"
                ,
                ViewData = new ViewDataDictionary(model)
            };
        }
Ejemplo n.º 12
0
        public bool Insert(EmployeesEntity entity)
        {
            try
            {
                var sb = new StringBuilder();
                sb.Append("SET DATEFORMAT DMY; ");
                sb.Append("INSERT [HR].[Employees] ");
                sb.Append("( ");
                sb.Append("[Id], ");
                sb.Append("[Name], ");
                sb.Append("[Age], ");
                sb.Append("[HiringDate], ");
                sb.Append("[GrossSalary], ");
                sb.Append("[ModifiedDate] ");
                sb.Append(") ");
                sb.Append("VALUES ");
                sb.Append("( ");
                sb.Append(" @intId, ");
                sb.Append(" @chnName, ");
                sb.Append(" @intAge, ");
                sb.Append(" @dtmHiringDate, ");
                sb.Append(" @decGrossSalary, ");
                sb.Append(" ISNULL(@dtmModifiedDate, (getdate())) ");
                sb.Append(") ");
                sb.Append("SELECT @intErrorCode=@@ERROR; ");

                var commandText = sb.ToString();
                sb.Clear();

                using (var dbConnection = _dbProviderFactory.CreateConnection())
                {
                    if (dbConnection == null)
                    {
                        throw new ArgumentNullException("dbConnection", "The db connection can't be null.");
                    }

                    dbConnection.ConnectionString = _connectionString;

                    using (var dbCommand = _dbProviderFactory.CreateCommand())
                    {
                        if (dbCommand == null)
                        {
                            throw new ArgumentNullException("dbCommand" + " The db Insert command for entity [Employees] can't be null. ");
                        }

                        dbCommand.Connection  = dbConnection;
                        dbCommand.CommandText = commandText;

                        //Input Parameters
                        _dataHandler.AddParameterToCommand(dbCommand, "@intId", CsType.Int, ParameterDirection.Input, entity.Id);
                        _dataHandler.AddParameterToCommand(dbCommand, "@chnName", CsType.String, ParameterDirection.Input, entity.Name);
                        _dataHandler.AddParameterToCommand(dbCommand, "@intAge", CsType.Int, ParameterDirection.Input, entity.Age);
                        _dataHandler.AddParameterToCommand(dbCommand, "@dtmHiringDate", CsType.DateTime, ParameterDirection.Input, entity.HiringDate);
                        _dataHandler.AddParameterToCommand(dbCommand, "@decGrossSalary", CsType.Decimal, ParameterDirection.Input, entity.GrossSalary);
                        _dataHandler.AddParameterToCommand(dbCommand, "@dtmModifiedDate", CsType.DateTime, ParameterDirection.Input, null);

                        //Output Parameters
                        _dataHandler.AddParameterToCommand(dbCommand, "@intErrorCode", CsType.Int, ParameterDirection.Output, null);

                        //Open Connection
                        if (dbConnection.State != ConnectionState.Open)
                        {
                            dbConnection.Open();
                        }

                        //Execute query.
                        _rowsAffected = dbCommand.ExecuteNonQuery();
                        _errorCode    = int.Parse(dbCommand.Parameters["@intErrorCode"].Value.ToString());

                        if (_errorCode != 0)
                        {
                            // Throw error.
                            throw new Exception("The Insert method for entity [Employees] reported the Database ErrorCode: " + _errorCode);
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                //Bubble error to caller and encapsulate Exception object
                throw new Exception("EmployeesRepository::Insert::Error occured.", ex);
            }
        }
Ejemplo n.º 13
0
        public bool DeleteById(int id)
        {
            _errorCode    = 0;
            _rowsAffected = 0;

            try
            {
                var sb = new StringBuilder();
                sb.Append("DELETE FROM [dbo].[tState]");
                sb.Append("WHERE");
                sb.Append("[stateId]=@stateId;");
                sb.Append("SELECT @intErrorCode = @@ERROR;");

                var commanText = sb.ToString();
                sb.Clear();

                using (var dbConnection = _dbProviderFactory.CreateConnection())
                {
                    if (dbConnection == null)
                    {
                        throw new ArgumentNullException("dbConnection", "the db connection can't be null");
                    }
                    dbConnection.ConnectionString = _connectionString;

                    using (var dbCommand = _dbProviderFactory.CreateCommand())
                    {
                        if (dbCommand == null)
                        {
                            throw new ArgumentNullException("dbCommand", "the db Delete command for entity [State] can't be null");
                        }
                        dbCommand.Connection  = dbConnection;
                        dbCommand.CommandText = commanText;

                        _dataHandler.AddParameterToCommand(dbCommand, "@stateId", csType.Int, ParameterDirection.Input, id);
                        _dataHandler.AddParameterToCommand(dbCommand, "@intErrorCode", csType.Int, ParameterDirection.Output, null);

                        if (dbConnection.State != ConnectionState.Open)
                        {
                            dbConnection.Open();
                        }
                        _rowsAffected = dbCommand.ExecuteNonQuery();
                        _errorCode    = int.Parse(dbCommand.Parameters["@intErrorCode"].Value.ToString());

                        if (_errorCode != 0)
                        {
                            // Throw error.
                            throw new Exception("The Delete method for entity [state] reported the Database ErrorCode: " + _errorCode);
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                //Bubble error to caller and encapsulate Exception object
                throw new Exception("StateRepository::Delete::Error occured.", ex);
            }

            //throw new NotImplementedException();
        }
Ejemplo n.º 14
0
 public ActionResult Choose(int id)
 {
     try
     {
         Session["ChosenOwnerID"] = id;
         return(RedirectToAction("../Sitters/ListAll"));
     }
     catch (Exception ex)
     {
         //Log exception error
         _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);
         ViewBag.Message = Server.HtmlEncode(ex.Message);
         return(View("Error"));
     }
 }
Ejemplo n.º 15
0
 public ActionResult Details(int id)
 {
     try
     {
         var session = SelectSessionById(id);
         return(View(session));
     }
     catch (Exception ex)
     {
         //Log exception error
         _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);
         ViewBag.Message = Server.HtmlEncode(ex.Message);
         return(View("Error"));
     }
 }
Ejemplo n.º 16
0
        // Insert function will insert given parameters into record in SQL Server
        public bool Insert(SessionsEntity entity)
        {
            try
            {
                using (var dbConnection = _dbProviderFactory.CreateConnection())
                {
                    if (dbConnection == null)
                    {
                        throw new ArgumentNullException("dbConnection", "The db connection can't be null.");
                    }

                    dbConnection.ConnectionString = _connectionString;

                    using (var dbCommand = _dbProviderFactory.CreateCommand())
                    {
                        if (dbCommand == null)
                        {
                            throw new ArgumentNullException("dbCommand" + " The db Insert command for entity [Sessions] can't be null. ");
                        }

                        // CODE BELOW USES A STORED PROCEDURE TO INSERT INTO SESSIONS TABLES
                        dbCommand.Connection  = dbConnection;
                        dbCommand.CommandType = CommandType.StoredProcedure;
                        dbCommand.CommandText = "Session_Insert";

                        //Input Parameters
                        _dataHandler.AddParameterToCommand(dbCommand, "@intSitterID", CsType.Int, ParameterDirection.Input, entity.SitterID);
                        _dataHandler.AddParameterToCommand(dbCommand, "@intOwnerID", CsType.Int, ParameterDirection.Input, entity.OwnerID);
                        _dataHandler.AddParameterToCommand(dbCommand, "@chnStatus", CsType.String, ParameterDirection.Input, entity.Status);
                        _dataHandler.AddParameterToCommand(dbCommand, "@decFee", CsType.Decimal, ParameterDirection.Input, entity.Fee);
                        _dataHandler.AddParameterToCommand(dbCommand, "@dtmDate", CsType.DateTime, ParameterDirection.Input, entity.Date);

                        //Output Parameters
                        _dataHandler.AddParameterToCommand(dbCommand, "@intErrorCode", CsType.Int, ParameterDirection.Output, null);

                        //Open Connection
                        if (dbConnection.State != ConnectionState.Open)
                        {
                            dbConnection.Open();
                        }

                        //Execute query.
                        _rowsAffected = dbCommand.ExecuteNonQuery();
                        _errorCode    = int.Parse(dbCommand.Parameters["@intErrorCode"].Value.ToString());

                        if (_errorCode != 0)
                        {
                            // Throw error.
                            throw new Exception("The Insert method for entity [Sessions] reported the Database ErrorCode: " + _errorCode);
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                //Bubble error to caller and encapsulate Exception object
                throw new Exception("SessionsRepository::Insert::Error occured.", ex);
            }
        }
Ejemplo n.º 17
0
        // The following function will insert data from the Create view
        public bool Insert(UsersEntity entity)
        {
            try
            {
                using (var dbConnection = _dbProviderFactory.CreateConnection())
                {
                    if (dbConnection == null)
                    {
                        throw new ArgumentNullException("dbConnection", "The db connection can't be null.");
                    }

                    dbConnection.ConnectionString = _connectionString;

                    using (var dbCommand = _dbProviderFactory.CreateCommand())
                    {
                        if (dbCommand == null)
                        {
                            throw new ArgumentNullException("dbCommand" + " The db Insert command for entity [Owners] can't be null. ");
                        }

                        dbCommand.Connection  = dbConnection;
                        dbCommand.CommandType = CommandType.StoredProcedure;
                        if (entity.Role == "Sitter")
                        {
                            dbCommand.CommandText = "Sitter_Insert";
                        }
                        else if (entity.Role == "Owner")
                        {
                            dbCommand.CommandText = "Owner_Insert";
                        }
                        string hashedpassword = Crypto.HashPassword(entity.Password);
                        //Input Parameters
                        _dataHandler.AddParameterToCommand(dbCommand, "@chnUsername", CsType.String, ParameterDirection.Input, entity.Username);
                        _dataHandler.AddParameterToCommand(dbCommand, "@chnFirstName", CsType.String, ParameterDirection.Input, entity.FirstName);
                        _dataHandler.AddParameterToCommand(dbCommand, "@chnLastName", CsType.String, ParameterDirection.Input, entity.LastName);
                        _dataHandler.AddParameterToCommand(dbCommand, "@chnEmail", CsType.String, ParameterDirection.Input, entity.Email);
                        _dataHandler.AddParameterToCommand(dbCommand, "@chnPassword", CsType.String, ParameterDirection.Input, hashedpassword);
                        _dataHandler.AddParameterToCommand(dbCommand, "@intAge", CsType.Int, ParameterDirection.Input, entity.Age);
                        _dataHandler.AddParameterToCommand(dbCommand, "@binIsActive", CsType.Boolean, ParameterDirection.Input, entity.IsActive);
                        _dataHandler.AddParameterToCommand(dbCommand, "@chnRole", CsType.String, ParameterDirection.Input, entity.Role);

                        // Insert User record information based on role
                        if (entity.Role == "Sitter")
                        {
                            _dataHandler.AddParameterToCommand(dbCommand, "@chnName", CsType.String, ParameterDirection.Input, entity.Name);
                            _dataHandler.AddParameterToCommand(dbCommand, "@decFee", CsType.Decimal, ParameterDirection.Input, entity.Fee);
                            _dataHandler.AddParameterToCommand(dbCommand, "@chnBio", CsType.String, ParameterDirection.Input, entity.Bio);
                            _dataHandler.AddParameterToCommand(dbCommand, "@dtmHiringDate", CsType.DateTime, ParameterDirection.Input, entity.HiringDate);
                            _dataHandler.AddParameterToCommand(dbCommand, "@decGrossSalary", CsType.Decimal, ParameterDirection.Input, entity.GrossSalary);
                        }
                        else if (entity.Role == "Owner")
                        {
                            _dataHandler.AddParameterToCommand(dbCommand, "@chnOwnerName", CsType.String, ParameterDirection.Input, entity.OwnerName);
                            _dataHandler.AddParameterToCommand(dbCommand, "@chnPetName", CsType.String, ParameterDirection.Input, entity.PetName);
                            _dataHandler.AddParameterToCommand(dbCommand, "@intPetAge", CsType.Int, ParameterDirection.Input, entity.PetAge);
                            _dataHandler.AddParameterToCommand(dbCommand, "@chnContactPhone", CsType.String, ParameterDirection.Input, entity.ContactPhone);
                        }

                        //Output Parameters
                        _dataHandler.AddParameterToCommand(dbCommand, "@intErrorCode", CsType.Int, ParameterDirection.Output, null);

                        //Open Connection
                        if (dbConnection.State != ConnectionState.Open)
                        {
                            dbConnection.Open();
                        }

                        //Execute query.
                        _rowsAffected = dbCommand.ExecuteNonQuery();
                        _errorCode    = int.Parse(dbCommand.Parameters["@intErrorCode"].Value.ToString());

                        if (_errorCode != 0)
                        {
                            // Throw error.
                            throw new Exception("The Insert method for entity [Users] reported the Database ErrorCode: " + _errorCode);
                        }
                    }
                }

                #region Depricated code By Role

                /* Depricated code
                 *
                 * if (entity.Role == "Owner")
                 * {
                 *  var newuserid = 0;
                 *  sb.Clear();
                 *  sb.Append("SET DATEFORMAT DMY; ");
                 *  sb.Append("SELECT UserID ");
                 *  sb.Append("FROM [Users] ");
                 *  sb.Append("WHERE Username = @chnUsername ");
                 *  sb.Append("SELECT @intErrorCode=@@ERROR; ");
                 *
                 *  commandText = sb.ToString();
                 *  sb.Clear();
                 *
                 *  using (var dbConnection = _dbProviderFactory.CreateConnection())
                 *  {
                 *      if (dbConnection == null)
                 *          throw new ArgumentNullException("dbConnection", "The db connection can't be null.");
                 *
                 *      dbConnection.ConnectionString = _connectionString;
                 *
                 *      using (var dbCommand = _dbProviderFactory.CreateCommand())
                 *      {
                 *          if (dbCommand == null)
                 *              throw new ArgumentNullException("dbCommand" + " The db Get command for entity [Owners] can't be null. ");
                 *
                 *          dbCommand.Connection = dbConnection;
                 *          dbCommand.CommandText = commandText;
                 *          //Input Parameters
                 *          _dataHandler.AddParameterToCommand(dbCommand, "@chnUsername", CsType.String, ParameterDirection.Input, entity.Username);
                 *
                 *          //Output Parameters
                 *          _dataHandler.AddParameterToCommand(dbCommand, "@intErrorCode", CsType.Int, ParameterDirection.Output, null);
                 *          //Open Connection
                 *          if (dbConnection.State != ConnectionState.Open)
                 *              dbConnection.Open();
                 *
                 *          //Execute query.
                 *          using (var reader = dbCommand.ExecuteReader())
                 *          {
                 *              if (reader.HasRows)
                 *              {
                 *                  while (reader.Read())
                 *                  {
                 *                      newuserid = reader.GetInt32(0);
                 *                  }
                 *              }
                 *          }
                 *      }
                 *  }
                 *  if (newuserid != 0)
                 *  {
                 *      sb.Clear();
                 *      sb.Append("SET DATEFORMAT DMY; ");
                 *      sb.Append("INSERT [Owners] ");
                 *      sb.Append("( ");
                 *      sb.Append("[OwnerName], ");
                 *      sb.Append("[PetName], ");
                 *      sb.Append("[PetAge], ");
                 *      sb.Append("[ContactPhone], ");
                 *      sb.Append("[ModifiedDate], ");
                 *      sb.Append("[UserID] ");
                 *      sb.Append(") ");
                 *      sb.Append("VALUES (");
                 *      sb.Append("@chnOwnerName, ");
                 *      sb.Append("@chnPetName, ");
                 *      sb.Append("@intPetAge, ");
                 *      sb.Append("@chnContactPhone, ");
                 *      sb.Append("ISNULL(@dtmModifiedDate, (getdate())), ");
                 *      sb.Append("@intUserID ");
                 *      sb.Append(") ");
                 *      sb.Append("SELECT @intErrorCode=@@ERROR; ");
                 *
                 *      commandText = sb.ToString();
                 *      sb.Clear();
                 *
                 *      using (var dbConnection = _dbProviderFactory.CreateConnection())
                 *      {
                 *          if (dbConnection == null)
                 *              throw new ArgumentNullException("dbConnection", "The db connection can't be null.");
                 *
                 *          dbConnection.ConnectionString = _connectionString;
                 *
                 *          using (var dbCommand = _dbProviderFactory.CreateCommand())
                 *          {
                 *              if (dbCommand == null)
                 *                  throw new ArgumentNullException("dbCommand" + " The db Insert command for entity [Owners] can't be null. ");
                 *
                 *              dbCommand.Connection = dbConnection;
                 *              dbCommand.CommandText = commandText;
                 *
                 *              //Input Parameters
                 *              _dataHandler.AddParameterToCommand(dbCommand, "@chnOwnerName", CsType.String, ParameterDirection.Input, entity.OwnerName);
                 *              _dataHandler.AddParameterToCommand(dbCommand, "@chnPetName", CsType.String, ParameterDirection.Input, entity.PetName);
                 *              _dataHandler.AddParameterToCommand(dbCommand, "@intPetAge", CsType.Int, ParameterDirection.Input, entity.PetAge);
                 *              _dataHandler.AddParameterToCommand(dbCommand, "@chnContactPhone", CsType.String, ParameterDirection.Input, entity.ContactPhone);
                 *              _dataHandler.AddParameterToCommand(dbCommand, "@intUserID", CsType.Int, ParameterDirection.Input, newuserid);
                 *              _dataHandler.AddParameterToCommand(dbCommand, "@dtmModifiedDate", CsType.DateTime, ParameterDirection.Input, null);
                 *
                 *
                 *              //Output Parameters
                 *              _dataHandler.AddParameterToCommand(dbCommand, "@intErrorCode", CsType.Int, ParameterDirection.Output, null);
                 *
                 *              //Open Connection
                 *              if (dbConnection.State != ConnectionState.Open)
                 *                  dbConnection.Open();
                 *
                 *              //Execute query.
                 *              _rowsAffected = dbCommand.ExecuteNonQuery();
                 *              _errorCode = int.Parse(dbCommand.Parameters["@intErrorCode"].Value.ToString());
                 *
                 *              if (_errorCode != 0)
                 *              {
                 *                  // Throw error.
                 *                  throw new Exception("The Insert method for entity [Owners] reported the Database ErrorCode: " + _errorCode);
                 *              }
                 *
                 *          }
                 *      }
                 *  }
                 * }
                 * if (entity.Role == "Sitter")
                 * {
                 *  var newuserid = 0;
                 *  sb.Clear();
                 *  sb.Append("SET DATEFORMAT DMY; ");
                 *  sb.Append("SELECT UserID ");
                 *  sb.Append("FROM [Users] ");
                 *  sb.Append("WHERE Username = @chnUsername ");
                 *  sb.Append("SELECT @intErrorCode=@@ERROR; ");
                 *
                 *  commandText = sb.ToString();
                 *  sb.Clear();
                 *
                 *  using (var dbConnection = _dbProviderFactory.CreateConnection())
                 *  {
                 *      if (dbConnection == null)
                 *          throw new ArgumentNullException("dbConnection", "The db connection can't be null.");
                 *
                 *      dbConnection.ConnectionString = _connectionString;
                 *
                 *      using (var dbCommand = _dbProviderFactory.CreateCommand())
                 *      {
                 *          if (dbCommand == null)
                 *              throw new ArgumentNullException("dbCommand" + " The db Get command for entity [Owners] can't be null. ");
                 *
                 *          dbCommand.Connection = dbConnection;
                 *          dbCommand.CommandText = commandText;
                 *          //Input Parameters
                 *          _dataHandler.AddParameterToCommand(dbCommand, "@chnUsername", CsType.String, ParameterDirection.Input, entity.Username);
                 *
                 *          //Output Parameters
                 *          _dataHandler.AddParameterToCommand(dbCommand, "@intErrorCode", CsType.Int, ParameterDirection.Output, null);
                 *          //Open Connection
                 *          if (dbConnection.State != ConnectionState.Open)
                 *              dbConnection.Open();
                 *
                 *          //Execute query.
                 *          using (var reader = dbCommand.ExecuteReader())
                 *          {
                 *              if (reader.HasRows)
                 *              {
                 *                  while (reader.Read())
                 *                  {
                 *                      newuserid = reader.GetInt32(0);
                 *                  }
                 *              }
                 *          }
                 *      }
                 *  }
                 *  if (newuserid != 0)
                 *  {
                 *      sb.Clear();
                 *      sb.Append("SET DATEFORMAT DMY; ");
                 *      sb.Append("INSERT [Sitters] ");
                 *      sb.Append("( ");
                 *      sb.Append("[Name], ");
                 *      sb.Append("[Fee], ");
                 *      sb.Append("[Bio], ");
                 *      sb.Append("[Age], ");
                 *      sb.Append("[HiringDate], ");
                 *      sb.Append("[GrossSalary], ");
                 *      sb.Append("[ModifiedDate], ");
                 *      sb.Append("[UserID] ");
                 *      sb.Append(") ");
                 *      sb.Append("VALUES (");
                 *      sb.Append("@chnName, ");
                 *      sb.Append("@decFee, ");
                 *      sb.Append("@chnBio, ");
                 *      sb.Append("@intAge, ");
                 *      sb.Append("@dtmHiringDate, ");
                 *      sb.Append("@decGrossSalary, ");
                 *      sb.Append("ISNULL(@dtmModifiedDate, (getdate())), ");
                 *      sb.Append("@intUserID ");
                 *      sb.Append(") ");
                 *      sb.Append("SELECT @intErrorCode=@@ERROR; ");
                 *
                 *      commandText = sb.ToString();
                 *      sb.Clear();
                 *
                 *      using (var dbConnection = _dbProviderFactory.CreateConnection())
                 *      {
                 *          if (dbConnection == null)
                 *              throw new ArgumentNullException("dbConnection", "The db connection can't be null.");
                 *
                 *          dbConnection.ConnectionString = _connectionString;
                 *
                 *          using (var dbCommand = _dbProviderFactory.CreateCommand())
                 *          {
                 *              if (dbCommand == null)
                 *                  throw new ArgumentNullException("dbCommand" + " The db Insert command for entity [Owners] can't be null. ");
                 *
                 *              dbCommand.Connection = dbConnection;
                 *              dbCommand.CommandText = commandText;
                 *
                 *              //Input Parameters
                 *              _dataHandler.AddParameterToCommand(dbCommand, "@chnName", CsType.String, ParameterDirection.Input, entity.Name);
                 *              _dataHandler.AddParameterToCommand(dbCommand, "@decFee", CsType.Decimal, ParameterDirection.Input, entity.Fee);
                 *              _dataHandler.AddParameterToCommand(dbCommand, "@chnBio", CsType.String, ParameterDirection.Input, entity.Bio);
                 *              _dataHandler.AddParameterToCommand(dbCommand, "@intAge", CsType.Int, ParameterDirection.Input, entity.Age);
                 *              _dataHandler.AddParameterToCommand(dbCommand, "@intUserID", CsType.Int, ParameterDirection.Input, newuserid);
                 *              _dataHandler.AddParameterToCommand(dbCommand, "@dtmHiringDate", CsType.DateTime, ParameterDirection.Input, entity.HiringDate);
                 *              _dataHandler.AddParameterToCommand(dbCommand, "@decGrossSalary", CsType.Decimal, ParameterDirection.Input, entity.GrossSalary);
                 *              _dataHandler.AddParameterToCommand(dbCommand, "@dtmModifiedDate", CsType.DateTime, ParameterDirection.Input, null);
                 *
                 *
                 *              //Output Parameters
                 *              _dataHandler.AddParameterToCommand(dbCommand, "@intErrorCode", CsType.Int, ParameterDirection.Output, null);
                 *
                 *              //Open Connection
                 *              if (dbConnection.State != ConnectionState.Open)
                 *                  dbConnection.Open();
                 *
                 *              //Execute query.
                 *              _rowsAffected = dbCommand.ExecuteNonQuery();
                 *              _errorCode = int.Parse(dbCommand.Parameters["@intErrorCode"].Value.ToString());
                 *
                 *              if (_errorCode != 0)
                 *              {
                 *                  // Throw error.
                 *                  throw new Exception("The Insert method for entity [Owners] reported the Database ErrorCode: " + _errorCode);
                 *              }
                 *
                 *          }
                 *      }
                 *  }
                 * }
                 */
                #endregion
                return(true);
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                //Bubble error to caller and encapsulate Exception object
                throw new Exception("UsersRepository::Insert::Error occured.", ex);
            }
        }
Ejemplo n.º 18
0
        // The following function will insert data from the Create view
        public bool Insert(OwnersEntity entity)
        {
            try
            {
                using (var dbConnection = _dbProviderFactory.CreateConnection())
                {
                    if (dbConnection == null)
                    {
                        throw new ArgumentNullException("dbConnection", "The db connection can't be null.");
                    }

                    dbConnection.ConnectionString = _connectionString;

                    using (var dbCommand = _dbProviderFactory.CreateCommand())
                    {
                        if (dbCommand == null)
                        {
                            throw new ArgumentNullException("dbCommand" + " The db Insert command for entity [Owners] can't be null. ");
                        }

                        // CODE BELOW INSERTS USER INFORMATION INTO MULTIPLE TABLES
                        dbCommand.Connection  = dbConnection;
                        dbCommand.CommandType = CommandType.StoredProcedure;
                        dbCommand.CommandText = "Owner_Insert";

                        string hashedpassword = Crypto.HashPassword(entity.Password);
                        //Input Parameters
                        _dataHandler.AddParameterToCommand(dbCommand, "@chnUsername", CsType.String, ParameterDirection.Input, entity.Username);
                        _dataHandler.AddParameterToCommand(dbCommand, "@chnFirstName", CsType.String, ParameterDirection.Input, entity.FirstName);
                        _dataHandler.AddParameterToCommand(dbCommand, "@chnLastName", CsType.String, ParameterDirection.Input, entity.LastName);
                        _dataHandler.AddParameterToCommand(dbCommand, "@chnEmail", CsType.String, ParameterDirection.Input, entity.Email);
                        _dataHandler.AddParameterToCommand(dbCommand, "@chnPassword", CsType.String, ParameterDirection.Input, hashedpassword);
                        _dataHandler.AddParameterToCommand(dbCommand, "@binIsActive", CsType.Boolean, ParameterDirection.Input, entity.IsActive);
                        _dataHandler.AddParameterToCommand(dbCommand, "@intAge", CsType.Int, ParameterDirection.Input, entity.Age);
                        _dataHandler.AddParameterToCommand(dbCommand, "@chnRole", CsType.String, ParameterDirection.Input, entity.Role);
                        _dataHandler.AddParameterToCommand(dbCommand, "@chnOwnerName", CsType.String, ParameterDirection.Input, entity.OwnerName);
                        _dataHandler.AddParameterToCommand(dbCommand, "@chnPetName", CsType.String, ParameterDirection.Input, entity.PetName);
                        _dataHandler.AddParameterToCommand(dbCommand, "@intPetAge", CsType.Int, ParameterDirection.Input, entity.PetAge);
                        _dataHandler.AddParameterToCommand(dbCommand, "@chnContactPhone", CsType.String, ParameterDirection.Input, entity.ContactPhone);

                        //Output Parameters
                        _dataHandler.AddParameterToCommand(dbCommand, "@intErrorCode", CsType.Int, ParameterDirection.Output, null);

                        //Open Connection
                        if (dbConnection.State != ConnectionState.Open)
                        {
                            dbConnection.Open();
                        }

                        //Execute query.
                        _rowsAffected = dbCommand.ExecuteNonQuery();
                        _errorCode    = int.Parse(dbCommand.Parameters["@intErrorCode"].Value.ToString());

                        if (_errorCode != 0)
                        {
                            // Throw error.
                            throw new Exception("The Insert method for entity [Owners] reported the Database ErrorCode: " + _errorCode);
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                //Bubble error to caller and encapsulate Exception object
                throw new Exception("OwnersRepository::Insert::Error occured.", ex);
            }
        }
Ejemplo n.º 19
0
 public ActionResult Choose(int id, decimal fee)
 {
     try
     {
         Session["ChosenSitterID"]  = id;
         Session["ChosenSitterFee"] = fee;
         return(RedirectToAction("../Sessions/CreateByOwner/" + Session["ChosenOwnerID"]));
     }
     catch (Exception ex)
     {
         //Log exception error
         _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);
         ViewBag.Message = Server.HtmlEncode(ex.Message);
         return(View("Error"));
     }
 }
Ejemplo n.º 20
0
        public bool Insert(PersonsEntity entity)
        {
            try
            {
                var sb = new StringBuilder();
                sb.Append("INSERT [TechTest].[Persons] ");
                sb.Append("( ");
                sb.Append("[PersonId], ");
                sb.Append("[Firstname], ");
                sb.Append("[Surname], ");
                sb.Append("[Gender], ");
                sb.Append("[EmailAddress], ");
                sb.Append("[PhoneNumber] ");
                sb.Append(") ");
                sb.Append("VALUES ");
                sb.Append("( ");
                sb.Append(" @intId, ");
                sb.Append(" @chnName, ");
                sb.Append(" @intAge, ");
                sb.Append(" @dtmHiringDate, ");
                sb.Append(" @decGrossSalary, ");
                sb.Append(" ISNULL(@dtmModifiedDate, (getdate())) ");
                sb.Append(") ");
                sb.Append("SELECT @intErrorCode=@@ERROR; ");

                var commandText = sb.ToString();
                sb.Clear();

                using (var dbConnection = _dbProviderFactory.CreateConnection())
                {
                    if (dbConnection == null)
                    {
                        throw new ArgumentNullException("dbConnection", "The db connection can't be null.");
                    }

                    dbConnection.ConnectionString = _connectionString;

                    using (var dbCommand = _dbProviderFactory.CreateCommand())
                    {
                        if (dbCommand == null)
                        {
                            throw new ArgumentNullException("dbCommand" + " The db Insert command for entity [Persons] can't be null. ");
                        }

                        dbCommand.Connection  = dbConnection;
                        dbCommand.CommandText = commandText;

                        //Input Parameters
                        _dataHandler.AddParameterToCommand(dbCommand, "@personId", CsType.Int, ParameterDirection.Input, entity.PersonId);
                        _dataHandler.AddParameterToCommand(dbCommand, "@firstName", CsType.Int, ParameterDirection.Input, entity.Firstname);
                        _dataHandler.AddParameterToCommand(dbCommand, "@surname", CsType.Int, ParameterDirection.Input, entity.Surname);
                        _dataHandler.AddParameterToCommand(dbCommand, "@gender", CsType.Int, ParameterDirection.Input, entity.Gender);
                        _dataHandler.AddParameterToCommand(dbCommand, "@emailAddress", CsType.Int, ParameterDirection.Input, entity.EmailAddress);
                        _dataHandler.AddParameterToCommand(dbCommand, "@phoneNumber", CsType.Int, ParameterDirection.Input, entity.PhoneNumber);

                        //Output Parameters
                        _dataHandler.AddParameterToCommand(dbCommand, "@intErrorCode", CsType.Int, ParameterDirection.Output, null);

                        //Open Connection
                        if (dbConnection.State != ConnectionState.Open)
                        {
                            dbConnection.Open();
                        }

                        //Execute query.
                        _rowsAffected = dbCommand.ExecuteNonQuery();
                        _errorCode    = int.Parse(dbCommand.Parameters["@intErrorCode"].Value.ToString());

                        if (_errorCode != 0)
                        {
                            // Throw error.
                            throw new Exception("The Insert method for entity [Persons] reported the Database ErrorCode: " + _errorCode);
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                //Bubble error to caller and encapsulate Exception object
                throw new Exception("PersonsRepository::Insert::Error occured.", ex);
            }
        }
        public bool Insert(SuburbEntity entity)
        {
            try
            {
                var sb = new StringBuilder();
                sb.Append("INSERT [dbo].[Suburb] ");
                sb.Append("( ");
                sb.Append("[SuburbName],");
                sb.Append("[StateId]");
                sb.Append(") ");
                sb.Append("VALUES ");
                sb.Append("( ");
                sb.Append(" @SuburbName,");
                sb.Append(" @StateId");
                sb.Append(") ");
                sb.Append("SELECT @intErrorCode=@@ERROR; ");


                var commandText = sb.ToString();
                sb.Clear();

                using (var dbConnection = _dbProviderFactory.CreateConnection())
                {
                    if (dbConnection == null)
                    {
                        throw new ArgumentNullException("dbConnection", "The db connection can't be null.");
                    }

                    dbConnection.ConnectionString = _connectionString;

                    using (var dbCommand = _dbProviderFactory.CreateCommand())
                    {
                        if (dbCommand == null)
                        {
                            throw new ArgumentNullException("dbCommand" + " The db Insert command for entity [Suburb] can't be null. ");
                        }

                        dbCommand.Connection  = dbConnection;
                        dbCommand.CommandText = commandText;

                        //Input Parameters
                        _dataHandler.AddParameterToCommand(dbCommand, "@SuburbName", CsType.String, ParameterDirection.Input, entity.SuburbName);
                        _dataHandler.AddParameterToCommand(dbCommand, "@StateId", CsType.String, ParameterDirection.Input, entity.StateId);

                        //Output Parameters
                        _dataHandler.AddParameterToCommand(dbCommand, "@intErrorCode", CsType.Int, ParameterDirection.Output, null);

                        //Open Connection
                        if (dbConnection.State != ConnectionState.Open)
                        {
                            dbConnection.Open();
                        }

                        //Execute query.
                        _rowsAffected = dbCommand.ExecuteNonQuery();
                        _errorCode    = int.Parse(dbCommand.Parameters["@intErrorCode"].Value.ToString());

                        if (_errorCode != 0)
                        {
                            // Throw error.
                            throw new Exception("The Insert method for entity [Suburb] reported the Database ErrorCode: " + _errorCode);
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                //Log exception error
                _loggingHandler.LogEntry(ExceptionHandler.GetExceptionMessageFormatted(ex), true);

                //Bubble error to caller and encapsulate Exception object
                throw new Exception("SuburbRepository::Insert::Error occured.", ex);
            }
        }