public ActionResult RecordByAttachment(int id) { using (Entity context = new Entity()) { t_observation_attachment attachment = context.t_observation_attachment.Find(id); if (attachment == null) { throw new ArgumentException("Invalid ObservationAttachmentID: " + id.ToString()); } t_observation observation = context.t_observation.Find(attachment.observation_id); if (observation == null) { throw new ArgumentException("Invalid observationId: " + attachment.observation_id.ToString()); } t_site site = context.t_site.Find(observation.site_id); if (site == null) { throw new ArgumentException("Invalid siteId: " + observation.site_id.ToString()); } t_indicator indicator = context.t_indicator.Find(observation.indicator_id); if (indicator == null) { throw new ArgumentException("Invalid indicatorId: " + observation.indicator_id.ToString()); } return(View("Record", (new Observation(indicator, site, observation.begin_date)))); //RedirectToAction("Record", (new Observation(observation.site_id, site, observation.begin_date))); //return RedirectToAction("Record", new { indicatorId = observation.indicator_id, siteId = observation.site_id, beginDate = observation.begin_date }); //return Record(observation.indicator_id, observation.site_id, observation.begin_date); } }
public JsonResult ApproveAttachment(int attachmentId, bool approve) { using (Entity context = new Entity()) { try { t_observation_attachment attachment = context.t_observation_attachment.Find(attachmentId); if (attachment == null) { throw new ArgumentException("Invalid attachmentId: " + attachmentId.ToString()); } attachment.active = approve; attachment.updatedby_userid = CurrentUser.Id; attachment.updated_date = DateTime.Now; context.SaveChanges(); context.Entry(attachment).Reference(n => n.updatedby).Load(); return(Json(new { success = true, Active = attachment.active, UpdatedBy = attachment.updatedby.full_name, UpdatedOn = attachment.updated_date.Value.ToString("d") })); } catch (Exception ex) { return(GetJsonResult(ex)); } } }
public Request(t_observation_attachment entity) : this(entity, false) { ObjectType = RequestObjectType.Attachment; ObjectId = entity.observation_attachment_id; Name = entity.attachment_file_name; Status = SetStatus(entity.active); }
public ObservationAttachment(t_observation_attachment attachment) { AttachmentId = attachment.observation_attachment_id; ObservationId = attachment.observation_id; FileName = attachment.attachment_file_name; FileSize = attachment.attachment.Length; Active = attachment.active; CreatedByUserId = attachment.createdby_userid; CreatedOn = attachment.created_date; UpdatedByUserId = attachment.updatedby_userid; UpdatedOn = attachment.updated_date; }
public ActionResult DownloadAttachmentFile(int attachmentId) { using (Entity context = new Entity()) { t_observation_attachment attachment = context.t_observation_attachment.Find(attachmentId); if (attachment == null) { return(new HttpNotFoundResult(String.Format("attachmentId: {0}", attachmentId))); } else { return(File(attachment.attachment, "application/octet-stream", attachment.attachment_file_name)); } } }
public JsonResult DeleteAttachment(int attachmentId) { using (Entity context = new Entity()) { try { t_observation_attachment attachment = context.t_observation_attachment.Find(attachmentId); context.t_observation_attachment.Remove(attachment); context.SaveChanges(); return(Json(new { success = true })); } catch (Exception ex) { return(GetJsonResult(ex)); } } }
private int?UpsertAttachment(dynamic model) { // Offline attachments are always treated as new attachments. (We don't // sync existing attachments to localStorage because of storage limitations). var base64 = (string)model.Attachment; var bytes = Convert.FromBase64String(base64.Substring(base64.IndexOf(',') + 1)); t_observation_attachment entity = new t_observation_attachment() { observation_id = model.ObservationId, attachment = bytes, attachment_file_name = model.FileName, active = false, createdby_userid = CurrentUserId, created_date = Convert.ToDateTime(model.CreatedOn) }; Context.t_observation_attachment.Add(entity); Context.SaveChanges(); return(entity.observation_attachment_id); }
public JsonResult AddAttachment([Bind(Exclude = "FileBytes")] ObservationAttachment model, HttpPostedFileBase fileBytes) { using (Entity context = new Entity()) { try { t_observation_attachment attachment = new t_observation_attachment(); attachment.observation_id = model.ObservationId; attachment.attachment_file_name = model.FileName; byte[] file = new byte[fileBytes.ContentLength]; int result = fileBytes.InputStream.Read(file, 0, fileBytes.ContentLength); attachment.attachment = file; attachment.createdby_userid = CurrentUser.Id; attachment.created_date = DateTime.Now; context.t_observation_attachment.Add(attachment); context.SaveChanges(); context.Entry(attachment).Reference(n => n.createdby).Load(); return(Json(new { success = true, AttachmentId = attachment.observation_attachment_id, ObservationId = attachment.observation_id, FileName = attachment.attachment_file_name, FileSize = attachment.attachment.Length, Approved = attachment.active, CreatedBy = attachment.createdby.full_name, CreatedOn = attachment.created_date.ToString("d") })); } catch (Exception ex) { return(GetJsonResult(ex)); } } }