Пример #1
0
        public FileContentResult Download(string id)
        {
            AspNetVendor aspNetVendor = _context.AspNetVendor.SingleOrDefault(a => a.UserId == id);
            var          filename     = aspNetVendor.FileLocation;
            string       tempFilePath = System.IO.Path.Combine(_hostingEnvironment.WebRootPath, "VendorData", filename);

            byte[] filebytes = System.IO.File.ReadAllBytes(tempFilePath);
            return(File(filebytes, "application/force-download", "Data Vendor " + aspNetVendor.CompanyName + ".pdf"));
        }
Пример #2
0
        public async Task <ViewResult> PDFUpload(IFormFile file, AspNetVendor aspNetVendor)
        {
            ViewBag.userId = _usermanager.GetUserId(HttpContext.User);
            string uid = ViewBag.userId;

            try
            {
                string uploadSuccess = await pdfUpload.UploadPDF(file);

                if (uploadSuccess == "")
                {
                    var CheckUser = _context.AspNetVendor.FirstOrDefault(a => a.UserId == uid);

                    if (CheckUser == null)
                    {
                        const string msg = "For The First Time, You Must Upload Yor Comapany Data with Pdf, or Docx Extension";
                        throw new Exception(msg);
                    }
                    else
                    {
                        var CheckId = _context.AspNetVendor.FirstOrDefault(a => a.UserId == uid);
                        if (CheckId != null)
                        {
                            //CheckId.UserId = aspNetVendor.UserId;
                            CheckId.NpwpNo         = aspNetVendor.NpwpNo;
                            CheckId.CompanyName    = aspNetVendor.CompanyName;
                            CheckId.Address        = aspNetVendor.Address;
                            CheckId.SiupNo         = aspNetVendor.SiupNo;
                            CheckId.SuplierType    = "Null";
                            CheckId.ContactName    = aspNetVendor.ContactName;
                            CheckId.Contact        = aspNetVendor.Contact;
                            CheckId.ContactEmail   = aspNetVendor.ContactEmail;
                            CheckId.InvoiceName    = aspNetVendor.InvoiceName;
                            CheckId.InvoiceEmail   = aspNetVendor.InvoiceEmail;
                            CheckId.InvoiceContact = aspNetVendor.InvoiceContact;
                            CheckId.swiftcode      = aspNetVendor.swiftcode;
                            //CheckId.FileLocation = uploadSuccess;

                            _context.AspNetVendor.Update(CheckId);

                            await _context.SaveChangesAsync();
                        }
                    }
                }
                else if (uploadSuccess != "File must be either .pdf, .docx, .doc, .zip, or .rar")
                {
                    ViewBag.Message = "File Uploaded Successfully";
                    var data = new AspNetVendor
                    {
                        UserId         = uid,
                        CompanyName    = aspNetVendor.CompanyName,
                        Address        = aspNetVendor.Address,
                        NpwpNo         = aspNetVendor.NpwpNo,
                        SiupNo         = aspNetVendor.SiupNo,
                        SuplierType    = "Null",
                        ContactName    = aspNetVendor.ContactName,
                        Contact        = aspNetVendor.Contact,
                        ContactEmail   = aspNetVendor.ContactEmail,
                        InvoiceName    = aspNetVendor.InvoiceName,
                        InvoiceContact = aspNetVendor.InvoiceContact,
                        InvoiceEmail   = aspNetVendor.InvoiceEmail,
                        swiftcode      = aspNetVendor.swiftcode,
                        FileLocation   = uploadSuccess
                    };

                    var CheckUser = _context.AspNetVendor.FirstOrDefault(a => a.UserId == uid);
                    if (CheckUser == null)
                    {
                        if (ModelState.IsValid)
                        {
                            _context.AspNetVendor.Add(data);
                            await _context.SaveChangesAsync();
                        }
                    }
                    else
                    {
                        var CheckId = _context.AspNetVendor.FirstOrDefault(a => a.UserId == uid);
                        if (CheckId != null)
                        {
                            //CheckId.UserId = aspNetVendor.UserId;
                            CheckId.NpwpNo         = aspNetVendor.NpwpNo;
                            CheckId.CompanyName    = aspNetVendor.CompanyName;
                            CheckId.Address        = aspNetVendor.Address;
                            CheckId.SiupNo         = aspNetVendor.SiupNo;
                            CheckId.SuplierType    = "Null";
                            CheckId.ContactName    = aspNetVendor.ContactName;
                            CheckId.Contact        = aspNetVendor.Contact;
                            CheckId.ContactEmail   = aspNetVendor.ContactEmail;
                            CheckId.InvoiceName    = aspNetVendor.InvoiceName;
                            CheckId.InvoiceEmail   = aspNetVendor.InvoiceEmail;
                            CheckId.InvoiceContact = aspNetVendor.InvoiceContact;
                            CheckId.FileLocation   = uploadSuccess;
                            CheckId.swiftcode      = aspNetVendor.swiftcode;

                            _context.AspNetVendor.Update(CheckId);

                            await _context.SaveChangesAsync();
                        }
                    }
                }
                return(View("Index"));
            }
            catch (Exception ex)
            {
                return(View("Error", new ErrorViewModel()
                {
                    ErrorMessage = ex.Message
                }));
            }
        }
Пример #3
0
        public async Task <IActionResult> UpdateVendorData(IFormFile file1, UserViewModel model)
        {
            var userLogin = _userManager.GetUserName(User);

            //variabel error jika ada
            var hasilError = "";

            //Tambahkan Link Akses Direktori
            var link1 = "wwwroot/Pdf/Vendor";
            var link2 = "wwwroot\\Pdf\\Vendor\\";

            //Cek User yang Terhubung
            var _users = _dbContext.AspNetUsers.FirstOrDefault(a => a.UserName == userLogin);

            //model baru jika ada error
            var modelSimpan = (from user in _dbContext.AspNetUsers
                               join role in _dbContext.Roles on user.RolesId equals Convert.ToString(role.Id)
                               join vendor in _dbContext.AspNetVendor on user.UserName equals vendor.UserId
                               into joinVendor
                               from Vendor in joinVendor.DefaultIfEmpty()
                               where user.UserName == userLogin
                               select new UserViewModel
            {
                aspnetUser = user,
                roles = role,
                AspNetVendor = Vendor
            }).FirstOrDefault();

            var photos = modelSimpan.aspnetUser.Picture;

            if (photos == null)
            {
                photos = "avatar5.png";
            }
            ViewBag.Picture = photos;

            //Setelah Model Disimpan lakukan Proses
            if (userLogin == null)
            {
                return(Redirect("/Account/Login"));
            }
            if (_users == null)
            {
                hasilError        = "User with username = "******" Not Found !!";
                ViewBag.ErrorPage = hasilError;
                return(View("ProfileUser", modelSimpan));
            }
            //Cek apakah dia ada di aspNetVendor
            var _inAspVendor = _dbContext.AspNetVendor.FirstOrDefault(a => a.UserId == userLogin);

            //Jika Tidak Ada lakukan insert Procedure
            if (_inAspVendor == null)
            {
                //Cek apakah File PDF Null
                if (file1 == null)
                {
                    hasilError        = "You Must Insert Your Company File First !!";
                    ViewBag.ErrorPage = hasilError;
                    return(View("ProfileUser", modelSimpan));
                }
                //Upload PDF
                string uploadPDF = await _uploadPDF.PDFUpload(file1, link1);

                if (uploadPDF == "")
                {
                    hasilError        = "Cannot Get Your File, Please Upload .pdf file with 5MB Maximum size !!";
                    ViewBag.ErrorPage = hasilError;
                    return(View("ProfileUser", modelSimpan));
                }
                else if (uploadPDF != "File must be .pdf extension and Maximum Size is 5MB")
                {
                    //Add Data Vendor in Table ASPNET Vendor
                    var VendorData = new AspNetVendor
                    {
                        UserId         = userLogin,
                        CompanyName    = model.AspNetVendor.CompanyName,
                        Address        = model.AspNetVendor.Address,
                        NpwpNo         = model.AspNetVendor.NpwpNo,
                        SiupNo         = model.AspNetVendor.SiupNo,
                        SuplierType    = "",
                        ContactName    = model.AspNetVendor.ContactName,
                        Contact        = model.AspNetVendor.Contact,
                        ContactEmail   = model.AspNetVendor.ContactEmail,
                        InvoiceName    = model.AspNetVendor.InvoiceName,
                        InvoiceContact = model.AspNetVendor.InvoiceContact,
                        InvoiceEmail   = model.AspNetVendor.InvoiceEmail,
                        FileLocation   = uploadPDF,
                        Swiftcode      = model.AspNetVendor.Swiftcode,
                        Bank_Account1  = model.AspNetVendor.Bank_Account1,
                        Bank_Account2  = model.AspNetVendor.Bank_Account2,
                        VendorCity     = model.AspNetVendor.VendorCity,
                        VendorFaxNo    = model.AspNetVendor.VendorFaxNo,
                        Currency       = model.AspNetVendor.Currency,
                        Country        = model.AspNetVendor.Country,
                        IsActive       = "No",
                    };
                    _dbContext.AspNetVendor.Add(VendorData);
                    await _dbContext.SaveChangesAsync();

                    //Update Users Role
                    _users.RolesId = "1002";
                    _dbContext.AspNetUsers.Update(_users);
                    await _dbContext.SaveChangesAsync();

                    //Reload Page
                    return(RedirectToAction(nameof(ProfileUser)));
                }
                else
                {
                    hasilError        = uploadPDF;
                    ViewBag.ErrorPage = hasilError;
                    return(View("ProfileUser", modelSimpan));
                }
            }
            else
            {
                var _aspnetVendor = _dbContext.AspNetVendor.FirstOrDefault(a => a.UserId == userLogin);
                //Cek Vendor di tabel BML
                var _vendorinBMLContext = _bmlContext.Vendors.FirstOrDefault(a => a.VendorNo == _aspnetVendor.VendorNo);

                if (_aspnetVendor.IsActive == "Yes")
                {
                    _vendorinBMLContext.VendorContact    = model.AspNetVendor.ContactName;
                    _vendorinBMLContext.VendorPhoneNo    = model.AspNetVendor.Contact;
                    _vendorinBMLContext.VendorFaxNo      = model.AspNetVendor.VendorFaxNo;
                    _vendorinBMLContext.MobileNo         = model.AspNetVendor.InvoiceContact;
                    _vendorinBMLContext.Email            = model.AspNetVendor.ContactEmail;
                    _vendorinBMLContext.LastModifiedBy   = _userManager.GetUserName(User);
                    _vendorinBMLContext.LastModifiedTime = DateTime.Now;
                    _bmlContext.Vendors.Update(_vendorinBMLContext);
                    _bmlContext.SaveChanges();

                    //Update di tabel MainSystem
                    _aspnetVendor.ContactName    = model.AspNetVendor.ContactName;
                    _aspnetVendor.Contact        = model.AspNetVendor.Contact;
                    _aspnetVendor.ContactEmail   = model.AspNetVendor.ContactEmail;
                    _aspnetVendor.InvoiceName    = model.AspNetVendor.InvoiceName;
                    _aspnetVendor.InvoiceContact = model.AspNetVendor.InvoiceContact;
                    _aspnetVendor.InvoiceEmail   = model.AspNetVendor.InvoiceEmail;
                    _aspnetVendor.VendorFaxNo    = model.AspNetVendor.VendorFaxNo;
                    _dbContext.AspNetVendor.Update(_aspnetVendor);
                    _dbContext.SaveChanges();

                    //reload page
                    return(RedirectToAction(nameof(ProfileUser)));
                }
                else
                {
                    if (file1 == null)
                    {
                        _aspnetVendor.CompanyName    = model.AspNetVendor.CompanyName;
                        _aspnetVendor.Address        = model.AspNetVendor.Address;
                        _aspnetVendor.NpwpNo         = model.AspNetVendor.NpwpNo;
                        _aspnetVendor.SiupNo         = model.AspNetVendor.SiupNo;
                        _aspnetVendor.ContactName    = model.AspNetVendor.ContactName;
                        _aspnetVendor.Contact        = model.AspNetVendor.Contact;
                        _aspnetVendor.ContactEmail   = model.AspNetVendor.ContactEmail;
                        _aspnetVendor.InvoiceName    = model.AspNetVendor.InvoiceName;
                        _aspnetVendor.InvoiceContact = model.AspNetVendor.InvoiceContact;
                        _aspnetVendor.InvoiceEmail   = model.AspNetVendor.InvoiceEmail;
                        _aspnetVendor.Swiftcode      = model.AspNetVendor.Swiftcode;
                        _aspnetVendor.Bank_Account1  = model.AspNetVendor.Bank_Account1;
                        _aspnetVendor.Bank_Account2  = model.AspNetVendor.Bank_Account2;
                        _aspnetVendor.Country        = model.AspNetVendor.Country;
                        _aspnetVendor.Currency       = model.AspNetVendor.Currency;
                        _aspnetVendor.VendorCity     = model.AspNetVendor.VendorCity;
                        _aspnetVendor.VendorFaxNo    = model.AspNetVendor.VendorFaxNo;
                        _dbContext.AspNetVendor.Update(_aspnetVendor);
                        await _dbContext.SaveChangesAsync();

                        //Update Users Role
                        _users.RolesId = "1002";
                        _dbContext.AspNetUsers.Update(_users);
                        await _dbContext.SaveChangesAsync();

                        //Cek apakah data sudah ada di BML Context
                        if (_aspnetVendor.VendorNo != null || _aspnetVendor.VendorNo != "")
                        {
                            _vendorinBMLContext.VendorName    = model.AspNetVendor.CompanyName;
                            _vendorinBMLContext.VendorAddress = model.AspNetVendor.Address;
                            _vendorinBMLContext.VendorCity    = model.AspNetVendor.VendorCity;
                            _vendorinBMLContext.VendorContact = model.AspNetVendor.ContactName;
                            _vendorinBMLContext.VendorPhoneNo = model.AspNetVendor.Contact;
                            _vendorinBMLContext.VendorFaxNo   = model.AspNetVendor.VendorFaxNo;
                            _vendorinBMLContext.CurrencyCode  = model.AspNetVendor.Currency;
                            _vendorinBMLContext.Country       = model.AspNetVendor.Country;
                            _vendorinBMLContext.MobileNo      = model.AspNetVendor.InvoiceContact;
                            _vendorinBMLContext.Email         = model.AspNetVendor.InvoiceEmail;
                            _vendorinBMLContext.Swiftcode     = model.AspNetVendor.Swiftcode;
                            _bmlContext.Vendors.Update(_vendorinBMLContext);
                            _bmlContext.SaveChanges();
                        }

                        //reload page
                        return(RedirectToAction(nameof(ProfileUser)));
                    }
                    else
                    {
                        string uploadPDF = await _uploadPDF.PDFUpload(file1, link1);

                        if (uploadPDF == "")
                        {
                            hasilError        = "Cannot Get Your File, Please Upload .pdf file with 5MB Maximum size !!";
                            ViewBag.ErrorPage = hasilError;
                            return(View("ProfileUser", modelSimpan));
                        }
                        else if (uploadPDF != "File must be .pdf extension and Maximum Size is 5MB")
                        {
                            //hapus existing pdf
                            string Dispose = _deletePDF.Delete(modelSimpan.AspNetVendor.FileLocation, link2);
                            _aspnetVendor.CompanyName    = model.AspNetVendor.CompanyName;
                            _aspnetVendor.Address        = model.AspNetVendor.Address;
                            _aspnetVendor.NpwpNo         = model.AspNetVendor.NpwpNo;
                            _aspnetVendor.SiupNo         = model.AspNetVendor.SiupNo;
                            _aspnetVendor.ContactName    = model.AspNetVendor.ContactName;
                            _aspnetVendor.Contact        = model.AspNetVendor.Contact;
                            _aspnetVendor.ContactEmail   = model.AspNetVendor.ContactEmail;
                            _aspnetVendor.InvoiceName    = model.AspNetVendor.InvoiceName;
                            _aspnetVendor.InvoiceContact = model.AspNetVendor.InvoiceContact;
                            _aspnetVendor.InvoiceEmail   = model.AspNetVendor.InvoiceEmail;
                            _aspnetVendor.Swiftcode      = model.AspNetVendor.Swiftcode;
                            _aspnetVendor.Bank_Account1  = model.AspNetVendor.Bank_Account1;
                            _aspnetVendor.Bank_Account2  = model.AspNetVendor.Bank_Account2;
                            _aspnetVendor.Country        = model.AspNetVendor.Country;
                            _aspnetVendor.Currency       = model.AspNetVendor.Currency;
                            _aspnetVendor.VendorCity     = model.AspNetVendor.VendorCity;
                            _aspnetVendor.VendorFaxNo    = model.AspNetVendor.VendorFaxNo;
                            _aspnetVendor.FileLocation   = uploadPDF;
                            _dbContext.AspNetVendor.Update(_aspnetVendor);
                            await _dbContext.SaveChangesAsync();

                            //Update Users Role
                            _users.RolesId = "1002";
                            _dbContext.AspNetUsers.Update(_users);
                            await _dbContext.SaveChangesAsync();

                            //Cek apakah data sudah ada di BML Context
                            if (_aspnetVendor.VendorNo != null || _aspnetVendor.VendorNo != "")
                            {
                                _vendorinBMLContext.VendorName    = model.AspNetVendor.CompanyName;
                                _vendorinBMLContext.VendorAddress = model.AspNetVendor.Address;
                                _vendorinBMLContext.VendorCity    = model.AspNetVendor.VendorCity;
                                _vendorinBMLContext.VendorContact = model.AspNetVendor.ContactName;
                                _vendorinBMLContext.VendorPhoneNo = model.AspNetVendor.Contact;
                                _vendorinBMLContext.VendorFaxNo   = model.AspNetVendor.VendorFaxNo;
                                _vendorinBMLContext.CurrencyCode  = model.AspNetVendor.Currency;
                                _vendorinBMLContext.Country       = model.AspNetVendor.Country;
                                _vendorinBMLContext.MobileNo      = model.AspNetVendor.InvoiceContact;
                                _vendorinBMLContext.Email         = model.AspNetVendor.InvoiceEmail;
                                _vendorinBMLContext.Swiftcode     = model.AspNetVendor.Swiftcode;
                                _bmlContext.Vendors.Update(_vendorinBMLContext);
                                _bmlContext.SaveChanges();
                            }

                            //reload page
                            return(RedirectToAction(nameof(ProfileUser)));
                        }
                        else
                        {
                            hasilError        = uploadPDF;
                            ViewBag.ErrorPage = hasilError;
                            return(View("ProfileUser", modelSimpan));
                        }
                    }
                }
            }
        }