示例#1
0
        private async Task AddPicture(Patient patient, IFormFile thePicture)
        {
            //get the picture and save it with the Patient
            if (thePicture != null)
            {
                string mimeType   = thePicture.ContentType;
                long   fileLength = thePicture.Length;
                if (!(mimeType == "" || fileLength == 0))//Looks like we have a file!!!
                {
                    if (mimeType.Contains("image"))
                    {
                        PatientPhoto p = new PatientPhoto
                        {
                            FileName = Path.GetFileName(thePicture.FileName)
                        };
                        using (var memoryStream = new MemoryStream())
                        {
                            await thePicture.CopyToAsync(memoryStream);

                            p.PhotoContentFull.Content   = memoryStream.ToArray();
                            p.PhotoContentFull.MimeType  = mimeType;
                            p.PhotoContentThumb.Content  = ResizeImage.shrinkImagePNG(p.PhotoContentFull.Content);
                            p.PhotoContentThumb.MimeType = "image/png";
                        }
                        patient.PatientPhoto = p;
                    }
                }
            }
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Title title, IFormFile titleImage)
        {
            if (ModelState.IsValid)
            {
                if (titleImage != null)
                {
                    string mimeType   = titleImage.ContentType;
                    long   fileLength = titleImage.Length;
                    if (!(mimeType == "" || fileLength == 0))
                    {
                        using (var memoryStream = new MemoryStream())
                        {
                            await titleImage.CopyToAsync(memoryStream);

                            title.TitleImageContent = ResizeImage.shrinkImagePNG(memoryStream.ToArray(), 150, 150);
                        }
                        title.TitleImageMimeType = mimeType;
                        title.TitleImageFileName = titleImage.FileName;
                    }
                }

                _context.Add(title);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(title));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,TitleId")] Issue issue, IFormFile coverImage)
        {
            if (ModelState.IsValid)
            {
                if (coverImage != null)
                {
                    string mimeType   = coverImage.ContentType;
                    long   fileLength = coverImage.Length;
                    if (!(mimeType == "" || fileLength == 0))
                    {
                        using (var memoryStream = new MemoryStream())
                        {
                            await coverImage.CopyToAsync(memoryStream);

                            issue.CoverImageContent = ResizeImage.shrinkImagePNG(memoryStream.ToArray(), 150, 150);
                        }
                        issue.CoverImageMimeType = mimeType;
                        issue.CoverImageFileName = coverImage.FileName;
                    }
                }

                _context.Add(issue);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TitleId"] = new SelectList(_context.Titles, "Id", "Id", issue.TitleId);
            return(View(issue));
        }
示例#4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Title title, IFormFile titleImage)
        {
            if (id != title.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (titleImage != null)
                    {
                        string mimeType   = titleImage.ContentType;
                        long   fileLength = titleImage.Length;
                        if (!(mimeType == "" || fileLength == 0))
                        {
                            using (var memoryStream = new MemoryStream())
                            {
                                await titleImage.CopyToAsync(memoryStream);

                                title.TitleImageContent = ResizeImage.shrinkImagePNG(memoryStream.ToArray(), 150, 150);
                            }
                            title.TitleImageMimeType = mimeType;
                            title.TitleImageFileName = titleImage.FileName;
                        }
                    }

                    _context.Update(title);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TitleExists(title.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(title));
        }