Ejemplo n.º 1
0
        public List <Customer> GetAllUsers()
        {
            DbOutput dbOut = this.accountRepository.GetAllUsers();

            if (dbOut.Result == DbResult.Faild)
            {
                Console.WriteLine(dbOut.ErrorMessage);
                return(null);
            }

            List <Customer> users = new List <Customer>();

            for (int i = 0; i < dbOut.OutElements.Count; i += 5)
            {
                var user = new Customer()
                {
                    UserId   = Convert.ToInt32(dbOut.OutElements.ElementAt(i)),
                    Email    = dbOut.OutElements.ElementAt(i + 1).ToString(),
                    SurName  = dbOut.OutElements.ElementAt(i + 2).ToString(),
                    UserRole = new Role()
                    {
                        Id   = Convert.ToInt32(dbOut.OutElements.ElementAt(i + 3)),
                        Name = dbOut.OutElements.ElementAt(i + 4).ToString()
                    }
                };
                users.Add(user);
            }

            return(users);
        }
Ejemplo n.º 2
0
        protected DbOutput ExecuteNonQueryUsingSPOut(string spName, List <SqlParameter> param)
        {
            DbOutput result = new DbOutput();

            OpenConnection();
            cmd             = new SqlCommand();
            cmd.CommandText = spName;
            cmd.CommandType = CommandType.StoredProcedure;
            foreach (SqlParameter p in param)
            {
                cmd.Parameters.Add(p);
            }
            SqlParameter oParam = new SqlParameter();

            oParam.ParameterName = "@OutPutKey";
            oParam.Direction     = ParameterDirection.Output;
            oParam.DbType        = DbType.Int32;
            cmd.Parameters.Add(oParam);

            cmd.Connection = con;
            cmd.ExecuteNonQuery();
            CloseConnection();
            result.DbVal = Convert.ToInt32(oParam.Value);
            return(result);
        }
Ejemplo n.º 3
0
        public OutputService SelectOutput(string outputType)
        {
            OutputService service;

            switch (outputType)
            {
            case "ConsoleMessageService":
                service = new ConsoleOutput();
                break;

            case "InMemoryMessageService":
                service = new DbOutput();
                break;

            case "MobileMessageService":
                service = new FileOutput();
                break;

            default:
                service = new ConsoleOutput();
                break;
            }


            return(service);
        }
Ejemplo n.º 4
0
        public Customer ChangeRole(int userId, int roleId)
        {
            DbOutput dbOut = this.accountRepository.ChangeRole(userId, roleId);

            if (dbOut.Result == DbResult.Faild)
            {
                Console.WriteLine(dbOut.ErrorMessage);
                return(null);
            }
            var user = this.GetUser(userId);

            return(user);
        }
Ejemplo n.º 5
0
        public DbOutput RunDbRequest(string funckName, bool mustRespond = false, Tuple <string, OracleDbType, object>[] args = null, Tuple <string, OracleDbType> returnVal = null)
        {
            string connectionString = $"User Id={this.configuration["Authentication:Login"]};Password={this.configuration["Authentication:Password"]};Data Source={this.configuration["Authentication:Schema"]};Connection Timeout=100;";
            var    returnVals       = new DbOutput();

            using (var con = new OracleConnection(connectionString))
            {
                using (OracleCommand cmd = con.CreateCommand())
                {
                    try
                    {
                        cmd.CommandText = funckName;
                        cmd.CommandType = CommandType.StoredProcedure;
                        foreach (Tuple <string, OracleDbType, object> arg in args)
                        {
                            cmd.Parameters.Add(arg.Item1, arg.Item2).Value = arg.Item3;
                        }
                        con.Open();
                        if (mustRespond)
                        {
                            returnVals.OutElements = new List <object>();
                            cmd.Parameters.Add(returnVal.Item1, returnVal.Item2).Direction = ParameterDirection.Output;
                            cmd.ExecuteNonQuery();
                            OracleDataReader rdr = cmd.ExecuteReader();
                            while (rdr.Read())
                            {
                                for (int i = 0; i < rdr.FieldCount; i++)
                                {
                                    returnVals.OutElements.Add(rdr[i]);
                                }
                            }
                        }
                        else
                        {
                            cmd.ExecuteNonQuery();
                        }
                        returnVals.Result = DbResult.Successed;
                    }
                    catch (Exception ex)
                    {
                        returnVals.ErrorMessage = ex.Message.Split("\n").First().Split(":").Last().Remove(0, 1);
                        returnVals.Result       = DbResult.Faild;
                    }
                    finally
                    {
                        con.Close();
                    }
                }
            }
            return(returnVals);
        }
Ejemplo n.º 6
0
        public string Login(string email, string password)
        {
            DbOutput loginResult = this.accountRepository.Login(email, password);

            if (loginResult.Result == DbResult.Faild)
            {
                return(loginResult.ErrorMessage);
            }
            if (loginResult.OutElements.Count == 0)
            {
                return("Some error!");
            }
            return(loginResult.OutElements.SingleOrDefault(element => true).ToString());
        }
Ejemplo n.º 7
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //write logic to save Prescription
            //SavePrescription()


            //save Prescription
            //save PrescriptionDetails
            DoctorBAO bao    = new DoctorBAO();
            DbOutput  result = bao.SavePrescription(Convert.ToInt32(hdnPkId.Value), user.Id, txtRemark.Text);

            //result.DbVal

            foreach (GridViewRow row in grdSelectedMedicine.Rows)
            {
                //PK_Medicineid
                //chkMonrning
                //chkAfternoon
                //chkNight

                int      medicineId = Convert.ToInt32(grdSelectedMedicine.DataKeys[row.RowIndex]["PK_Medicineid"]);
                CheckBox m          = row.FindControl("chkMonrning") as CheckBox;
                CheckBox a          = row.FindControl("chkAfternoon") as CheckBox;
                CheckBox n          = row.FindControl("chkNight") as CheckBox;

                int isMo = 0;
                int isAf = 0;
                int isNi = 0;
                if (m.Checked)
                {
                    isMo = 1;
                }
                if (a.Checked)
                {
                    isAf = 1;
                }
                if (n.Checked)
                {
                    isNi = 1;
                }

                bao.SavePrescriptionDetails(result.DbVal, medicineId, isMo, isAf, isNi, "");
            }
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "Failuer", "alert('Prescription Saved Successfully')", true);
        }
Ejemplo n.º 8
0
        public string Registration(string nickname, string email, string password)
        {
            if (string.IsNullOrEmpty(password))
            {
                return("Password cannot be empty");
            }
            if (password.Length < 8)
            {
                return("Password length cannot be less then 8");
            }
            DbOutput registerResult = this.accountRepository.Registration(nickname, email, password);

            if (registerResult.Result == DbResult.Faild)
            {
                return(registerResult.ErrorMessage = registerResult.ErrorMessage.Substring(0, 1).ToUpper() + registerResult.ErrorMessage.Substring(1, registerResult.ErrorMessage.Length - 1).ToLower());
            }
            return(null);
        }
Ejemplo n.º 9
0
        public static void Main()
        {
            var outputMethod = new DbOutput<Seznamka>();
            //foreach (var scraper in HoroscopeScrapers)
            //{
            //    if (scraper.ShouldScrapeNow())
            //    {
            //        outputMethod.Out(scraper.Scrape());
            //    }
            //}

            var console = new ConsoleOutput<Seznamka>();
            foreach (var scraper in SeznamkyScrapers)
            {
                if (scraper.ShouldScrapeNow())
                {
                    outputMethod.Out(scraper.Scrape());
                }
            }
        }
Ejemplo n.º 10
0
        public Customer GetUser(int userId)
        {
            DbOutput dbOut = this.accountRepository.GetUser(userId);

            if (dbOut.Result == DbResult.Faild)
            {
                Console.WriteLine(dbOut.ErrorMessage);
                return(null);
            }
            var user = new Customer()
            {
                UserId   = Convert.ToInt32(dbOut.OutElements.ElementAt(0)),
                Email    = dbOut.OutElements.ElementAt(1).ToString(),
                SurName  = dbOut.OutElements.ElementAt(2).ToString(),
                UserRole = new Role()
                {
                    Id   = Convert.ToInt32(dbOut.OutElements.ElementAt(3)),
                    Name = dbOut.OutElements.ElementAt(4).ToString()
                }
            };

            return(user);
        }
Ejemplo n.º 11
0
 public async static Task <DbOutput <T> > ExecuteStoredProcAsync <T>(this DbCommand command)
 {
     using (command)
     {
         if (command.Connection.State == System.Data.ConnectionState.Closed)
         {
             command.Connection.Open();
         }
         try
         {
             using (var reader = await command.ExecuteReaderAsync())
             {
                 DbOutput <T> output = new DbOutput <T>();
                 output.AddRange(reader.MapToList <T>());
                 output.DbParameters = command.Parameters;
                 return(output);
             }
         }
         finally
         {
             command.Connection.Close();
         }
     }
 }