Exemplo n.º 1
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
                }));
            }
        }
Exemplo n.º 2
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
                }));
            }
        }
Exemplo n.º 3
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 }));
            }
        }
        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
                });
            }
        }
Exemplo n.º 5
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 });
            }
        }