示例#1
0
 public ActionResult DeleteAttachment(PtoSMessageHeaderModel Model)
 {
     try
     {
         tblParentToSchollMessageAttachment Tble = Connection.tblParentToSchollMessageAttachments.Find(
             Model.SeqNo);
         string path = Tble.AttachementPath;
         Connection.tblParentToSchollMessageAttachments.Remove(Tble);
         Connection.SaveChanges();
         System.IO.File.Delete(Server.MapPath(path));
         return(Json(Model.SeqNo, JsonRequestBehavior.AllowGet));
     }
     catch
     {
         return(Json("Error", JsonRequestBehavior.AllowGet));
     }
 }
示例#2
0
        public JsonResult AttachmentUpload(PtoSMessageHeaderModel Model)
        {
            try
            {
                var  file         = Model.Attachment_File;
                long AttachmentId = 0;
                tblParentToSchollMessageAttachment Attachmentfile = new tblParentToSchollMessageAttachment();
                if (file != null)
                {
                    var Atid = Connection.tblParameters.Where(x => x.ParameterId == "PSMAS").Select(
                        x => x.ParameterValue).SingleOrDefault();
                    AttachmentId = Convert.ToInt64(Atid);
                    long Next             = AttachmentId + 1;
                    var  Attachement_Path = "/Attachments/PtS/" + DateTime.Now.ToString("yyyy") + "/" +
                                            DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd") + "/" + Model.MessageId;
                    var fileName  = Path.GetFileName(file.FileName);
                    var extention = Path.GetExtension(file.FileName);
                    Attachmentfile.AttachementName = file.FileName;
                    Attachmentfile.AttachementPath = Attachement_Path + "/" + file.FileName;
                    Attachmentfile.MessageId       = Model.MessageId;
                    Attachmentfile.SeqNo           = AttachmentId;

                    Connection.tblParentToSchollMessageAttachments.Add(Attachmentfile);
                    Connection.SaveChanges();

                    tblParameter TCtable = Connection.tblParameters.SingleOrDefault(
                        x => x.ParameterId == "PSMAS");
                    TCtable.ParameterValue = Next.ToString();
                    Connection.SaveChanges();
                    if (!Directory.Exists(Server.MapPath(Attachement_Path)))
                    {
                        Directory.CreateDirectory(Server.MapPath(Attachement_Path));
                    }
                    file.SaveAs(Server.MapPath(Attachement_Path + "/" + file.FileName));
                }
                var result = new { FileName = file.FileName, SeqNo = AttachmentId };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception Ex)
            {
                Errorlog.ErrorManager.LogError("AttachmentUpload(PtoSMessageHeaderModel Model) @PSMessageController", Ex);
                var result = new { FileName = "Error", SeqNo = "Error" };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }