private CommissionModel getCommissionModel(int id)
        {
            CommissionModel comMod = new CommissionModel();

            try
            {
                queryString = "SELECT ID, serviceTypeID, commission FROM dbspa.tblcommissions WHERE (isDeleted = 0) AND (ID = ?)";

                parameters = new List <string>();
                parameters.Add(id.ToString());

                MySqlDataReader reader = conDB.getSelectConnection(queryString, parameters);

                while (reader.Read())
                {
                    comMod.ServiceTypeID = reader["serviceTypeID"].ToString();
                    comMod.Commission    = reader["commission"].ToString();
                    comMod.ID1           = reader["ID"].ToString();
                }

                conDB.closeConnection();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            return(comMod);
        }
        //public Tuple<bool, string, long> AddCommissionRequestOld(CommissionModel commissionModel, long universityId)
        //{
        //    try
        //    {
        //        //واکشی دانشجو اگر وجود دارد وگرنه ایجاد می شود
        //        var student =
        //            _studentRepository.Where(s => s.StudentNumber == commissionModel.StudentNumber)
        //                .Include(i => i.Person).Include(i => i.Person.Profile).FirstOrDefault() ??
        //            new Student();
        //        student.StudentNumber = commissionModel.StudentNumber;
        //        student.FieldofStudyId = commissionModel.FieldofStudyId;
        //        student.Grade = commissionModel.Grade;
        //        student.MilitaryServiceStatus = commissionModel.MilitaryServiceStatus;

        //        //واکشی پروفایل اگر وجود دارد
        //        Profile profile;
        //        if (student.Person == null)
        //        {
        //            profile =
        //             _profileRepository.Where(p => p.NationalCode == commissionModel.NationalCode).FirstOrDefault() ??
        //             new Profile();
        //        }
        //        else
        //        {
        //            profile = student.Person.Profile;
        //        }
        //        profile.Name = commissionModel.Name;
        //        profile.Family = commissionModel.Family;
        //        profile.NationalCode = commissionModel.NationalCode;
        //        profile.Gender = commissionModel.Gender;

        //        //واکشی درخواست اگر وجود دارد
        //        var request = _requestRepository.Where(i => i.Id == commissionModel.Id).Include(i => i.Commission)
        //            .Include(i => i.MemberMaster).FirstOrDefault() ?? new Request();
        //        request.RequestType = commissionModel.RequestType;
        //        request.NumberofRemainingUnits = commissionModel.NumberofRemainingUnits;
        //        request.NumberofSpentUnits = commissionModel.NumberofSpentUnits;
        //        request.RequestStatus = commissionModel.RequestStatus;
        //        request.Description = commissionModel.Description;
        //        request.MemberMaster = _memberMasterRepository.Where(d => d.RequestType == RequestType.Comision)
        //            .OrderByDescending(p => p.Id).FirstOrDefault();

        //        long personId = 0;
        //        if (profile.PersonId == 0)
        //        {
        //            var person = new Person
        //            {
        //                Active = true,
        //                UniversityId = universityId,
        //                Profile = profile,
        //                Student = student
        //            };
        //            _personRepository.Add(person);
        //            personId = person.Id;
        //        }
        //        else
        //        {
        //            personId = profile.PersonId;
        //            student.PersonId = profile.PersonId;
        //            _studentRepository.AddOrUpdate(s => s.PersonId, student);
        //        }

        //        var x = new PersianCalendar();
        //        commissionModel.Date =
        //            x.ToDateTime(commissionModel.Date.Year, commissionModel.Date.Month, commissionModel.Date.Day, 0, 0, 0, 0, 0);
        //        //درج درخواست به همراه کمیسیون
        //        if (request.Id > 0)
        //        {
        //            request.Commission.CommissionNumber = commissionModel.CommissionNumber;
        //            request.Commission.Date = commissionModel.Date;
        //            request.Commission.Description = commissionModel.Description;
        //            _requestRepository.Update(request);
        //        }
        //        else
        //        {
        //            request.PersonId = personId;
        //            request.Commission = new Commission
        //            {
        //                CommissionNumber = commissionModel.CommissionNumber,
        //                Date = commissionModel.Date,
        //                Description = commissionModel.Description
        //            };
        //            _requestRepository.Add(request);
        //        }
        //        //آپدیت موارد خاص آموزشی مربوط به درخواست
        //        _commissionSpecialEducationRepository.Delete(c => c.CommissionId == commissionModel.Id);
        //        commissionModel.CommissionSpecialEducations.ForEach(c => c.CommissionId = commissionModel.Id);
        //        _commissionSpecialEducationRepository.Add(commissionModel.CommissionSpecialEducations);
        //        _unitOfWork.SaveChanges();
        //        return new Tuple<bool, string, long>(true, "عملیات ثبت به درستی انجام شد", request.Id);
        //    }
        //    catch (Exception exception)
        //    {
        //        return new Tuple<bool, string, long>(false, "خطا در ثبت درخواست", 0);
        //    }
        //}

        /// <summary>
        /// ذخیره درخواست کمیسیون یا شورا به همراه پروفایل و دانشجو و شخص
        /// </summary>
        /// <param name="commissionModel"></param>
        /// <returns></returns>
        public Tuple <bool, string, long> UpdateCommissionRequest(CommissionModel commissionModel)
        {
            try
            {
                var request = _requestRepository.Where(i => i.Id == commissionModel.Id).Include(i => i.Commission)
                              .Include(i => i.MemberMaster).FirstOrDefault();
                request.NumberofRemainingUnits = commissionModel.NumberofRemainingUnits;
                request.NumberofSpentUnits     = commissionModel.NumberofSpentUnits;
                request.Description            = commissionModel.Description;
                request.MemberMaster           = _memberMasterRepository.Where(d => d.RequestType == RequestType.Comision).OrderByDescending(p => p.Id).FirstOrDefault();

                var x = new PersianCalendar();
                commissionModel.Date =
                    x.ToDateTime(commissionModel.Date.Year, commissionModel.Date.Month, commissionModel.Date.Day, 0, 0, 0, 0, 0);

                request.Commission.CommissionNumber = commissionModel.CommissionNumber;
                request.Commission.Date             = commissionModel.Date;
                request.Commission.Description      = commissionModel.Description;
                _requestRepository.Update(request);

                //آپدیت موارد خاص آموزشی مربوط به درخواست
                _commissionSpecialEducationRepository.Delete(c => c.CommissionId == commissionModel.Id);
                commissionModel.CommissionSpecialEducations.ForEach(c => c.CommissionId = commissionModel.Id);
                _commissionSpecialEducationRepository.Add(commissionModel.CommissionSpecialEducations);
                _unitOfWork.SaveChanges();
                return(new Tuple <bool, string, long>(true, "عملیات ثبت به درستی انجام شد", request.Id));
            }
            catch (Exception exception)
            {
                return(new Tuple <bool, string, long>(false, "خطا در ثبت درخواست", 0));
            }
        }
        private void updateCommissionDetails(CommissionModel comModel)
        {
            try
            {
                CommissionModel stm = cmbServiceType.SelectedItem as CommissionModel;

                queryString = "UPDATE dbspa.tblcommissions SET commission = ? " +
                              "WHERE ID = ?";
                parameters = new List <string>();
                parameters.Add(String.Format("{0:0.00}", txtCommission.Text));
                parameters.Add(comModel.ID1);

                conDB.AddRecordToDatabase(queryString, parameters);

                conDB.closeConnection();

                MessageBox.Show("RECORD UPDATED SUCCESSFULLY!");
                conDB.writeLogFile("UPDATED COMMISSION RECORD: RECORD ID: " + comModel.ID1);
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED TO UPDATE RECORD! " + "," + ex.Message);
            }
        }
Esempio n. 4
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));
        }
Esempio n. 5
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));
        }
Esempio n. 6
0
        public virtual ActionResult Create(string special, CommissionModel commissionModel)
        {
            ModelState.Remove("Id");
            if (!ModelState.IsValid)
            {
                return(Json(new { isError = true, Message = "ورودی نامعتبر!" }));
            }
            //var userId = long.Parse(User.Identity.GetUserId());
            //var data = _personManagementService.IsStudentExist(commissionModel.StudentNumber, userId,
            //            commissionModel.RequestType).Result;
            //if (!data.Item1)
            //    return Json(new { isError = true, Message = data.Item2 });

            string[] arrSpecialEducations = special.Split('&');
            if (arrSpecialEducations.Length > 1)
            {
                string[] fields;
                long     specialId;

                for (var i = 0; i < arrSpecialEducations.Length - 1; i++)
                {
                    fields    = arrSpecialEducations[i].Split(',');
                    specialId = Convert.ToInt64(fields[0]);
                    CommissionSpecialEducation commissionSpecialEducation = new CommissionSpecialEducation
                    {
                        // CommissionId = Convert.ToInt64(commissionModel.Id),
                        SpecialEducationId = specialId
                    };
                    commissionModel.CommissionSpecialEducations.Add(commissionSpecialEducation);
                }
            }
            var userAuthenticationType = (AuthenticationType)Enum.Parse(typeof(AuthenticationType), User.AuthenType(), true);
            var levelId = Convert.ToInt64(User.LevelId());

            commissionModel.RequestType   = RequestType.Comision;
            commissionModel.RequestStatus = RequestStatus.Waiting;
            var result = _comissionService.AddCommissionRequest(commissionModel, levelId);

            return(Json(new { isError = !result.Item1, Message = result.Item2, requestId = result.Item3 }));
        }
        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            CommissionView comView = dgvCommission.SelectedItem as CommissionView;

            if (comView != null)
            {
                int id = Convert.ToInt32(comView.ID);
                if (id != 0)
                {
                    CommissionModel com = getCommissionModel(id);
                    com.ServiceTypeModel = getServiceTypeModel(Convert.ToInt32(com.ServiceTypeID));
                    com.IfEditDetails    = true;

                    CommissionDetails cd = new CommissionDetails(this, com);
                    cd.ShowDialog();
                }
            }
            else
            {
                MessageBox.Show("No record selected!");
            }
        }
 public CommissionDetails(CommissionWindow co, CommissionModel cm)
 {
     comModel = cm;
     comms    = co;
     InitializeComponent();
 }
Esempio n. 9
0
        public IHttpActionResult PostTransaction([FromBody] CommissionModel commissionModel)
        {
            MySqlTransaction mysqlTrx = (dynamic)null;
            MySqlConnection  con      = (dynamic)null;

            try
            {
                WebClient wc = new WebClient();
                wc.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(ApiUsername + ":" + ApiPassword)));
                var totalCommission = (dynamic)null;
                var agentPaidAmt    = (dynamic)null;
                var jamboPaidAmt    = (dynamic)null;

                //get agent Id
                string agentsjson = wc.DownloadString(Baseurl + "api/GetAgents");
                var    agts       = JsonConvert.DeserializeObject <List <ServiceModel> >(agentsjson);
                var    agtresults = (from a in agts where a.agent_email_id == commissionModel.AgentEmailId select a.a_id).SingleOrDefault();
                int    agentId    = Convert.ToInt32(agtresults);


                //get service commission
                string json     = wc.DownloadString(Baseurl + "api/GetServices");
                var    svcs     = JsonConvert.DeserializeObject <List <ServiceModel> >(json);
                var    jsresult = (from a in svcs where a.s_id == commissionModel.ServiceId select a.jambo_comm_percent).SingleOrDefault();

                //get total commission % here
                decimal srvComm = jsresult;
                decimal srvFee  = Convert.ToDecimal(commissionModel.TransactionCost);
                totalCommission = (srvComm / 100) * srvFee;

                //subdivide commision between JamboPay and agents

                //JamboPay gets
                jamboPaidAmt = Convert.ToDecimal(0.6) * totalCommission;

                //Agent gets
                agentPaidAmt = Convert.ToDecimal(0.4) * totalCommission;

                if (string.IsNullOrWhiteSpace(commissionModel.TransactionCost.ToString(CultureInfo.InvariantCulture)))
                {
                    return(Json("lsvcFeeEmpty"));
                }

                using (con = new MySqlConnection(ConString))
                {
                    string insertQry =
                        "INSERT INTO agent_transactions(service_id, agent_id, agent_transaction_cost, agent_commision_amt, jambo_commission_amt) " +
                        "VALUES(@serviceId, @agentId, @trxCost, @agentCommAmt, @jamboCommAmt)";

                    con.Open();
                    MySqlCommand command = new MySqlCommand(insertQry, con);
                    // Start a local transaction
                    mysqlTrx = con.BeginTransaction();
                    // assign both transaction object and connection to Command object for a pending local transaction
                    command.Connection  = con;
                    command.Transaction = mysqlTrx;

                    //use parametarized queries to prevent sql injection
                    command.Parameters.AddWithValue("@serviceId", commissionModel.ServiceId);
                    command.Parameters.AddWithValue("@agentId", agentId);
                    command.Parameters.AddWithValue("@trxCost", commissionModel.TransactionCost);
                    command.Parameters.AddWithValue("@agentCommAmt", agentPaidAmt);
                    command.Parameters.AddWithValue("@jamboCommAmt", jamboPaidAmt);

                    if (command.ExecuteNonQuery() == 1)
                    {
                        //commit the insert transaction to dB
                        mysqlTrx.Commit();
                        return(Ok("success"));
                    }
                    con.Close();
                    return(Ok("Error Occured!"));
                }
            }
            catch (MySqlException ex)
            {
                try
                {
                    //rollback the transaction if any error occurs during the process of inserting
                    con.Open();
                    mysqlTrx.Rollback();
                    con.Close();
                }
                catch (MySqlException ex2)
                {
                    if (mysqlTrx.Connection != null)
                    {
                        return(Ok("An exception of type " + ex2.GetType() + " was encountered while attempting to roll back the transaction!"));
                    }
                }
                return(Ok("No record was inserted due to this error: " + ex.Message));
            }
            finally
            {
                con.Close();
            }
        }