예제 #1
0
        public NoteImage Update(NoteImage entity)
        {
            context.Entry(entity).State = EntityState.Modified;
            context.SaveChanges();

            return(entity);
        }
예제 #2
0
        public NoteImage Create(NoteImage entity)
        {
            context.NoteImages.Add(entity);
            context.SaveChanges();

            return(entity);
        }
        private void AddImage(int noteId, IFormFile image)
        {
            NoteImage noteImage = new NoteImage();

            noteImage.NoteId = noteId;
            noteImage.Image  = EncodeImage(image);

            _context.note_images.Add(noteImage);
        }
예제 #4
0
        public static async Task <bool> RemoveNoteImage(NoteImage noteImage)
        {
            if (noteImage == null)
            {
                return(true);
            }
            bool success = true;

            try
            {
                Debug.WriteLine("Delete {0}", noteImage.URL);
                var file = await StorageFile.GetFileFromPathAsync(noteImage.URL);

                await file.DeleteAsync();
            }
            catch (Exception)
            {
                success = false;
            }

            return(success);
        }
예제 #5
0
        public virtual ActionResult Create(NoteImageViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.Image == null)
                {
                    ModelState.AddModelError("", "Proszę wybrać zdjecie.");
                    return(View(model));
                }

                var image = new NoteImage()
                {
                    NoteId = model.NoteId,
                    Title  = model.Title
                };

                var imageManager = new ImageManager(model.Image);

                if (ImageExist(imageManager))
                {
                    ModelState.AddModelError("", "Zdjęcie z taką nazwą już istnieje.");
                    return(View(model));
                }
                else
                {
                    if (UploadImage(imageManager))
                    {
                        image.Path = imageManager.FilePath;
                        image.Name = model.Image.FileName;
                    }
                }

                _imagesRepository.Create(image);

                return(RedirectToAction(MVC.Admin.NoteImages.List(model.NoteId)));
            }

            return(View(model));
        }
예제 #6
0
        public static async Task <bool> RemoveNoteImage(NoteImage noteImage, bool deleteFromDB = true)
        {
            if (noteImage == null)
            {
                return(true);
            }
            bool success = true;

            try
            {
                Debug.WriteLine("Delete " + noteImage.URL);
                var file = await StorageFile.GetFileFromPathAsync(noteImage.URL);

                await file.DeleteAsync();

                if (deleteFromDB)
                {
                    LocalDB.Delete(noteImage);
                    RoamingDB.Delete(noteImage);
                }
            }
            catch (Exception)
            {
                success = false;
            }

            if (deleteFromDB)
            {
                var handler2 = NotesSaved;
                if (handler2 != null)
                {
                    handler2(null, EventArgs.Empty);
                }
            }

            return(success);
        }
예제 #7
0
        public async Task <JsonResult> NewNote(string zoneId)
        {
            string userId = _userManager.GetUserId(User);

            string content    = Request.Form["noteContent"].ToString();
            string noteTypeId = Request.Form["noteType"].ToString();
            string dateTime   = Request.Form["dateTime"].ToString();

            var files = Request.Form.Files;


            var zone = _context.zone.Where(z => z.zoneId == zoneId)
                       .Select(z => new
            {
                zoneId    = z.zoneId,
                projectId = z.zoneType.project.projectId,
                zoneName  = z.name,
                planName  = z.plan.name
            }).FirstOrDefault();



            var staff = _context.staff.Where(s => s.Id == userId && s.department.project.projectId == zone.projectId).Include(s => s.department.project).Include(s => s.user).FirstOrDefault();

            if (staff == null)
            {
                Response.StatusCode = 400;
                return(Json(new { error = "Bad Request" }));
            }


            DateTime date;

            if (!(DateTime.TryParse(dateTime, out date)))
            {
                Response.StatusCode = 400;
                return(Json(new { error = "Bad Request: Invalid Date Time" }));
            }

            Note note = new Note
            {
                noteId     = Guid.NewGuid().ToString(),
                content    = content,
                noteTypeId = noteTypeId,
                zoneId     = zoneId,
                createdAt  = DateTime.Now,
                staffId    = staff.staffId
            };

            _context.note.Add(note);
            _context.SaveChanges();

            string imgSrcList = "";

            string serverPath   = Path.Combine(new string[] { _environment.WebRootPath, "construction", "noteimage" });
            string dataBasePath = Path.Combine(new string[] { "/", "construction", "noteimage" });

            for (int i = 0; i < files.Count; i++)
            {
                IFormFile file = files.ElementAt(i);
                if (file.Length > 0)
                {
                    string id = Guid.NewGuid().ToString();

                    string fileServerPath = Path.Combine(serverPath, id);
                    if (!Directory.Exists(fileServerPath))
                    {
                        Directory.CreateDirectory(fileServerPath);
                    }

                    string path = Path.Combine(fileServerPath, file.FileName);
                    using (var fileStream = new FileStream(path, FileMode.Create))
                    {
                        await file.CopyToAsync(fileStream);
                    }

                    NoteImage noteImage = new NoteImage
                    {
                        noteImageId = id,
                        noteId      = note.noteId,
                        staffId     = staff.staffId,
                        imgSrc      = Path.Combine(dataBasePath, id, file.FileName)
                    };
                    _context.noteImage.Add(noteImage);
                    _context.SaveChanges();

                    imgSrcList += "<img style=\"width: 100%; margin: .5em auto; border: solid 2px rgba(0, 0, 0, .1)\" src=\"http://cospotter.com/" + noteImage.imgSrc + "\"/>";
                }
            }


            var users = _context.staff.Where(s => s.department.project.projectId == zone.projectId)
                        .Select(s => new
            {
                fullname = s.user.fullname,
                email    = s.user.Email
            }).ToList();

            var noteType = _context.noteType.Where(z => z.noteTypeId == noteTypeId).FirstOrDefault();

            string subject = "Notification from - " + staff.department.project.name;
            string body    = "<div style=\"font-family: inherit; padding: 1em\"><h3 style=\"margin: .5em 0\">"
                             + zone.planName + " - " + zone.zoneName + " - " + noteType.name + "</h3><p style=\"line-height: 1.5em; margin: 0 0 .5em 0\">"
                             + note.content
                             + "</p><h5 style=\"margin: .5em 0; line-height: 1.5em\">By <label style=\"background-color: #eee; padding: .15em .5em; border-radius: 2px\">"
                             + /*USER INFO*/ staff.user.fullname + " - " + staff.user.Email + "</label> from <label style=\"background-color: #eee; padding: .15em .5em; border-radius: 2px\">"
                             + /*DEPARTMENT*/ staff.department.name + " </label></h5><div>"
                             + /*IMG LIST-- <img style=\"width: 30%; margin: 0 auto; border: solid 2px rgba(0, 0, 0, .1)\" src=\"1.png\"/> --*/ imgSrcList + "</div></div>"
                             + "<div><a style=\"font-size:3em; text-decoration:none; display:flex; align-content:center; align-items:center\" href=\"http://cospotter.com/app\"><img src=\"http://cospotter.com/images/icons/Cospotter.png\"/><h2>Cospotter</h2></a></div>";

            _emailSender.SendEmailAsync(users, subject, body);

            var notes = _context.note
                        .Include(n => n.staff.user)
                        .Where(n => n.zoneId == zoneId)
                        .Select(n => new
            {
                noteType   = n.noteType.name,
                content    = n.content,
                createdAt  = n.createdAt,
                username   = n.staff.user.Email,
                noteImages = _context.noteImage.Where(nm => nm.noteId == n.noteId).Select(nm => new { src = nm.imgSrc }).ToList()
            }).ToList();

            return(Json(new { notes }));
        }
예제 #8
0
        public async void HandleImageFromFilePicker(IReadOnlyList <StorageFile> files)
        {
            NotesPage.EnablePopupLightDismiss();

            if (files == null || files.Count <= 0)
            {
                return;
            }
            bool error = false;

            try
            {
                //delete old images
                //await AppData.RemoveNoteImages(Note.Images);

                //clear image list
                //Note.Images.Clear();

                //add new images
                foreach (var file in files)
                {
                    if (file == null)
                    {
                        continue;
                    }
                    Debug.WriteLine("Picked photo: " + file.Path);

                    NoteImage noteImage = new NoteImage();

                    StorageFile savedImage = await AppSettings.Instance.SaveImage(file, Note.ID, noteImage.ID);

                    var imageProperties = await savedImage.Properties.GetImagePropertiesAsync();

                    noteImage.NoteId = Note.ID;
                    noteImage.URL    = savedImage.Path;
                    noteImage.Width  = imageProperties.Width;
                    noteImage.Height = imageProperties.Height;

                    Note.Images.Add(noteImage);
                    break;
                }

                //Note.NotifyPropertyChanged("Images");
            }
            catch (Exception e)
            {
                error = true;

                var exceptionProperties = new Dictionary <string, string>()
                {
                    { "Details", "Failed to save images" }
                };

                var exceptionMetrics = new Dictionary <string, double>();
                exceptionMetrics.Add("Image count", Note.Images.Count);
                for (int i = 0; i < Note.Images.Count; i++)
                {
                    exceptionMetrics.Add(string.Format("Image[{0}] Width", i), Note.Images[i].Width);
                    exceptionMetrics.Add(string.Format("Image[{0}] Height", i), Note.Images[i].Height);
                }

                App.TelemetryClient.TrackException(e, exceptionProperties, exceptionMetrics);
            }

            if (error)
            {
                //await(new MessageDialog("Failed to save image. Try again.", "Sorry")).ShowAsync();
                return;
            }

            // update note with new image so we dont lose it if the user closes the app
            if (!IsNewNote && !Note.IsEmpty())
            {
                try
                {
                    bool success = await AppData.CreateOrUpdateNote(Note);

                    if (success)
                    {
                        IsNewNote = false;
                    }
                } catch (Exception e) { }
            }
        }