Пример #1
0
 public int UpdateApplicantPhoto(ApplicantPhoto photo)
 {
     using (var entities = new atmEntities())
     {
         var exist = (from a in entities.tblApplicantPhotoes where a.Id == photo.Id select a).SingleOrDefault();
         if (null != exist)
         {
             exist.ApplicantId = photo.ApplicantId;
             exist.LastModifiedBy = photo.LastModifiedBy;
             exist.LastModifiedDt = photo.LastModifiedDate;
             exist.Photo = photo.Photo;
             exist.PhotoExt = photo.PhotoExt;
             entities.SaveChanges();
             return exist.Id;
         }
     }
     return 0;
 }
Пример #2
0
 public ApplicantPhoto GetPhoto(int applicantid)
 {
     if (applicantid != 0)
     {
         using (var entities = new atmEntities())
         {
             var exist = (from a in entities.tblApplicantPhotoes where a.ApplicantId == applicantid select a).SingleOrDefault();
             if (null != exist)
             {
                 var p = new ApplicantPhoto
                 {
                     ApplicantId = exist.ApplicantId,
                     CreatedBy = exist.CreatedBy,
                     CreatedDate = exist.CreatedDt,
                     Id = exist.Id,
                     LastModifiedBy = exist.LastModifiedBy,
                     LastModifiedDate = exist.LastModifiedDt,
                     Photo = exist.Photo,
                     PhotoExt = exist.PhotoExt
                 };
                 return p;
             }
         }
     }
     return null;
 }
Пример #3
0
 public int SaveApplicantPhoto(ApplicantPhoto photo)
 {
     using (var entities = new atmEntities())
     {
         var exist = (from a in entities.tblApplicantPhotoes where a.ApplicantId == photo.ApplicantId select a).SingleOrDefault();
         if (null != exist)
         {
             photo.Id = exist.Id;
             UpdateApplicantPhoto(photo);
         }
         else
         {
             var p = new tblApplicantPhoto
             {
                 ApplicantId = photo.ApplicantId,
                 CreatedBy = photo.CreatedBy,
                 CreatedDt = photo.CreatedDate,
                 Photo = photo.Photo,
                 PhotoExt = photo.PhotoExt
             };
             entities.tblApplicantPhotoes.Add(p);
             if (entities.SaveChanges() > 0)
                 return p.Id;
         }
     }
     return 0;
 }
Пример #4
0
        public ActionResult Upload()
        {
            var uploadtype = Request.Form["uploadtype"];
            var applicantid = Request.Form["applicantid"];
            foreach (string fileu in Request.Files)
            {
                var hpf = Request.Files[fileu];
                if (hpf.ContentLength != 0 && hpf.FileName != null)
                {
                    var ext = Path.GetExtension(hpf.FileName).ToLower();

                    try
                    {
                        if (uploadtype == "LETTER")
                        {
                            if (hpf.ContentLength > 1000000)
                                return Json(new { Ok = false, message = "Muat naik tidak berjaya. Saiz fail melebihi saiz yang dibenarkan (500KB)", item = new object() }, JsonRequestBehavior.AllowGet);

                            if (applicantid != null)
                            {
                                var path = ConfigurationManager.AppSettings["SuppDocFolder"];
                                var appid = 0;
                                int.TryParse(applicantid, out appid);
                                var applicant = ObjectBuilder.GetObject<IApplicantPersistence>("ApplicantPersistence").GetApplicant(appid);
                                if (applicant != null)
                                {
                                    var guid = Guid.NewGuid().ToString();
                                    applicant.OriginalPelepasanDocument = hpf.FileName;
                                    applicant.PelepasanDocument = guid + ext;
                                    hpf.SaveAs(Path.Combine(System.Web.HttpContext.Current.Server.MapPath(@"~/SuppDoc"), (guid + ext)));
                                    applicant.Save();
                                    //hpf.SaveAs(savedFileName);
                                    return Json(new { OK = true, message = "Muatnaik Berjaya", item = JsonConvert.SerializeObject(new { PelepasanDocument = applicant.PelepasanDocument, OriginalPelepasanDocument = applicant.OriginalPelepasanDocument }) }, JsonRequestBehavior.AllowGet);

                                }
                            }
                        }

                        if (uploadtype == "PROFILE")
                        {
                            if (hpf.ContentLength > 500000)
                                return Json(new { Ok = false, message = "Muat naik tidak berjaya. Saiz fail melebihi saiz yang dibenarkan (500KB)", item = new object() }, JsonRequestBehavior.AllowGet);

                            if (ext == ".jpg" || ext == ".jpeg" || ext == ".png" || ext == ".gif" || ext == ".bmp")
                            {
                                var fileBytes = new byte[hpf.ContentLength];
                                var stream = hpf.InputStream.Read(fileBytes, 0, hpf.ContentLength);

                                if (applicantid != null)
                                {
                                    var appid = 0;
                                    int.TryParse(applicantid, out appid);
                                    var applicant = ObjectBuilder.GetObject<IApplicantPersistence>("ApplicantPersistence").GetApplicant(appid);
                                    if (applicant != null)
                                    {
                                        // check where there already exist the photo or not
                                        var existphoto = ObjectBuilder.GetObject<IApplicantPersistence>("ApplicantPersistence").GetPhoto(applicant.ApplicantId);
                                        if (null != existphoto && existphoto.Id != 0)
                                        {
                                            var appphoto = new ApplicantPhoto
                                            {
                                                Photo = fileBytes,
                                                PhotoExt = ext,
                                                ApplicantId = applicant.ApplicantId,
                                                CreatedBy = applicant.CreatedBy,
                                                CreatedDate = DateTime.Now,
                                                Id = existphoto.Id
                                            };
                                            appphoto.Save();
                                        }
                                        else
                                        {
                                            var appphoto = new ApplicantPhoto
                                            {
                                                Photo = fileBytes,
                                                PhotoExt = ext,
                                                ApplicantId = applicant.ApplicantId,
                                                CreatedBy = applicant.CreatedBy,
                                                CreatedDate = DateTime.Now
                                            };
                                            appphoto.Save();
                                        }

                                    }
                                }
                            }
                            else
                                return Json(new { OK = false, message = "Muatnaik tidak berjaya. Jenis fail tidak dibenarkan", item = new object() }, JsonRequestBehavior.AllowGet);

                            //hpf.SaveAs(savedFileName);
                            return Json(new { OK = true, message = "Muatnaik Berjaya", item = JsonConvert.SerializeObject("") }, JsonRequestBehavior.AllowGet);
                        }

                        if (uploadtype == "ACQDOCFS")
                        {
                            var acquisitionid = Request.Form["acquisitionid"];
                            if (hpf.ContentLength > 5000000)
                                return Json(new { Ok = false, message = "Muat naik tidak berjaya. Saiz fail melebihi saiz yang dibenarkan (5MB)", item = new object() }, JsonRequestBehavior.AllowGet);

                            if (acquisitionid != null)
                            {
                                var path = ConfigurationManager.AppSettings["SuppDocFolder"];
                                var appid = 0;
                                int.TryParse(acquisitionid, out appid);
                                if (appid != 0)
                                {
                                    var acq = ObjectBuilder.GetObject<IAcquisitionPersistence>("AcquisitionPersistence").GetAcquisition(appid);
                                    if (null != acq)
                                    {
                                        var guid = Guid.NewGuid().ToString();
                                        var filename = guid + ext;
                                        hpf.SaveAs(Path.Combine(System.Web.HttpContext.Current.Server.MapPath(@"~/SuppDoc"), (filename)));
                                        acq.FinalSupportingDocumentOriginal = hpf.FileName;
                                        acq.FinalSupportingDocument = filename;
                                        acq.Save();
                                        return Json(new { OK = true, message = "Muatnaik Berjaya", item = JsonConvert.SerializeObject(new { DocumentName = hpf.FileName }) }, JsonRequestBehavior.AllowGet);
                                    }
                                }
                            }
                        }

                        if (uploadtype == "ACQDOCRD")
                        {
                            var acquisitionid = Request.Form["acquisitionid"];
                            if (hpf.ContentLength > 5000000)
                                return Json(new { Ok = false, message = "Muat naik tidak berjaya. Saiz fail melebihi saiz yang dibenarkan (5MB)", item = new object() }, JsonRequestBehavior.AllowGet);

                            if (acquisitionid != null)
                            {
                                var path = ConfigurationManager.AppSettings["SuppDocFolder"];
                                var appid = 0;
                                int.TryParse(acquisitionid, out appid);
                                if (appid != 0)
                                {
                                    var acq = ObjectBuilder.GetObject<IAcquisitionPersistence>("AcquisitionPersistence").GetAcquisition(appid);
                                    if (null != acq)
                                    {
                                        var guid = Guid.NewGuid().ToString();
                                        var filename = guid + ext;
                                        hpf.SaveAs(Path.Combine(System.Web.HttpContext.Current.Server.MapPath(@"~/SuppDoc"), (filename)));
                                        acq.ReportDutySupportingDocumentOriginal = hpf.FileName;
                                        acq.ReportDutySupportingDocument = filename;
                                        acq.Save();
                                        return Json(new { OK = true, message = "Muatnaik Berjaya", item = JsonConvert.SerializeObject(new { DocumentName = hpf.FileName }) }, JsonRequestBehavior.AllowGet);
                                    }
                                }
                            }
                        }

                        if (uploadtype == "ACQDOCIS")
                        {
                            var acquisitionid = Request.Form["acquisitionid"];
                            if (hpf.ContentLength > 5000000)
                                return Json(new { Ok = false, message = "Muat naik tidak berjaya. Saiz fail melebihi saiz yang dibenarkan (5MB)", item = new object() }, JsonRequestBehavior.AllowGet);

                            if (acquisitionid != null)
                            {
                                var path = ConfigurationManager.AppSettings["SuppDocFolder"];
                                var appid = 0;
                                int.TryParse(acquisitionid, out appid);
                                if (appid != 0)
                                {
                                    var acq = ObjectBuilder.GetObject<IAcquisitionPersistence>("AcquisitionPersistence").GetAcquisition(appid);
                                    if (null != acq)
                                    {
                                        var guid = Guid.NewGuid().ToString();
                                        var filename = guid + ext;
                                        hpf.SaveAs(Path.Combine(System.Web.HttpContext.Current.Server.MapPath(@"~/SuppDoc"), (filename)));
                                        acq.FirstSupportingDocumentOriginal = hpf.FileName;
                                        acq.FirstSupportingDocument = filename;
                                        acq.Save();
                                        return Json(new { OK = true, message = "Muatnaik Berjaya", item = JsonConvert.SerializeObject(new { DocumentName = hpf.FileName }) }, JsonRequestBehavior.AllowGet);
                                    }
                                }
                            }
                        }

                    }
                    catch (Exception exc)
                    {
                        throw exc;
                    }
                }
            }
            // Return JSON
            return Json(new { OK = false, message = "Tidak Berjaya", item = new object() }, JsonRequestBehavior.AllowGet);
        }