public ActionResult CompanyLogo()
        {
            // Initialization.
            ImgViewModel model = new ImgViewModel {
                FileAttach = null, FileName = ""
            };

            try
            {
                // Settings.
                model.ImgLst = (from c in db.AcCompanies
                                where c.AcCompanyID == 1
                                select new ImgObj
                {
                    FileId = 1,
                    FileName = "ICCSlogo.PNG",
                    FileContentType = c.Logo,
                    FileFullPath = "ICCSlogo"
                }).FirstOrDefault();
            }
            catch (Exception ex)
            {
                // Info
                Console.Write(ex);
            }

            // Info.
            return(this.View(model));
        }
        public ActionResult Index(string id)
        {
            if (Request.IsAuthenticated)
            {
                AuthenticateUser();

                int idDecrypted = Security.DecryptId(Convert.ToString(id));

                var opdExpenseService = _opdExpenseService.GetOpdExpensesAgainstId(Convert.ToInt32(idDecrypted));

                ViewData["OPDTYPE"]       = opdExpenseService.OpdType;
                ViewData["OPDEXPENSE_ID"] = idDecrypted;

                ImgViewModel model = new ImgViewModel {
                    FileAttach = null, ImgLst = new List <OpdExpenseImageVM>()
                };

                model.ImgLst = _opdExpenseImageService.GetOpdExpensesImageAgainstOpdExpenseId(Convert.ToInt32(idDecrypted));

                model.OPDExpenseID = idDecrypted;
                return(this.View(model));
            }
            else
            {
                return(RedirectToAction(UrlIndex, UrlHome));
            }
        }
        public ActionResult Index(ImgViewModel model)
        {
            if (Request.IsAuthenticated)
            {
                AuthenticateUser();

                if (ModelState.IsValid)
                {
                    // Converting to bytes.
                    byte[] uploadedFile = new byte[model.FileAttach.InputStream.Length];
                    model.FileAttach.InputStream.Read(uploadedFile, 0, uploadedFile.Length);

                    OpdExpenseImageVM opdExpense_Image = new OpdExpenseImageVM();

                    ViewData["OPDTYPE"] = model.OPDType;

                    if (model.OPDExpenseID == 0)
                    {
                        model.OPDExpenseID = Security.DecryptId(Request.Url.Segments[3].ToString());
                    }

                    string emailAddress = GetEmailAddress();
                    ViewData["OPDEXPENSE_ID"] = model.OPDExpenseID;
                    // Initialization.
                    opdExpense_Image.OpdExpenseId  = model.OPDExpenseID;
                    opdExpense_Image.ImageBase64   = Convert.ToBase64String(uploadedFile);
                    opdExpense_Image.ImageExt      = model.FileAttach.ContentType;
                    opdExpense_Image.CreatedDate   = DateTime.Now;
                    opdExpense_Image.ImageName     = model.FileAttach.FileName;
                    opdExpense_Image.NameExpenses  = model.ExpenseName;
                    opdExpense_Image.ExpenseAmount = model.ExpenseAmount;
                    OpdExpenseImageVM OpdExpensePatient_Obj = _opdExpenseImageService.CreateOpdExpenseImage(opdExpense_Image, emailAddress);

                    ImgViewModel modelUploaded = new ImgViewModel {
                        FileAttach = null, ImgLst = new List <OpdExpenseImageVM>()
                    };
                    ModelState.Clear();
                    modelUploaded.ImgLst = _opdExpenseImageService.GetOpdExpensesImageAgainstOpdExpenseId(Convert.ToInt32(model.OPDExpenseID));

                    return(this.View(modelUploaded));
                }
                else
                {
                    if (model.OPDExpenseID == 0)
                    {
                        model.OPDExpenseID = Security.DecryptId(Request.Url.Segments[3].ToString());
                    }
                    model.ImgLst              = _opdExpenseImageService.GetOpdExpensesImageAgainstOpdExpenseId(Convert.ToInt32(model.OPDExpenseID));
                    ViewData["OPDTYPE"]       = model.OPDType;
                    ViewData["OPDEXPENSE_ID"] = model.OPDExpenseID;
                    // Info
                    return(this.View(model));
                }
            }
            else
            {
                return(RedirectToAction(UrlIndex, UrlHome));
            }
        }
        public ActionResult CompanyLogo(ImgViewModel model)
        {
            // Initialization.
            string fileContent     = string.Empty;
            string fileContentType = string.Empty;
            string _path           = "";

            try
            {
                // Verification
                if (ModelState.IsValid)
                {
                    // Converting to bytes.
                    byte[] uploadedFile = new byte[model.FileAttach.InputStream.Length];
                    model.FileAttach.InputStream.Read(uploadedFile, 0, uploadedFile.Length);
                    string _FileName = Path.GetFileName(model.FileAttach.FileName);
                    _path = Path.Combine(Server.MapPath("~/UploadFiles"), _FileName);

                    Session["CompanyLogoByte"] = uploadedFile;
                    model.FileAttach.SaveAs(_path);

                    //file.SaveAs(_path);
                    // Initialization.
                    //fileContent = Convert.ToBase64String(uploadedFile);
                    //fileContentType = model.FileAttach.ContentType;
                    //model.Image = ConvertToBytes(model.FileAttach);
                    // Saving info.
                    //  this.databaseManager.sp_insert_file(model.FileAttach.FileName, fileContentType, fileContent);
                }

                // Settings.
                model.ImgLst = new ImgObj
                {
                    FileId          = 1,
                    FileName        = model.FileAttach.FileName,
                    FileContentType = model.FileAttach.ContentType,
                    FileFullPath    = _path
                };

                Session["LogoFilePath"] = _path;

                return(PartialView(model));
            }
            catch (Exception ex)
            {
                // Info
                Console.Write(ex);
            }

            // Info
            return(this.View(model));
        }
예제 #5
0
        public void ConvertTests()
        {
            // Arrange
            var    img      = new ImgViewModel();
            Bitmap image    = new Bitmap(@"zielone.jpg");
            var    expected = typeof(BitmapImage);

            // Act
            var actual = img.Convert(image);

            //Assert
            Assert.IsType(expected, actual);
        }
예제 #6
0
        public IActionResult UploadImg([FromForm] ImgViewModel input)
        {
            try
            {
                var retorno = imgRepository.UploadImg(input);

                return(StatusCode(200, retorno.Result));
            }
            catch (Exception ex)
            {
                return(StatusCode(400, ex.Message));
            }
        }
예제 #7
0
        private void formatMarginsMenuItem_Click(object sender, RoutedEventArgs e)
        {
            // Instantiate the dialog box
            DialogBox dlgView = new DialogBox();

            // Call parent view model to get child view model
            ImgViewModel mvm = this.DataContext as ImgViewModel;

            // Configure the dialog box
            dlgView.DataContext = mvm.DlgViewModel;

            // Open the dialog box modally
            dlgView.ShowDialog();
        }
예제 #8
0
        public void ToMainColorsTests()
        {
            // Arrange
            var          img   = new ImgViewModel();
            Bitmap       image = new Bitmap(@"zielone.jpg");
            const string WrongFormatMessage = "Niepoprawny format";

            // Act
            try
            {
                img.ToMainColors(image);
            }
            catch (BadImageFormatException e)
            {   // Assert
                Assert.Contains(e.Message, WrongFormatMessage);
            }
        }
예제 #9
0
        public async Task <RetornoJsonViewModel> UploadImg(ImgViewModel file)
        {
            var urlKeyService = Service.GetUrlAndKey();

            try
            {
                // Declaração de variavel byte
                byte[] imageData = null;

                // Abre uma leitura da imagem e transforma-a em uma stream (fluxo, corrente), após isso, cria uma classe de leitura binária
                var br = new BinaryReader(file.Img.OpenReadStream());
                // Transforma novamente a imagem em uma stream e usa como parametro, a propriedade Lenght (comprimento da stream), após isso lê todos os bytes do comprimento da stream e devolve uma matriz de bytes.
                imageData = br.ReadBytes((int)file.Img.OpenReadStream().Length);

                // Declaração de dados de multiplas partes, aceita variados dados para passar como parametro da requisição.
                // OBS. Seria como colocar na TAG <form> do HTML, uma propriedade "multipart/form-data" nos parametros.
                MultipartFormDataContent form = new MultipartFormDataContent();

                // Adiciona um parametro necessário para a requisição da api, chamada "key" (aqui seria a key da sua conta, dentro do site).
                form.Add(new StringContent(urlKeyService.Key), "key");
                // Adiciona a imagem em bytes (dados binários) como parametro.
                form.Add(new ByteArrayContent(imageData), "image", file.Img.FileName);
                // OBS. Esta API em especial, aceita dados baseados em 64 bits (base64), dados binários ou uma URL para a imagem.

                HttpResponseMessage resposta = await Client.PostAsync(urlKeyService.Url, form);

                if (!resposta.IsSuccessStatusCode)
                {
                    throw new Exception("Ocorreu um erro na requisição à API.");
                }

                // Propriedade Content guarda a resposta da requisição HTTP
                // Mapeia o objeto de resposta para RetornoJsonViewModel (mapeamento é representado pelos sinais de menor e igual <> seguido de parenteses)

                // Explicação da Sintaxe: após o método para ler assincronamente, dentro dos simbolos "<>" terá a classe de retorno do mapeamento e dentro dos parenteses, estará o objeto que será mapeado [...]
                // [...] Que neste caso, não é necessário para o nosso objetivo, pois estamos acessando o método de leitura com o próprio objeto de resposta da API.
                RetornoJsonViewModel retorno = await resposta.Content.ReadAsAsync <RetornoJsonViewModel>();

                return(retorno);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #10
0
 public SubscribeAsByteStream(RandomizeImage Ri, ImgViewModel Ivm)
 {
     base.imgRandomizer = Ri;
     this.ivm           = Ivm;
     debugmsg           = new StringBuilder();
 }
예제 #11
0
 public SubscribeAsByteStream(RandomizeImage Ri, ImgViewModel Ivm)
 {
     base.imgRandomizer=Ri;
     this.ivm = Ivm;
     debugmsg = new StringBuilder();
 }
예제 #12
0
 public MainWindow()
 {
     InitializeComponent();
     DataContext = new ImgViewModel();
     ImageTime.Text = "This TextBox Belongs to " + ImageTime.Dispatcher.Thread.Name;
 }
예제 #13
0
        private void Image_MouseMove(object sender, MouseEventArgs e)
        {
            ImgViewModel mvm = this.DataContext as ImgViewModel;

            mvm.ImageLocation = e.GetPosition(this).ToString();
        }
예제 #14
0
 public MainWindow()
 {
     InitializeComponent();
     DataContext    = new ImgViewModel();
     ImageTime.Text = "This TextBox Belongs to " + ImageTime.Dispatcher.Thread.Name;
 }