예제 #1
0
        public ActionResult StatusCentili(Guid clientid, string status)
        {
            log.Info("Token/StatusCentili has been fired.");
            Guid id = clientid;

            using (var context = new AuctionsDB())
            {
                using (var trans = context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        tokenOrder to = context.tokenOrder.Find(id);
                        if (to != null)
                        {
                            //menjamo status u ono sto je prosledjeno
                            User user = context.User.Find(to.idUser);
                            if (user != null)
                            {
                                if (to.status != "SUBMITTED           ")
                                {
                                    return(RedirectToAction("ListOrders", "Token"));
                                }
                                if (status.Equals("success"))
                                {
                                    user.NumberOfTokens += (int)to.numTokens;
                                    to.status            = "COMPLETED";
                                }
                                else
                                {
                                    to.status = "CANCELED";
                                }
                                context.Entry(user).State = System.Data.Entity.EntityState.Modified;
                                context.Entry(to).State   = System.Data.Entity.EntityState.Modified;
                                sendMail(user.Email, "Centili payment", "Your payment was successful.");
                                context.SaveChanges();
                                trans.Commit();
                            }
                            else
                            {
                                throw new Exception();
                            }
                        }
                        else
                        {
                            throw new Exception();
                        }
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        log.Error("Centili payment exception caught");
                    }
                }
            }
            return(RedirectToAction("ListOrders", "Token"));
        }
예제 #2
0
        //get za confirmation
        public string Get(string clientid, string status)
        {
            log.Info("Api/Status has been fired");

            using (var context = new AuctionsDB())
            {
                using (var trans = context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        tokenOrder to = context.tokenOrder.Find(Guid.Parse(clientid));
                        if (to == null)
                        {
                            log.Error("API with wrong token id called");
                            throw new Exception();
                        }

                        User user = context.User.Find(to.idUser);
                        if (user != null)
                        {
                            if (to.status != "SUBMITTED           ")
                            {
                                log.Error("API already called");
                                throw new Exception();
                            }
                            if (status.Equals("success"))
                            {
                                user.NumberOfTokens += (int)to.numTokens;
                                to.status            = "COMPLETED";
                            }
                            else
                            {
                                to.status = "CANCELED";
                            }
                            TokenController.sendMail(user.Email, "Centili payment", "Your payment was successful.");
                            context.Entry(user).State = System.Data.Entity.EntityState.Modified;
                            context.Entry(to).State   = System.Data.Entity.EntityState.Modified;
                            context.SaveChanges();
                            trans.Commit();
                        }
                        else
                        {
                            log.Error("API user not found.");
                            throw new Exception();
                        }
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        return("failed!");
                    }
                }
            }
            return("success!");
        }
예제 #3
0
        public ActionResult ConfirmBuy(string package)
        {
            log.Info("Token/ConfirmBuy has been fired.");
            int    numT = 0;
            string link = "";

            if (package.Equals("1"))
            {
                link = "&package=1";
                numT = AdminParams.S;
            }
            else if (package.Equals("2"))
            {
                link = "&package=2";
                numT = AdminParams.G;
            }
            else
            {
                link = "&package=3";
                numT = AdminParams.P;
            }
            ViewBag.link    = link;
            ViewBag.package = package;
            E_Commerce.Models.User user = null;
            using (var con = new E_Commerce.Models.AuctionsDB())
            {
                using (var trans = con.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        user = con.User.Find(User.Identity.GetUserId());
                        if (user != null)
                        {
                            //make token order
                            var to = new tokenOrder()
                            {
                                id        = Guid.NewGuid(),
                                numTokens = numT,
                                idUser    = User.Identity.GetUserId(),
                                status    = "SUBMITTED",
                                price     = AdminParams.T * numT
                            };
                            con.tokenOrder.Add(to);
                            con.SaveChanges();
                            trans.Commit();
                            return(View(to));
                        }
                        else
                        {
                            throw new Exception();
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error("Error with submitting token order");
                        trans.Rollback();
                    }
                }
            }

            return(RedirectToAction("ListOrders", "Token"));
        }