Beispiel #1
0
        public IActionResult CreateOrder(LinkOrder linkOrder)
        {
            if (ModelState.IsValid)
            {
                if (signInManager.IsSignedIn(User) == true)
                {
                    SignedUserName = User.Identity.Name;
                    user           = dbContext.CustomUsers.FirstOrDefault(x => x.UserName == SignedUserName);

                    //===================== GETS THE BALANCE OF SIGNED USER
                    var userBalance = dbContext.Balances.FirstOrDefault(x => x.DbPassportUserModelId == user.Id);
                    userBalance.TLBalance -= linkOrder.ProductPrice;
                    dbContext.SaveChanges();

                    //==================== ADDS TRANSACTION WHEN MONEY IS SPENT
                    UserTransaction userTransaction = new UserTransaction()
                    {
                        TransactionType     = 2, //================ 1 for medaxil, 2 for mexaric
                        Amount              = linkOrder.ProductPrice,
                        CurrencyType        = 2, //=================== 1 for azn, 2 for try,
                        Date                = DateTime.Now,
                        DbPassportUserModel = user
                    };
                    dbContext.Transactions.Add(userTransaction);
                    dbContext.SaveChanges();

                    LinkOrder dbLinkOrder = new LinkOrder()
                    {
                        OrderLink           = linkOrder.OrderLink,
                        ProductPrice        = linkOrder.ProductPrice,
                        ProductAmount       = linkOrder.ProductAmount,
                        OrderComment        = linkOrder.OrderComment,
                        DeliveryAddress     = linkOrder.DeliveryAddress,
                        PaymentMethod       = linkOrder.PaymentMethod,
                        DbPassportUserModel = user,
                        OrderDate           = DateTime.Now,
                        OrderStatus         = 10
                    };


                    if (dbContext.Orders.Count() > 0)
                    {
                        dbLinkOrder.OrderNumber = dbContext.Orders.Max(x => x.OrderNumber) + 1;
                    }
                    else
                    {
                        dbLinkOrder.OrderNumber = 1;
                    }


                    dbContext.Orders.Add(dbLinkOrder);
                    dbContext.SaveChanges();

                    return(Json(new { redirectUrl = Url.Action("Index", "PanelPage") }));
                }
            }

            return(RedirectToAction("Index", "MakeOrder"));
        }
Beispiel #2
0
        public IActionResult Index()
        {
            if (signInManager.IsSignedIn(User) == true)
            {
                SignedUserName = User.Identity.Name;
                user           = dbContext.CustomUsers.FirstOrDefault(x => x.UserName == SignedUserName);
            }

            var userBalance = dbContext.Balances.FirstOrDefault(x => x.DbPassportUserModelId == user.Id);

            return(View(userBalance));
        }
Beispiel #3
0
        //=============================================================== DOWNLOAD EXCELL(.xlsx) FILE TL
        public IActionResult DownloadExcellTL()
        {
            if (signInManager.IsSignedIn(User) == true)
            {
                SignedUserName = User.Identity.Name;
                user           = dbContext.CustomUsers.FirstOrDefault(x => x.UserName == SignedUserName);
            }

            var Transactions = dbContext.Transactions.Where(x => x.DbPassportUserModelId == user.Id && x.CurrencyType == 2);

            using (var workbook = new XLWorkbook())
            {
                var worksheet  = workbook.Worksheets.Add("Transactions");
                var currentRow = 1;
                worksheet.Cell(currentRow, 1).Value = "Əməliyyat";
                worksheet.Cell(currentRow, 2).Value = "Məbləğ";
                worksheet.Cell(currentRow, 3).Value = "Tarix";


                foreach (var transaction in Transactions)
                {
                    worksheet.Columns().AdjustToContents();//============= this line makes cell width larger rspect to its content
                    currentRow++;
                    if (transaction.TransactionType == 1)
                    {
                        worksheet.Cell(currentRow, 1).Value = "Mədaxil";
                    }
                    else if (transaction.TransactionType == 2)
                    {
                        worksheet.Cell(currentRow, 1).Value = "Məxaric";
                    }
                    worksheet.Cell(currentRow, 2).Value = transaction.Amount;
                    worksheet.Cell(currentRow, 3).Value = transaction.Date.ToString("dd/MM/yyyy HH:mm:ss");
                }

                using (var stream = new MemoryStream())
                {
                    workbook.SaveAs(stream);
                    var content = stream.ToArray();

                    return(File(
                               content,
                               "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                               "ƏməliyyatlarTL.xlsx"
                               ));
                }
            }
        }
Beispiel #4
0
        public IActionResult IncreaseBalance(AccountBalanceViewModel accountBalanceViewModel)
        {
            if (signInManager.IsSignedIn(User) == true)
            {
                SignedUserName = User.Identity.Name;
                user           = dbContext.CustomUsers.FirstOrDefault(x => x.UserName == SignedUserName);
            }

            var balance = dbContext.Balances.FirstOrDefault(x => x.DbPassportUserModelId == user.Id);

            balance.LastIncreasedAZNBalanceDate = DateTime.Now;
            balance.AZNBalance += accountBalanceViewModel.AZNBalance;
            dbContext.SaveChanges();


            UserTransaction userTransaction = new UserTransaction()
            {
                TransactionType     = 1, //================ 1 for medaxil, 2 for mexaric
                Amount              = accountBalanceViewModel.AZNBalance,
                CurrencyType        = 1, //=================== 1 for azn, 2 for try,
                Date                = DateTime.Now,
                DbPassportUserModel = user
            };

            dbContext.Transactions.Add(userTransaction);
            dbContext.SaveChanges();

            AccountBalanceViewModel sendData = new AccountBalanceViewModel()
            {
                AZNBalance = balance.AZNBalance,
                LastIncreasedAZNBalanceDate = balance.LastIncreasedAZNBalanceDate
            };

            var serializedBalance = JsonConvert.SerializeObject(sendData);

            return(Content(serializedBalance));
        }
Beispiel #5
0
        public IActionResult Index()
        {
            IndexDataViewModels indexDataViewModels = new IndexDataViewModels();

            //await createRolesandUsers();

            if (signInManager.IsSignedIn(User) == true)
            {
                SignedUserName = User.Identity.Name;
                user           = dbContext.CustomUsers.FirstOrDefault(x => x.UserName == SignedUserName);
            }

            ViewBag.Name          = user.Name;
            ViewBag.Surname       = user.Surname;
            ViewBag.BirthdayYear  = user.BirthdayDate.Year;
            ViewBag.BirthdayMonth = user.BirthdayDate.Month;
            ViewBag.BirthdayDay   = user.BirthdayDate.Day;
            ViewBag.Email         = user.Email;
            ViewBag.Phone         = user.PhoneNumber;
            ViewBag.Sex           = user.Sex;
            ViewBag.Seria         = user.SeriaNumber;
            ViewBag.Fin           = user.FinCode;
            ViewBag.Citizenship   = user.Citizenship;
            ViewBag.Address       = user.Address;
            ViewBag.CustomerCode  = user.CustomerNumber;
            var addressTurkey = dbContext.Addressesabroads.FirstOrDefault(x => x.CountryId == 1);

            if (addressTurkey != null)
            {
                ViewBag.TrCity         = addressTurkey.City;
                ViewBag.TrIlce         = addressTurkey.District;
                ViewBag.TrSemt         = addressTurkey.DistrictTwo;
                ViewBag.TrZip          = addressTurkey.ZIP;
                ViewBag.TrUlke         = "Turkey";
                ViewBag.TrKimlik       = addressTurkey.identityNumber;
                ViewBag.TrCep          = addressTurkey.PhoneNumber;
                ViewBag.TrVergiNumara  = addressTurkey.TaxNumber;
                ViewBag.TrVergiAddress = addressTurkey.TaxAdministration;
            }
            else
            {
                ViewBag.TrCity         = " ";
                ViewBag.TrIlce         = " ";
                ViewBag.TrSemt         = " ";
                ViewBag.TrZip          = " ";
                ViewBag.TrUlke         = " ";
                ViewBag.TrKimlik       = " ";
                ViewBag.TrCep          = " ";
                ViewBag.TrVergiNumara  = " ";
                ViewBag.TrVergiAddress = " ";
            }
            var addressUsa = dbContext.Addressesabroads.FirstOrDefault(x => x.CountryId == 2);

            if (addressUsa != null)
            {
                ViewBag.TrCity         = addressUsa.City;
                ViewBag.TrIlce         = addressUsa.District;
                ViewBag.TrSemt         = addressUsa.DistrictTwo;
                ViewBag.TrZip          = addressUsa.ZIP;
                ViewBag.TrUlke         = "Usa";
                ViewBag.TrKimlik       = addressUsa.identityNumber;
                ViewBag.TrCep          = addressUsa.PhoneNumber;
                ViewBag.TrVergiNumara  = addressUsa.TaxNumber;
                ViewBag.TrVergiAddress = addressUsa.TaxAdministration;
            }



            Rootobject jsonToObject = GetCurrency();

            indexDataViewModels.rootobject = jsonToObject;

            var userInvoices = dbContext.Invoices.Where(x => x.DbPassportUserModelId == user.Id).ToList();

            userInvoices = userInvoices.OrderByDescending(x => x.InvoiceDate).ToList();
            indexDataViewModels.Invoices = userInvoices;

            var Balance = dbContext.Balances.FirstOrDefault(x => x.DbPassportUserModelId == user.Id);

            indexDataViewModels.accountBalanceViewModel = Balance;

            var userTransactions = dbContext.Transactions.Where(x => x.DbPassportUserModelId == user.Id).ToList();

            indexDataViewModels.Transactions = userTransactions;

            var userOrders = dbContext.Orders.Where(x => x.DbPassportUserModelId == user.Id).ToList();

            userOrders = userOrders.OrderByDescending(x => x.OrderDate).ToList();
            indexDataViewModels.Orders = userOrders;

            indexDataViewModels.courierDbViewModels = dbContext.CourierDeliveries.Include(x => x.CourierDbViewModelInvoices).ThenInclude(x => x.Invoice).Where(x => x.DbPassportUserModelId == user.Id).ToList();
            indexDataViewModels.addressesabroad     = dbContext.Addressesabroads.Include(x => x.Country).ToList();
            return(View(indexDataViewModels));
        }
Beispiel #6
0
        //=============================================================== ADDS PACKAGES(DELIVERED INVOICES) TO COURIER DELIVERIES LIST (FROM AJAX REQUEST)
        public IActionResult AddCourierDeliveries(CreateCourierViewModel createCourierViewModel)
        {
            if (ModelState.IsValid)
            {
                if (createCourierViewModel.IdOfInvoice == 0)
                {
                    ModelState.AddModelError("IdOfInvoice", "Bağlama mütləq seçilməlidir");
                }
                else
                {
                    if (signInManager.IsSignedIn(User) == true)
                    {
                        SignedUserName = User.Identity.Name;
                        user           = dbContext.CustomUsers.FirstOrDefault(x => x.UserName == SignedUserName);
                    }

                    var invoice = dbContext.Invoices.FirstOrDefault(x => x.id == createCourierViewModel.IdOfInvoice);

                    CourierDbViewModel courierDbViewModel = new CourierDbViewModel()
                    {
                        AddressOfDelivery   = createCourierViewModel.AddressOfDelivery,
                        District            = createCourierViewModel.District,
                        Village             = createCourierViewModel.Village,
                        Street              = createCourierViewModel.Street,
                        House               = createCourierViewModel.House,
                        PhoneNumber         = createCourierViewModel.PhoneNumber,
                        InvoiceComments     = createCourierViewModel.InvoiceComments,
                        DeliveredStatus     = 1,
                        DbPassportUserModel = user
                    };

                    CourierDbViewModelInvoice courierDbViewModelInvoice = new CourierDbViewModelInvoice()
                    {
                        Invoice            = invoice,
                        CourierDbViewModel = courierDbViewModel
                    };


                    courierDbViewModel.CourierDbViewModelInvoices.Add(courierDbViewModelInvoice);

                    dbContext.CourierDeliveries.Add(courierDbViewModel);

                    dbContext.SaveChanges();


                    //==================== RETURN DATA TO AJAX REQUEST
                    var newlyAddedCourier = dbContext.CourierDeliveries.Where(x => x.DbPassportUserModelId == user.Id).ToList().Last();

                    AjaxCourierViewModel ajaxCourierViewModel = new AjaxCourierViewModel()
                    {
                        id                = newlyAddedCourier.id,
                        District          = newlyAddedCourier.District,
                        Village           = newlyAddedCourier.Village,
                        Street            = newlyAddedCourier.Street,
                        House             = newlyAddedCourier.House,
                        InvoiceComments   = newlyAddedCourier.InvoiceComments,
                        PhoneNumber       = newlyAddedCourier.PhoneNumber,
                        AddressOfDelivery = newlyAddedCourier.AddressOfDelivery
                    };

                    var jsonObject = JsonConvert.SerializeObject(ajaxCourierViewModel);

                    return(Content(jsonObject));
                }
            }

            return(null);
        }
        public async Task <IActionResult> CreateUserSecond(PassportUserModel passportUser)
        {
            if (passportUser.agreeBox == false)
            {
                ModelState.AddModelError("agreeBox", "Zəhmət olmasa istifadəçi qaydaları ilə razı olun");
                return(View(passportUser));
            }
            if (ModelState.IsValid)
            {
                DateTime lastDateTime = new DateTime(passportUser.Year, passportUser.Month, passportUser.Day);
                var      howManyUsers = dbContext.Users.ToList();
                int      customerid;
                if (howManyUsers.Count == 0)
                {
                    customerid = 10000000;
                }
                else
                {
                    customerid = dbContext.CustomUsers.Max(x => x.CustomerNumber) + 1;
                }
                DbPassportUserModel finalUser = new DbPassportUserModel()
                {
                    UserName       = passportUser.Email,
                    Email          = passportUser.Email,
                    Name           = passportUser.Name,
                    Surname        = passportUser.Surname,
                    FinCode        = passportUser.FinCode,
                    SeriaNumber    = passportUser.SeriaNumber,
                    Sex            = passportUser.Sex,
                    Address        = passportUser.Address,
                    PhoneNumber    = passportUser.MobilePhone,
                    BirthdayDate   = lastDateTime,
                    CustomerNumber = customerid,
                    Citizenship    = passportUser.Citizenship
                };
                var existedEmail       = user.Users.FirstOrDefault(x => x.Email == finalUser.Email);
                var existedPhone       = user.Users.FirstOrDefault(x => x.PhoneNumber == finalUser.PhoneNumber);
                var existedSeriaNumber = user.Users.FirstOrDefault(x => x.SeriaNumber == finalUser.SeriaNumber);
                var existedFinNumber   = user.Users.FirstOrDefault(x => x.FinCode == finalUser.FinCode);
                if (existedEmail != null || existedPhone != null || existedSeriaNumber != null || existedFinNumber != null)
                {
                    if (existedEmail != null)
                    {
                        ModelState.AddModelError("Email", "Belə mail istifadə olunub");
                    }
                    if (existedPhone != null)
                    {
                        ModelState.AddModelError("MobilePhone", "Belə telefon nomrəsi istifadə olunub");
                    }
                    if (existedSeriaNumber != null)
                    {
                        ModelState.AddModelError("SeriaNumber", "Belə seriya nömrəsi nomrəsi istifadə olunub");
                    }
                    if (existedFinNumber != null)
                    {
                        ModelState.AddModelError("FinCode", "Belə Fin  nömrəsi nomrəsi istifadə olunub");
                    }
                }
                else
                {
                    var result = user.CreateAsync(finalUser, passportUser.Password).Result;
                    if (result.Succeeded)
                    {
                        await signIn.SignInAsync(finalUser, false);

                        var thResult = user.AddToRoleAsync(finalUser, "User").Result;
                        if (thResult.Succeeded)
                        {
                        }


                        var signedBalanceUser = dbContext.CustomUsers.FirstOrDefault(x => x.UserName == finalUser.UserName);

                        AccountBalanceViewModel accountBalanceViewModel = new AccountBalanceViewModel()
                        {
                            AZNBalance = 0.00M,
                            TLBalance  = 0.00M,
                            LastIncreasedAZNBalanceDate = DateTime.Now,
                            DbPassportUserModel         = signedBalanceUser
                        };
                        dbContext.Balances.Add(accountBalanceViewModel);

                        dbContext.SaveChanges();



                        var code = await user.GenerateEmailConfirmationTokenAsync(finalUser);

                        var link    = this.Url.ActionLink("EmailVerified", "Register", new { userId = finalUser.Id, code = code });
                        var message = new MimeMessage();
                        message.From.Add(new MailboxAddress("Limak", "*****@*****.**"));
                        message.To.Add(new MailboxAddress("Code academy", finalUser.Email));
                        message.Subject = "Test";
                        string customText  = $"<a href={link}> Click Me<a/>";
                        var    bodyBuilder = new BodyBuilder();
                        bodyBuilder.HtmlBody = $"<a href={link}> Click Me<a/>";

                        message.Body = bodyBuilder.ToMessageBody();


                        using (var client = new SmtpClient())
                        {
                            client.CheckCertificateRevocation = false;
                            client.Connect("smtp.gmail.com", 587, false);
                            client.Authenticate("*****@*****.**", "miko1999");
                            client.Send(message);
                        }
                        return(RedirectToAction("PleaseVerify"));
                    }
                    else
                    {
                        ModelState.AddModelError("Password", "Parolda 1 boyuk herf 1 reqem ve 1 simvol olmalidir");
                    }
                }
            }
            return(View(passportUser));
        }
Beispiel #8
0
        public async Task <IActionResult> CreateInvoice(CreateInvoiceViewModel createInvoiceViewModel)
        {
            if (ModelState.IsValid)
            {
                if (signInManager.IsSignedIn(User) == true)
                {
                    SignedUserName = User.Identity.Name;
                    user           = dbContext.CustomUsers.FirstOrDefault(x => x.UserName == SignedUserName);
                }

                Invoice invoice = new Invoice()
                {
                    StoreName            = createInvoiceViewModel.StoreName,
                    InvoiceProductType   = createInvoiceViewModel.InvoiceProductType,
                    InvoiceProductAmount = createInvoiceViewModel.InvoiceProductAmount,
                    InvoiceProductPrice  = createInvoiceViewModel.InvoiceProductPrice,
                    InvoiceFollowCode    = createInvoiceViewModel.InvoiceFollowCode,
                    DeliveryOffice       = createInvoiceViewModel.DeliveryOffice,
                    InvoiceDate          = createInvoiceViewModel.InvoiceDate,
                    InvoiceComments      = createInvoiceViewModel.InvoiceComments,
                    InvoiceProductWeight = null,
                    DeliveryMoney        = null,
                    InvoiceTime          = DateTime.Now.ToString("HH:mm"),
                    InvoiceStatus        = 1,
                    InvoiceCountryIndex  = createInvoiceViewModel.InvoiceCountryIndex,
                    DbPassportUserModel  = user
                };

                if (invoice.InvoiceDate == null)
                {
                    invoice.InvoiceDate = DateTime.Now;
                }

                if (dbContext.Invoices.Count() > 0)
                {
                    invoice.InvoiceNumber = dbContext.Invoices.Max(x => x.InvoiceNumber) + 1;
                }
                else
                {
                    invoice.InvoiceNumber = 1;
                }

                //======================================== If there is any image submitted then this image is added to folder
                if (createInvoiceViewModel.FormFile != null)
                {
                    var nameOfImage      = Path.GetFileNameWithoutExtension(createInvoiceViewModel.FormFile.FileName);
                    var extensionOfImage = Path.GetExtension(createInvoiceViewModel.FormFile.FileName);
                    var guid             = Guid.NewGuid();

                    var newFileName = nameOfImage + guid + extensionOfImage;


                    var rootPath = Path.Combine(_webHost.WebRootPath, "Invoice", "InvoiceGallery", newFileName);

                    using (var fileStream = new FileStream(rootPath, FileMode.Create))
                    {
                        createInvoiceViewModel.FormFile.CopyTo(fileStream);
                    }

                    invoice.FileName = newFileName;
                }


                dbContext.Invoices.Add(invoice);
                dbContext.SaveChanges();

                return(RedirectToAction("Index", "PanelPage"));
            }

            return(View());
        }