예제 #1
0
        public ActionResult Attach(string id)
        {
            var entity = RavenSession.Load <object>(id);

            if (entity == null)
            {
                return(HttpNotFound("Specified entity does not exists"));
            }

            using (var attachmentReader = new RequestAttachmentReader(Request))
            {
                if (attachmentReader.Count != 1)
                {
                    throw new NotSupportedException("One and only one attachment is required.");
                }

                var attachment = attachmentReader.First();

                var result = ExecuteCommand(new SaveAttachment(
                                                entity,
                                                attachment.Key,
                                                attachment.Value));

                return(Json(new { success = true, attachment = result }));
            }
        }
예제 #2
0
        public ActionResult QuickAttachment()
        {
            //The normal binding does not work
            var id            = RouteData.Values["id"] as string;
            var slotId        = Request.Form["slot"] as string;
            var name          = Request.Form["name"] as string;
            var uploadToNotes = string.IsNullOrEmpty(slotId);

            Employee employee;

            if (id == null)
            {
                employee = CreateEmployee(name);
            }
            else
            {
                employee = RavenSession.Load <Employee>(id);
                if (employee == null)
                {
                    return(HttpNotFound());
                }
            }

            using (var attachmentReader = new RequestAttachmentReader(Request))
            {
                var reading = attachmentReader.Select(x => ExecuteCommand(new SaveAttachment(employee, x.Key, x.Value)));
                if (!uploadToNotes)
                {
                    reading = reading.Take(1);
                }
                var attachments          = reading.ToArray();
                SlotWithAttachment added = null;

                if (string.IsNullOrEmpty(slotId))
                {
                    QuickAttachToNotes(employee, attachments);
                }
                else
                {
                    var slot = RavenSession.Load <AttachmentSlot>(slotId);
                    if (slot == null)
                    {
                        return(HttpNotFound());
                    }

                    added = employee.AddAttachment(attachments.First(), slot);
                }

                return(Json(new
                {
                    success = true,
                    entityId = employee.Id,
                    editUrl = Url.Action("Edit", new { id = employee.Id }),
                    attachment = attachments.FirstOrDefault(),
                    attachments = attachments,
                    added = added
                }));
            }
        }
예제 #3
0
        public ActionResult QuickAttachment()
        {
            Applicant applicant;
            //The normal binding does not work
            var id   = RouteData.Values["id"] as string;
            var name = Request.Form["name"] as string;

            if (id == null)
            {
                applicant = new Applicant(name);
                RavenSession.Store(applicant);
            }
            else
            {
                applicant = RavenSession.Load <Applicant>(id);
                if (applicant == null)
                {
                    return(HttpNotFound());
                }
            }

            using (var attachmentReader = new RequestAttachmentReader(Request))
            {
                var attachments = attachmentReader
                                  .Select(x => ExecuteCommand(new SaveAttachment(applicant, x.Key, x.Value)))
                                  .ToArray();

                var notes = attachments.Select(x => new NoteWithAttachment()
                {
                    Attachment   = x,
                    Note         = "QuickAttachment!",
                    RealDate     = DateTime.Now,
                    RegisterDate = DateTime.Now
                });

                if (applicant.Notes == null)
                {
                    applicant.Notes = notes.ToList();
                }
                else
                {
                    applicant.Notes.AddRange(notes);
                }

                return(Json(new
                {
                    success = true,
                    entityId = applicant.Id,
                    editUrl = Url.Action("Edit", new { id = applicant.Id }),
                    attachment = attachments.FirstOrDefault(),
                    attachments = attachments
                }));
            }
        }
예제 #4
0
        public ActionResult Post(string id)
        {
            var entity = RavenSession.Load <object>(id);

            if (entity == null)
            {
                return(HttpNotFound("Specified entity does not exists"));
            }

            using (var attachmentReader = new RequestAttachmentReader(Request))
            {
                var attachments = attachmentReader
                                  .Select(x => ExecuteCommand(new SaveAttachment(entity, x.Key, x.Value)))
                                  .ToArray();

                return(Json(new { success = true, attachment = attachments.FirstOrDefault(), attachments = attachments }));
            }
        }
예제 #5
0
        public ActionResult SavePhoto(string id)
        {
            var applicant = RavenSession.Load <Applicant>(id);

            using (var attachmentReader = new RequestAttachmentReader(Request))
            {
                if (attachmentReader.Count != 1)
                {
                    throw new NotSupportedException("One and only one photo is required.");
                }

                var attachment = attachmentReader.First();

                applicant.Photo = ExecuteCommand(new SavePhotoAttachments(
                                                     applicant,
                                                     attachment.Key,
                                                     attachment.Value));
                return(Json(new { success = true, attachment = applicant.Photo }));
            }
        }
예제 #6
0
        public ActionResult Attach(string id)
        {
            var entity = RavenSession.Load<object>(id);
            if (entity == null)
                return HttpNotFound("Specified entity does not exists");

            using (var attachmentReader = new RequestAttachmentReader(Request))
            {
                if (attachmentReader.Count != 1)
                    throw new NotSupportedException("One and only one attachment is required.");

                var attachment = attachmentReader.First();

                var result = ExecuteCommand(new SaveAttachment(
                    entity,
                    attachment.Key,
                    attachment.Value));

                return Json(new { success = true, attachment = result });
            }
        }
        public ActionResult SavePhoto(string id, string fileName)
        {
            var employee = RavenSession.Load<Employee>(id);

            using (var attachmentReader = new RequestAttachmentReader(Request))
            {
                if (attachmentReader.Count != 1)
                    throw new NotSupportedException("One and only one photo is required.");

                var attachment = attachmentReader.First();

                employee.Photo = ExecuteCommand(new SavePhotoAttachments(
                    employee,
                    attachment.Key,
                    attachment.Value));
                return Json(new { success = true, attachment = employee.Photo });
            }
        }
        public ActionResult QuickAttachment()
        {
            //The normal binding does not work
            var id = RouteData.Values["id"] as string;
            var slotId = Request.Form["slot"] as string;
            var name = Request.Form["name"] as string;
            var uploadToNotes = string.IsNullOrEmpty(slotId);

            Employee employee;
            if (id == null)
            {
                employee = CreateEmployee(name);
            }
            else
            {
                employee = RavenSession.Load<Employee>(id);
                if (employee == null)
                    return HttpNotFound();
            }

            using (var attachmentReader = new RequestAttachmentReader(Request))
            {
                var reading = attachmentReader.Select(x => ExecuteCommand(new SaveAttachment(employee, x.Key, x.Value)));
                if (!uploadToNotes)
                {
                    reading = reading.Take(1);
                }
                var attachments = reading.ToArray();
                SlotWithAttachment added = null;

                if (string.IsNullOrEmpty(slotId))
                {
                    QuickAttachToNotes(employee, attachments);
                }
                else
                {
                    var slot = RavenSession.Load<AttachmentSlot>(slotId);
                    if (slot == null)
                        return HttpNotFound();

                    added = employee.AddAttachment(attachments.First(), slot);
                }

                return Json(new
                {
                    success = true,
                    entityId = employee.Id,
                    editUrl = Url.Action("Edit", new { id = employee.Id }),
                    attachment = attachments.FirstOrDefault(),
                    attachments = attachments,
                    added = added
                });
            }
        }
예제 #9
0
        public ActionResult QuickAttachment()
        {
            Applicant applicant;
            //The normal binding does not work
            var id = RouteData.Values["id"] as string;
            var name = Request.Form["name"] as string;
            if (id == null)
            {
                applicant = new Applicant(name);
                RavenSession.Store(applicant);
            }
            else
            {
                applicant = RavenSession.Load<Applicant>(id);
                if (applicant == null)
                    return HttpNotFound();
            }

            using (var attachmentReader = new RequestAttachmentReader(Request))
            {
                var attachments = attachmentReader
                    .Select(x => ExecuteCommand(new SaveAttachment(applicant, x.Key, x.Value)))
                    .ToArray();

                var notes = attachments.Select(x => new NoteWithAttachment()
                    {
                        Attachment = x,
                        Note = "QuickAttachment!",
                        RealDate = DateTime.Now,
                        RegisterDate = DateTime.Now
                    });

                if (applicant.Notes == null)
                {
                    applicant.Notes = notes.ToList();
                }
                else
                {
                    applicant.Notes.AddRange(notes);
                }

                return Json(new
                {
                    success = true,
                    entityId = applicant.Id,
                    editUrl = Url.Action("Edit", new { id = applicant.Id }),
                    attachment = attachments.FirstOrDefault(),
                    attachments = attachments
                });
            }
        }
        public ActionResult Post(string id)
        {
            var entity = RavenSession.Load<object>(id);
            if (entity == null)
                return HttpNotFound("Specified entity does not exists");

            using (var attachmentReader = new RequestAttachmentReader(Request))
            {
                var attachments = attachmentReader
                    .Select(x => ExecuteCommand(new SaveAttachment(entity, x.Key, x.Value)))
                    .ToArray();

                return Json(new { success = true, attachment = attachments.FirstOrDefault(), attachments = attachments });
            }
        }