Пример #1
0
 //Admin Can see all user data
 //Dealer can see only dealer data associated with dealer username
 //[Authorize(Roles="Admin")]
 public ActionResult Index()
 {
     //By Default user is not an admin user
     Boolean IsAdmin =false;
     //Check if the user is an admin user
     if (Roles.IsUserInRole(User.Identity.Name, "Admin"))
         IsAdmin = true;
     //Create an object for the commission model
     CommissionModel Commissions = new CommissionModel();
     //Get the commission result, if an admin then retrive all data and if dealer then get the data associated with username
     var result = Commissions.GetCommission(User.Identity.Name, IsAdmin);
     //List<Havas_Exercise.Models.CommissionModel> C = result.ToList();
     return View(result);
 }
Пример #2
0
 public ActionResult Index(DateTime? StartDate=null,DateTime? EndDate=null,int PaymentStatus=0)
 {
     //By default user is not an admin user
     Boolean IsAdmin = false;
     //Check if the user is logged in as admin user
     if (Roles.IsUserInRole(User.Identity.Name, "Admin"))
         IsAdmin = true;
     //Create a commission model
     CommissionModel Commissions = new CommissionModel();
     //Passing the value to the method
     var result = Commissions.GetCommission(User.Identity.Name, IsAdmin,StartDate,EndDate,PaymentStatus);
     //List<Havas_Exercise.Models.CommissionModel> C = result.ToList();
     //pass the result to view which is a Index view
     return View(result);
 }
Пример #3
0
        //Get the commission
        //username: user's login name
        //isadmin : if the user is an admin user or not
        //startdate: if user wants to get the report for a specific date, put a startdate
        //enddate: if user wants to get the report for a specific date, put a enddate
        //status: get the report based on status value(Created=1 , Verified =2,Rejected=3,Awaiting Payment=4,Paid=5,Refunded =6)
        public List<CommissionModel> GetCommission(string username,bool isadmin, DateTime? startdate=null,DateTime? enddate=null,int status=0)
        {
            try
            {
                //Create a List for storing a Commission data
                List<CommissionModel> CommissionReport = new List<CommissionModel>();
                using (cn = new SqlConnection(ConnectionString))
                {
                    //open the connection
                    cn.Open();
                    cmd = new SqlCommand("GetCommissionReport", cn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@IsAdmin", isadmin);
                    cmd.Parameters.AddWithValue("@UserName", username);
                    cmd.Parameters.AddWithValue("@StartDate", startdate);
                    cmd.Parameters.AddWithValue("@EndDate", enddate);
                    cmd.Parameters.AddWithValue("@status",status);

                    dr = cmd.ExecuteReader();
                    //if readwer has rows
                    if (dr.HasRows)
                    {
                        //read all the value
                        while(dr.Read())
                        {
                            //create the commission object
                            CommissionModel commission = new CommissionModel();
                            commission.CommissionID = Convert.ToInt32(dr["CommissionId"]);
                            commission.CustomerID = Convert.ToInt32(dr["CustomerId"]);
                            commission.DealerID =  Convert.ToInt32(dr["DealerId"]);
                            commission.DealerName = dr["Name"].ToString();
                            commission.ProductID =  Convert.ToInt32(dr["ProductId"]);
                            commission.CommissionAmount = Convert.ToDecimal(dr["CommissionAmount"])  ;
                            //Switch case for displaying a payment status
                            switch (Convert.ToUInt32(dr["PaymentStatusId"] ))
                            {
                                case 1:
                                    commission.PaymentStatus ="Created";
                                   break;
                                case 2:
                                   commission.PaymentStatus ="Verified";
                                   break;
                                case 3:
                                    commission.PaymentStatus ="Rejected";
                                    break;
                                case 4:
                                    commission.PaymentStatus ="Awaiting Payment";
                                    break;
                                case 5:
                                    commission.PaymentStatus ="Paid";
                                    break;
                                case 6:
                                    commission.PaymentStatus ="Refunded";
                                    break;
                            }
                            commission.CreatedDate =  Convert.ToDateTime(dr["CreatedDate"]);
                            commission.ModifiedDate =  Convert.ToDateTime(dr["ModifiedDate"]);
                            //Add the commission object to list
                            CommissionReport.Add(commission) ;
                       }
                   }
                }
                //close the connection
                cn.Close();
                //return the Commission List
                return CommissionReport;
            }
            catch(Exception ex)
            {
                //if any error close the connection
                cn.Close();
                //Please log the error
                return null;
            }
        }
Пример #4
0
        //Get the commission
        //username: user's login name
        //isadmin : if the user is an admin user or not
        //startdate: if user wants to get the report for a specific date, put a startdate
        //enddate: if user wants to get the report for a specific date, put a enddate
        //status: get the report based on status value(Created=1 , Verified =2,Rejected=3,Awaiting Payment=4,Paid=5,Refunded =6)

        public List <CommissionModel> GetCommission(string username, bool isadmin, DateTime?startdate = null, DateTime?enddate = null, int status = 0)
        {
            try
            {
                //Create a List for storing a Commission data
                List <CommissionModel> CommissionReport = new List <CommissionModel>();
                using (cn = new SqlConnection(ConnectionString))
                {
                    //open the connection
                    cn.Open();
                    cmd             = new SqlCommand("GetCommissionReport", cn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@IsAdmin", isadmin);
                    cmd.Parameters.AddWithValue("@UserName", username);
                    cmd.Parameters.AddWithValue("@StartDate", startdate);
                    cmd.Parameters.AddWithValue("@EndDate", enddate);
                    cmd.Parameters.AddWithValue("@status", status);

                    dr = cmd.ExecuteReader();
                    //if readwer has rows
                    if (dr.HasRows)
                    {
                        //read all the value
                        while (dr.Read())
                        {
                            //create the commission object
                            CommissionModel commission = new CommissionModel();
                            commission.CommissionID     = Convert.ToInt32(dr["CommissionId"]);
                            commission.CustomerID       = Convert.ToInt32(dr["CustomerId"]);
                            commission.DealerID         = Convert.ToInt32(dr["DealerId"]);
                            commission.DealerName       = dr["Name"].ToString();
                            commission.ProductID        = Convert.ToInt32(dr["ProductId"]);
                            commission.CommissionAmount = Convert.ToDecimal(dr["CommissionAmount"]);
                            //Switch case for displaying a payment status
                            switch (Convert.ToUInt32(dr["PaymentStatusId"]))
                            {
                            case 1:
                                commission.PaymentStatus = "Created";
                                break;

                            case 2:
                                commission.PaymentStatus = "Verified";
                                break;

                            case 3:
                                commission.PaymentStatus = "Rejected";
                                break;

                            case 4:
                                commission.PaymentStatus = "Awaiting Payment";
                                break;

                            case 5:
                                commission.PaymentStatus = "Paid";
                                break;

                            case 6:
                                commission.PaymentStatus = "Refunded";
                                break;
                            }
                            commission.CreatedDate  = Convert.ToDateTime(dr["CreatedDate"]);
                            commission.ModifiedDate = Convert.ToDateTime(dr["ModifiedDate"]);
                            //Add the commission object to list
                            CommissionReport.Add(commission);
                        }
                    }
                }
                //close the connection
                cn.Close();
                //return the Commission List
                return(CommissionReport);
            }
            catch (Exception ex)
            {
                //if any error close the connection
                cn.Close();
                //Please log the error
                return(null);
            }
        }