Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "sub_code,name,abbrevation,seq_cd,sub_type,id")] Subject subject)
        {
            if (ModelState.IsValid)
            {
                subject.sub_type = subject.sub_type.ToUpper();
                db.Subjects.Add(subject);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(subject));
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Post(RequestModel req)
        {
            if (!ModelState.IsValid)
            {
                response = Request.CreateResponse(HttpStatusCode.BadRequest, "Bad Request: Improper Data Passed");
            }
            else
            {
                hslc exam_result = db.hslcs.Where(x => x.roll == req.roll && x.exm_year.ToString() == req.exam_year && x.dob == req.dob).FirstOrDefault();
                if (exam_result != null)
                {
                    //int exam_res_id = db.Database.SqlQuery<int>("select id from students where roll_no='" + req.roll_no + "' and year='" + req.year + "' and dob='" + req.dob + "'").FirstOrDefault();
                    if (db.requested_mark.Any(m => m.exam_result_id == exam_result.id && m.user_id == req.user_id))
                    {
                        response = Request.CreateResponse(HttpStatusCode.Conflict, "Duplicate request found! You have already requested the same. Please check in the request history.");
                    }
                    else
                    {
                        requested_mark requested_mark = new requested_mark();

                        requested_mark.request_date   = DateTime.Now;
                        requested_mark.payment_status = "unpaid";
                        requested_mark.exam_result_id = exam_result.id;
                        requested_mark.user_id        = req.user_id;
                        requested_mark.id             = generateRandomString(26);
                        requested_mark.txn_id         = null;

                        db.requested_mark.Add(requested_mark);
                        db.SaveChanges();
                        response = Request.CreateResponse(HttpStatusCode.OK,
                                                          new
                        {
                            message  = "Marksheet has been requested, please click proceed button for payment.",
                            req_list = db.RequestHistories.Where(x => x.user_id == req.user_id && x.payment_status == "unpaid").ToList()
                        });
                    }
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.NotFound, "No record found for the input specification.");
                }
            }
            return(response);
        }
Ejemplo n.º 3
0
        public ActionResult RecordPaymentRate(RateModel rate)
        {
            rate.id         = generateRandomString(26);
            rate.created_at = DateTime.Now;
            PaymentRates paymentRate = rate.ToPaymentRateModel();

            context.PaymentRates.Add(paymentRate);
            context.SaveChanges();
            List <PaymentRates> rate_list = context.PaymentRates.OrderByDescending(m => m.created_at).ToList();

            return(Json(new { msg = "You have successfully set new amount.", list = rate_list }));
        }
Ejemplo n.º 4
0
        public HttpResponseMessage PostSubjectYearCombinations(SubjectYearCombinations subjectYearCombinations)
        {
            if (!ModelState.IsValid)
            {
                response = Request.CreateResponse(HttpStatusCode.BadRequest, "Bad Request: Improper Data Passed");
            }
            else
            {
                if (db.SubjectYearCombinations.Any(m => m.sub_id == subjectYearCombinations.sub_id && m.year == subjectYearCombinations.year))
                {
                    response = Request.CreateResponse(HttpStatusCode.OK,
                                                      new
                    {
                        message  = "You have already added.",
                        list     = SubjectYearCombinationViewModel.ConvertToSubjectYearCombinationViewModel(db.SubjectYearCombinations.Where(m => m.year == subjectYearCombinations.year).ToList()),
                        subjects = SubjectViewModel.GetModelList(db.Subjects.OrderBy(m => m.name).ToList())
                    });
                }
                else
                {
                    db.SubjectYearCombinations.Add(subjectYearCombinations);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (DbUpdateException exception)
                    {
                        if (SubjectYearCombinationsExists(subjectYearCombinations.id))
                        {
                            response = Request.CreateResponse(HttpStatusCode.Conflict,
                                                              new
                            {
                                message  = "Conflict occurs.",
                                list     = SubjectYearCombinationViewModel.ConvertToSubjectYearCombinationViewModel(db.SubjectYearCombinations.Where(m => m.year == subjectYearCombinations.year).ToList()),
                                subjects = SubjectViewModel.GetModelList(db.Subjects.OrderBy(m => m.name).ToList())
                            });
                        }
                        else
                        {
                            response = Request.CreateResponse(HttpStatusCode.InternalServerError, new
                            {
                                message = "Failed to update." + exception.GetBaseException()
                            });
                        }
                    }
                    response = Request.CreateResponse(HttpStatusCode.OK,
                                                      new
                    {
                        message  = "You have successfully added.",
                        list     = SubjectYearCombinationViewModel.ConvertToSubjectYearCombinationViewModel(db.SubjectYearCombinations.Where(m => m.year == subjectYearCombinations.year).ToList()),
                        subjects = SubjectViewModel.GetModelList(db.Subjects.OrderBy(m => m.name).ToList())
                    });
                }
            }

            return(response);
        }
Ejemplo n.º 5
0
        public ActionResult RedirectFromPaypal()
        {
            if (Request.IsAuthenticated)
            {
                string user_id = User.Identity.GetUserId();
                if (isValidRedirection())
                {
                    try
                    {
                        TransactionHistory txn_hist = new TransactionHistory();

                        // Transaction verification form
                        var formVals = new Dictionary <string, string>();
                        formVals.Add("cmd", "_notify-synch");                                                    //notify-synch_notify-validate
                        formVals.Add("at", Convert.ToString(ConfigurationManager.AppSettings["IdentityToken"])); // this has to be adjusted
                        formVals.Add("tx", Request["tx"]);

                        bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["IsSandbox"]);

                        /*
                         * GetPayPalResponse will verify whether the transaction details extracted from
                         * the return url are correct or not.
                         */
                        string response = GetPayPalResponse(formVals, useSandbox);

                        if (response.Contains("SUCCESS"))
                        {
                            txn_hist.txn_id    = Request.QueryString["tx"];
                            txn_hist.amount    = decimal.Parse(GetPDTValue(response, "mc_gross"));
                            txn_hist.status    = GetPDTValue(response, "payment_status").Equals("Completed")?"Success":"Fail";
                            txn_hist.create_at = DateTime.Now;

                            //txn_hist.amount = decimal.Parse(Request.QueryString["amt"]);
                            //txn_hist.status = Request.QueryString["st"];
                            //DateTime paymentDate;
                            //DateTime.TryParseExact(HttpUtility.UrlDecode(GetPDTValue(response, "payment_date")), "HH:mm:ss MMM dd, yyyy PST", CultureInfo.InvariantCulture, DateTimeStyles.None, out paymentDate);
                            //txn_hist.create_at = paymentDate;


                            if (db.TransactionHistories.Any(m => m.txn_id == txn_hist.txn_id))
                            {
                                ViewBag.error         = 1;
                                ViewBag.PaymentResult = "Transaction already exist.";
                            }
                            else
                            {
                                /****Adding transaction record*******/
                                db.TransactionHistories.Add(txn_hist);
                                db.SaveChanges();

                                /***** Verifying whether the user has paid the right amount *****/
                                int     no_of_item   = db.requested_mark.Where(x => x.user_id == user_id && x.payment_status == "unpaid").Count();
                                decimal amt_per_item = RateModel.getCurrentRate(); //Convert.ToInt32(ConfigurationManager.AppSettings["amt_per_unit"]);//amount payable in each request for verification
                                decimal total        = no_of_item * amt_per_item;  //actual amount payable by the payer

                                /*If the user has not paid the right enough amount i.e. if the amount paid by the user is less than the actual amount payable,
                                 * then the status will be set to 'error', and hence he/she will not be allowed to download the marksheet. */
                                string payment_status = (txn_hist.status.Equals("Success")) ?(txn_hist.amount < total ?"error": "paid"): "unpaid";

                                /***** updating payment status in requested_mark table *******/
                                db.Database.ExecuteSqlCommand("update requested_mark set txn_id='" + txn_hist.txn_id + "', payment_status='" + payment_status + "' where payment_status='unpaid' and user_id='" + user_id + "'");
                                ViewBag.PaymentResult = "";
                                ViewBag.error         = 0;
                                ViewBag.Transaction   = txn_hist;

                                List <RequestHistories> txn_list = db.RequestHistories.Where(m => m.txn_id == txn_hist.txn_id && m.payment_status == "paid").ToList();
                                List <RequestHistModel> req_list = new List <RequestHistModel>();
                                foreach (RequestHistories row in txn_list)
                                {
                                    req_list.Add(new RequestHistModel(row));
                                }
                                if (txn_hist.amount < total)
                                {
                                    ViewBag.error   = 1;// error exists
                                    ViewBag.warning = "Since, you have paid an amount of Rs " + txn_hist.amount + " which is less than the actual payable amount of Rs " + total +
                                                      ", you won't be allowed to download marksheet. Please consult with administrator to cancel the order and start from the beginning.";
                                }
                                else
                                {
                                    ViewBag.error   = 0;  //no error
                                    ViewBag.warning = ""; //no warning
                                }
                                ViewBag.Title = "Payment Completed.";
                                return(View(req_list));
                            }
                        }
                        else if (response.Contains("FAIL"))
                        {
                            ViewBag.error         = 1;
                            ViewBag.PaymentResult = "Wrong transaction record....";
                        }
                        else
                        {
                            ViewBag.error         = 1;
                            ViewBag.PaymentResult = "Something went wrong...: " + response;
                        }
                        //just for printing whatever in the response
                        //ViewBag.PaymentResult = response;
                    }
                    catch (Exception ex)
                    {
                        ViewBag.error         = 1;
                        ViewBag.PaymentResult = "An error occurs: " + ex.ToString();
                    }
                }
                else
                {
                    ViewBag.error         = 1;
                    ViewBag.Title         = "Invalid Redirection";
                    ViewBag.PaymentResult = "Invalid redirection.";
                }
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
            return(View());
        }