Ejemplo n.º 1
0
        public async Task <IActionResult> Index()
        {
            var user = await _userManager.GetUserAsync(User);

            PaymentViewModel model  = new PaymentViewModel();
            var         order       = _context.Orders.Where(x => x.Users == user && x.OrderStatus == OrderStatus.Pending_Payment).Include(x => x.BasketItems).OrderByDescending(x => x.Id).FirstOrDefault();
            PaymentType paymentType = PaymentType.Tokenization;

            order.TransactionDate = DateTime.Now;
            order.ReferenceNumber = Get8Digits();
            string requestId = Guid.NewGuid().ToString().Replace("-", "");

            order.TransactionUUID = requestId;
            var paymentsettings = _context.PaymentSettings.Where(x => x.PaymentType == paymentType).FirstOrDefault();

            model.PaymentSetting = paymentsettings;
            model.Order          = order;
            var basketItems = _context.BasketItems.Where(x => x.Order == order).Include(x => x.Offers).OrderByDescending(x => x.Id);

            model.BasketItems = basketItems;
            _context.SaveChanges();
            return(View(model));
        }
        public async Task <IActionResult> Register(string Username, string Email, string Password, string Token, string FirstName, string LastName)
        {
            var user = new Users {
                UserName = Username, Email = Email, CreationDate = DateTime.Now, FirstName = FirstName, LastName = LastName
            };
            var result = await _userManager.CreateAsync(user, Password);

            if (result.Succeeded)
            {
                user = await _userManager.GetUserAsync(User);

                var token = _context.UserPushToken.Where(x => x.Token == Token).FirstOrDefault();
                if (token != null)
                {
                    token.User = user;
                }
                _context.SaveChanges();
                string            Address      = !string.IsNullOrEmpty(user.Address) ? user.Address : "";
                string            Age          = !string.IsNullOrEmpty(user.Age) ? user.Age : "";
                string            City         = !string.IsNullOrEmpty(user.City) ? user.City : "";
                string            Country      = !string.IsNullOrEmpty(user.Country) ? user.Country : "";
                DateTime          CreationDate = user.CreationDate;
                Gender            VGender      = user.Gender;
                string            Id           = user.Id;
                string            Image        = user.Image;
                string            PhoneNumber  = !string.IsNullOrEmpty(user.PhoneNumber) ? user.PhoneNumber : "";
                UserType          UserType     = user.UserType;
                ApiUsersViewModel api          = new ApiUsersViewModel {
                    Address = Address, Age = Age, City = City, Country = Country, CreationDate = CreationDate, Email = Email, FirstName = FirstName, Gender = VGender, Id = Id, Image = Image, LastName = LastName, PhoneNumber = PhoneNumber, UserName = Username, UserType = user.UserType
                };
                return(Ok(api));
            }
            else
            {
                return(Ok(result));
            }
        }
        public async Task <IActionResult> CheckList(int?edit, string action, string todotitle, DateTime?tododate, string tododetail, int?todoId, int?status)
        {
            var userId = _userManager.GetUserId(User);

            DashBoardViewModel model = new DashBoardViewModel();

            if (edit != null)
            {
                var todo = _context.CheckLists.Where(x => x.Id == edit).SingleOrDefault();
                model.TaskTitle       = todo.Title;
                model.TaskDescription = todo.Description;
                model.TaskDate        = todo.Timing;
                model.TaskId          = todo.Id;
            }
            if (action == "edittask")
            {
                var todo = _context.CheckLists.Where(x => x.Id == todoId).SingleOrDefault();
                todo.Title       = todotitle;
                todo.Description = tododetail;
                todo.Timing      = tododate != null ? (DateTime)tododate : todo.Timing;
                _context.SaveChanges();
            }
            if (action == "add")
            {
                var user = await _userManager.GetUserAsync(User);

                _context.CheckLists.Add(new DAL.CheckList {
                    Description = tododetail, Timing = tododate != null ? (DateTime)tododate : DateTime.Now, Title = todotitle, User = user, Status = CheckListStatus.ToDo
                });
                _context.SaveChanges();
            }
            else if (action == "updatestatus")
            {
                var todo = _context.CheckLists.Where(x => x.Id == todoId).SingleOrDefault();
                if (todo == null)
                {
                    return(NotFound());
                }
                else
                {
                    todo.Status = status == 0 ? CheckListStatus.ToDo : CheckListStatus.Done;
                    _context.SaveChanges();
                }
            }
            else if (action == "delete")
            {
                var todo = _context.CheckLists.Where(x => x.Id == todoId).SingleOrDefault();
                if (todo == null)
                {
                    return(NotFound());
                }
                else
                {
                    _context.CheckLists.Remove(todo);
                    _context.SaveChanges();
                }
            }
            checklist       = _context.CheckLists.Where(x => x.User.Id == userId).OrderByDescending(x => x.Id);
            model.CheckList = checklist;
            return(View(model));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Receipt(string reason_code, string payment_token, string req_transaction_uuid)
        {
            var order = _context.Orders.Where(x => x.TransactionUUID == req_transaction_uuid).Include(x => x.Users).Include(x => x.BasketItems).OrderByDescending(x => x.Id).FirstOrDefault();

            ViewData["PaymentTitle"] = "Thank You";
            if (reason_code == "100")
            {
                PaymentType paymentType     = PaymentType.Tokenization;
                var         paymentsettings = _context.PaymentSettings.Where(x => x.PaymentType == paymentType).FirstOrDefault();
                if (!string.IsNullOrEmpty(payment_token))
                {
                    var dbtoken = _context.UserPaymentTokens.Where(x => x.Token == payment_token && x.TokenStatus == TokenStatus.Valid).FirstOrDefault();
                    if (dbtoken == null)
                    {
                        dbtoken = new UserPaymentToken {
                            Token = payment_token, TokenStatus = TokenStatus.Valid, PaymentSetting = paymentsettings, User = order.Users
                        };
                        _context.UserPaymentTokens.Add(dbtoken);
                    }
                    var oldtokens = _context.UserPaymentTokens.Where(x => x.Token != payment_token && x.User == order.Users && x.TokenStatus == TokenStatus.Valid).AsEnumerable();
                    foreach (var t in oldtokens)
                    {
                        t.TokenStatus = TokenStatus.InValid;
                    }
                }
                order.OrderStatus    = OrderStatus.Completed;
                ViewData["Response"] = "Your order was processed successfully, thank you.";
                SendEmail(order);
            }
            else if (reason_code == "481")
            {
                PaymentType paymentType     = PaymentType.Tokenization;
                var         paymentsettings = _context.PaymentSettings.Where(x => x.PaymentType == paymentType).FirstOrDefault();
                if (!string.IsNullOrEmpty(payment_token))
                {
                    var dbtoken = _context.UserPaymentTokens.Where(x => x.Token == payment_token && x.TokenStatus == TokenStatus.Valid).FirstOrDefault();
                    if (dbtoken == null)
                    {
                        dbtoken = new UserPaymentToken {
                            Token = payment_token, TokenStatus = TokenStatus.Valid, PaymentSetting = paymentsettings, User = order.Users
                        };
                        _context.UserPaymentTokens.Add(dbtoken);
                    }
                    var oldtokens = _context.UserPaymentTokens.Where(x => x.Token != payment_token && x.User == order.Users && x.TokenStatus == TokenStatus.Valid).AsEnumerable();
                    foreach (var t in oldtokens)
                    {
                        t.TokenStatus = TokenStatus.InValid;
                    }
                }
                order.OrderStatus    = OrderStatus.Completed;
                ViewData["Response"] = "Your order was processed successfully, thank you.";
                SendEmail(order);
            }
            else
            {
                ViewData["PaymentTitle"] = "Payment Error";
                string responseMsg = "";
                switch (reason_code)
                {
                case "102":
                    responseMsg = "An Error has occured please try again later.";
                    break;

                case "104":
                    responseMsg = "An Error has occured please try again later.";
                    break;

                case "110":
                    order.OrderStatus = OrderStatus.OnHold;
                    responseMsg       = "The transaction was approved, but an error has occured, however a representative will contact you the soonest possible. Thank you.";
                    break;

                case "200":
                    order.OrderStatus = OrderStatus.OnHold;
                    responseMsg       = "The transaction was approved, but an error has occured, however a representative will contact you the soonest possible. Thank you.";
                    break;

                case "201":
                    order.OrderStatus = OrderStatus.OnHold;
                    responseMsg       = "The transaction was approved, but an error has occured, however a representative will contact you the soonest possible. Thank you.";
                    break;

                case "202":
                    responseMsg = "Sorry, Your card was expired.";
                    break;

                case "203":
                    responseMsg = "Insufficient funds in the account.";
                    break;

                case "204":
                    responseMsg = "Stolen or lost card.";
                    break;

                case "205":
                    responseMsg = " Issuing bank unavailable.";
                    break;

                case "207":
                    responseMsg = "Inactive card or card not authorized for card-not-present transactions.";
                    break;

                case "208":
                    responseMsg = "Inactive card or card not authorized for card-not-present transactions.";
                    break;

                case "210":
                    responseMsg = "The card has reached the credit limit.";
                    break;

                case "211":
                    responseMsg = "Invalid CVN.";
                    break;

                case "221":
                    responseMsg = "An Error has occured please try again later.";
                    break;

                case "222":
                    responseMsg = " Account frozen.";
                    break;

                case "230":
                    order.OrderStatus = OrderStatus.OnHold;
                    responseMsg       = "The transaction was approved, but an error has occured, however a representative will contact you the soonest possible. Thank you.";
                    break;

                case "231":

                    responseMsg = "Invalid account number.";
                    break;

                case "232":
                    responseMsg = "The card type is not accepted by the payment processor.";
                    break;

                case "233":
                    order.OrderStatus = OrderStatus.OnHold;
                    responseMsg       = "The transaction was approved, but an error has occured, however a representative will contact you the soonest possible. Thank you.";
                    break;

                case "234":
                    responseMsg = "An Error has occured please try again later.";
                    break;

                case "236":
                    responseMsg = "An Error has occured please try again later";
                    break;

                case "240":
                    responseMsg = "The card type sent is invalid or does not correlate with the credit card number.";
                    break;

                case "475":
                    responseMsg = "An Error has occured please try again later.";
                    break;

                case "476":
                    responseMsg = "An Error has occured please try again later.";
                    break;

                case "520":
                    order.OrderStatus = OrderStatus.OnHold;
                    responseMsg       = "The transaction was approved, but an error has occured, however a representative will contact you the soonest possible. Thank you.";
                    break;

                default:
                    responseMsg = "An Error has occured please try again later.";
                    break;
                }
                ViewData["Response"] = responseMsg;
            }
            var basketitems = _context.BasketItems.Where(x => x.Order.Id == order.Id).Include(x => x.Offers).Include(x => x.Offers.User).ToList();

            _context.SaveChanges();
            return(View(basketitems));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Register(string Username, string Email, string Password, string Token, string FirstName, string LastName, string FBToken)
        {
            Users user = null;

            if (!string.IsNullOrEmpty(FBToken))
            {
                user = _context.Users.Where(x => x.FBToken == FBToken).FirstOrDefault();
                if (user == null)
                {
                    user = _context.Users.Where(x => x.Email == Email).FirstOrDefault();
                }
            }
            if (user == null)
            {
                user = new Users {
                    UserName = Username, Email = Email, CreationDate = DateTime.Now, FirstName = FirstName, LastName = LastName, UserType = UserType.Planner, FBToken = FBToken
                };
                var result = await _userManager.CreateAsync(user, Password);

                if (result.Succeeded)
                {
                    await _userManager.AddToRoleAsync(user, "Planner");


                    await _signInManager.SignInAsync(user, isPersistent : false);

                    var token = _context.UserPushToken.Where(x => x.Token == Token).FirstOrDefault();
                    if (token != null)
                    {
                        token.User = user;
                    }
                    _context.SaveChanges();
                    string   Address      = !string.IsNullOrEmpty(user.Address) ? user.Address : "";
                    string   Age          = !string.IsNullOrEmpty(user.Age) ? user.Age : "";
                    string   City         = !string.IsNullOrEmpty(user.City) ? user.City : "";
                    string   Country      = !string.IsNullOrEmpty(user.Country) ? user.Country : "";
                    DateTime CreationDate = user.CreationDate;
                    Gender   VGender      = user.Gender;
                    string   Id           = user.Id;
                    string   Image        = user.Image;
                    string   PhoneNumber  = !string.IsNullOrEmpty(user.PhoneNumber) ? user.PhoneNumber : "";
                    UserType UserType     = user.UserType;
                    var      events       = _context.Events.Where(x => x.UserId == user.Id).FirstOrDefault();
                    if (events != null)
                    {
                        if (!string.IsNullOrEmpty(events.Image))
                        {
                            events.Image = "http://" + Request.Host + "/Media/" + events.Image;
                        }
                    }
                    else
                    {
                        events = new Events {
                        }
                    };
                    ApiUsersViewModel api = new ApiUsersViewModel {
                        Address = Address, Age = Age, City = City, Country = Country, CreationDate = CreationDate, Email = Email, FirstName = FirstName, Gender = VGender, Id = Id, Image = Image, LastName = LastName, PhoneNumber = PhoneNumber, UserName = Username, UserType = user.UserType, Events = events
                    };
                    return(Ok(api));
                }
                else
                {
                    return(Ok(result));
                }
            }
            else
            {
                await _signInManager.SignInAsync(user, isPersistent : false);

                var token = _context.UserPushToken.Where(x => x.Token == Token).FirstOrDefault();
                if (token != null)
                {
                    token.User = user;
                }
                _context.SaveChanges();
                string   Address      = !string.IsNullOrEmpty(user.Address) ? user.Address : "";
                string   Age          = !string.IsNullOrEmpty(user.Age) ? user.Age : "";
                string   City         = !string.IsNullOrEmpty(user.City) ? user.City : "";
                string   Country      = !string.IsNullOrEmpty(user.Country) ? user.Country : "";
                DateTime CreationDate = user.CreationDate;
                Gender   VGender      = user.Gender;
                string   Id           = user.Id;
                string   Image        = user.Image;
                string   PhoneNumber  = !string.IsNullOrEmpty(user.PhoneNumber) ? user.PhoneNumber : "";
                UserType UserType     = user.UserType;
                var      events       = _context.Events.Where(x => x.UserId == user.Id).FirstOrDefault();
                if (events != null)
                {
                    if (!string.IsNullOrEmpty(events.Image))
                    {
                        events.Image = "http://" + Request.Host + "/Media/" + events.Image;
                    }
                }
                else
                {
                    events = new Events {
                    }
                };
                ApiUsersViewModel api = new ApiUsersViewModel {
                    Address = Address, Age = Age, City = City, Country = Country, CreationDate = CreationDate, Email = Email, FirstName = FirstName, Gender = VGender, Id = Id, Image = Image, LastName = LastName, PhoneNumber = PhoneNumber, UserName = Username, UserType = user.UserType, Events = events
                };
                return(Ok(api));
            }
        }