public void Delete(FileAttachmentModel entity, Guid AttachGroupID)
        {
            objAttachment = new CRM_AttachmentRepository();

            if (objAttachment.GetAll(a => a.AttachGroupID == AttachGroupID && a.AttachFileID == entity.AttachFileID).Count() > 0)
            {
                CRM_Attachments deleteRecord = objAttachment.GetSingle(a => a.AttachGroupID == AttachGroupID && a.AttachFileID == entity.AttachFileID);

                objAttachment.Delete(deleteRecord);
            }
        }
        public FileAttachmentModel getAttachInfoByID(Guid attachGroupID, Guid attachFileID)
        {
            objAttachment = new CRM_AttachmentRepository();

            Mapper.CreateMap<CRM_Attachments, FileAttachmentModel>();
            objAttachment = new CRM_AttachmentRepository();

            CRM_Attachments objEntity = objAttachment.GetSingle(a => a.AttachGroupID == attachGroupID && a.AttachFileID == attachFileID);

            FileAttachmentModel objResult = new FileAttachmentModel();

            objResult = Mapper.Map(objEntity, objResult);

            return objResult;
        }
        public void Save(FileAttachmentModel entity, Guid AttachGroupID, string User)
        {
            objAttachment = new CRM_AttachmentRepository();

            Mapper.CreateMap<FileAttachmentModel, CRM_Attachments>();

            CRM_Attachments objSave = new CRM_Attachments();

            objSave = Mapper.Map(entity, objSave);

            objSave.AttachGroupID = AttachGroupID;
            objSave.CreatedBy = User;
            objSave.CreatedDate = DateTime.Now;

            objAttachment.Add(objSave);
        }
        public ActionResult Index(string qqfile)
        {
            if (Session["Attachment"] == null)
            {
                FAList = null;
            }
            else
            {
                FAList = (List<FileAttachmentModel>)Session["Attachment"];
            }

            FAList = getList();

            var path = Server.MapPath("~/UploadFiles");
            var file = string.Empty;
            var filenam = DateTime.Now.ToString("yyyyMMddhhmmss") + Request["qqfile"];
            var filename = filenam.Replace(" ", "_");

            FileAttachmentModel FAM = new FileAttachmentModel();
            FAM.AttachFileID = Guid.NewGuid();
            FAM.ActualFileName = qqfile.ToString();
            FAM.ServerFileName = filename;
            FAM.URL = Path.Combine(path, filename.ToString());
            FAM.Type = GetContentType(qqfile);

            try
            {
                var stream = Request.InputStream;
                if (String.IsNullOrEmpty(Request["qqfile"]))
                {
                    // IE
                    HttpPostedFileBase postedFile = Request.Files[0];

                    stream = postedFile.InputStream;
                    //file = Path.Combine(path, System.IO.Path.GetFileName(Request.Files[0].FileName));
                    file = Path.Combine(path, filename.ToString());
                }
                else
                {
                    //Webkit, Mozilla
                    //file = Path.Combine(path, qqfile);

                    file = Path.Combine(path, filename.ToString());
                }

                var buffer = new byte[stream.Length];
                stream.Read(buffer, 0, buffer.Length);
                System.IO.File.WriteAllBytes(file, buffer);

                FAM.Size = DesignUtils.getFileSize(FAM.URL);
                FAList.Add(FAM);

                Session["Attachment"] = FAList;
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = ex.Message }, "application/json");
            }

            return Json(new { success = true, filename }, "text/html");
        }