// GET: members/Details/5
        public IActionResult Details(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            member member = _context.member.Single(m => m.id == new Guid(id));

            if (member == null)
            {
                return(NotFound());
            }

            if (!String.IsNullOrEmpty(member.mem_photo))
            {
                pic_image m = _context.pic_image.Single(i => i.image_code == member.mem_photo);
                ViewBag.memPhoto = member.mem_photo + m.ref_doc_type;
            }

            if (!String.IsNullOrEmpty(member.cid_card_pic))
            {
                pic_image c = _context.pic_image.Single(i => i.image_code == member.cid_card_pic);
                ViewBag.cidCardPhoto = member.cid_card_pic + c.ref_doc_type;
            }

            prepareViewBag();
            return(View(member));
        }
Exemple #2
0
        public IActionResult ChangeVideoDesc(string imageCode, string imageDesc)
        {
            pic_image pi = _context.pic_image.SingleOrDefault(p => p.image_code == imageCode);

            pi.image_desc = imageDesc;
            _context.Update(pi);

            _context.SaveChanges();
            return(Json(new { result = "success", imageDesc = imageDesc }));
        }
        public IActionResult Edit(string id, [Bind("member_code,birthdate,building,cid_card,cid_card_pic,cid_type,country_code,current_age,district_code,email,fax,floor,fname,h_no,id,lane,latitude,lname,longitude,lot_no,marry_status,mem_group_code,mem_photo,mem_type_code,mlevel_code,mobile,mstatus_code,nationality,parent_code,place_name,province_code,religion,room,rowversion,sex,social_app_data,street,subdistrict_code,tel,texta_address,textb_address,textc_address,village,x_log,x_note,x_status,zip_code,zone")] member member)
        {
            if (ModelState.IsValid)
            {
                member.x_status = "Y";

                if ((!string.IsNullOrEmpty(member.mem_photo)) && (member.mem_photo.Substring(0, 1) != "M"))
                {
                    var       fileName = member.mem_photo.Substring(9);
                    pic_image m        = new pic_image();
                    m.image_code   = "M" + DateTime.Now.ToString("yyMMddhhmmss");
                    m.x_status     = "Y";
                    m.image_name   = fileName.Substring(0, (fileName.Length <= 50 ? fileName.Length : 50));
                    m.ref_doc_type = Path.GetExtension(fileName);
                    fileName       = m.image_code + m.ref_doc_type;
                    _context.pic_image.Add(m);
                    _context.SaveChanges();

                    var s = Path.Combine(Path.Combine(_env.WebRootPath, _configuration.GetSection("Paths").GetSection("images_upload").Value), member.mem_photo);
                    var d = Path.Combine(Path.Combine(_env.WebRootPath, _configuration.GetSection("Paths").GetSection("images_member").Value), fileName);
                    System.IO.File.Copy(s, d, true);
                    System.IO.File.Delete(s);
                    clearImageUpload();

                    member.mem_photo = m.image_code;
                }
                if ((!string.IsNullOrEmpty(member.cid_card_pic)) && (member.cid_card_pic.Substring(0, 1) != "C"))
                {
                    var       fileName  = member.cid_card_pic.Substring(9);
                    pic_image pic_image = new pic_image();
                    pic_image.image_code   = "C" + DateTime.Now.ToString("yyMMddhhmmss");
                    pic_image.x_status     = "Y";
                    pic_image.image_name   = fileName.Substring(0, (fileName.Length <= 50 ? fileName.Length : 50));
                    pic_image.ref_doc_type = Path.GetExtension(fileName);
                    fileName = pic_image.image_code + pic_image.ref_doc_type;
                    _context.pic_image.Add(pic_image);
                    _context.SaveChanges();

                    var s = Path.Combine(Path.Combine(_env.WebRootPath, _configuration.GetSection("Paths").GetSection("images_upload").Value), member.cid_card_pic);
                    var d = Path.Combine(Path.Combine(_env.WebRootPath, _configuration.GetSection("Paths").GetSection("images_member").Value), fileName);
                    System.IO.File.Copy(s, d, true);
                    System.IO.File.Delete(s);
                    clearImageUpload();

                    member.cid_card_pic = pic_image.image_code;
                }


                _context.Update(member);
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            prepareViewBag();
            return(View(member));
        }
        public IActionResult Edit(member member)
        {
            if (ModelState.IsValid)
            {
                member.x_status = "Y";

                if ((!string.IsNullOrEmpty(member.mem_photo)) && (member.mem_photo.Substring(0, 1) != "M"))
                {
                    var       fileName = member.mem_photo.Substring(9);
                    pic_image m        = new pic_image();
                    m.image_code   = "M" + DateTime.Now.ToString("yyMMddhhmmss");
                    m.x_status     = "Y";
                    m.image_name   = fileName.Substring(0, (fileName.Length <= 50 ? fileName.Length : 50));
                    m.ref_doc_type = Path.GetExtension(fileName);
                    fileName       = m.image_code + m.ref_doc_type;
                    _context.pic_image.Add(m);
                    _context.SaveChanges();

                    var s = Path.Combine(Path.Combine(_env.WebRootPath, _configuration.GetSection("Paths").GetSection("images_upload").Value), member.mem_photo);
                    var d = Path.Combine(Path.Combine(_env.WebRootPath, _configuration.GetSection("Paths").GetSection("images_member").Value), fileName);
                    System.IO.File.Copy(s, d, true);
                    System.IO.File.Delete(s);
                    clearImageUpload();

                    member.mem_photo = m.image_code;
                }
                if ((!string.IsNullOrEmpty(member.cid_card_pic)) && (member.cid_card_pic.Substring(0, 1) != "C"))
                {
                    var       fileName  = member.cid_card_pic.Substring(9);
                    pic_image pic_image = new pic_image();
                    pic_image.image_code   = "C" + DateTime.Now.ToString("yyMMddhhmmss");
                    pic_image.x_status     = "Y";
                    pic_image.image_name   = fileName.Substring(0, (fileName.Length <= 50 ? fileName.Length : 50));
                    pic_image.ref_doc_type = Path.GetExtension(fileName);
                    fileName = pic_image.image_code + pic_image.ref_doc_type;
                    _context.pic_image.Add(pic_image);
                    _context.SaveChanges();

                    var s = Path.Combine(Path.Combine(_env.WebRootPath, _configuration.GetSection("Paths").GetSection("images_upload").Value), member.cid_card_pic);
                    var d = Path.Combine(Path.Combine(_env.WebRootPath, _configuration.GetSection("Paths").GetSection("images_member").Value), fileName);
                    System.IO.File.Copy(s, d, true);
                    System.IO.File.Delete(s);
                    clearImageUpload();

                    member.cid_card_pic = pic_image.image_code;
                }


                _context.Update(member);
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            prepareViewBag();
            return(View(member));
        }
Exemple #5
0
        public IActionResult DeleteVideo(string albumCode, string imageCode)
        {
            pic_image pi = _context.pic_image.SingleOrDefault(p => p.image_code == imageCode);

            _context.Remove(pi);
            _context.SaveChanges();

            var uploads = Path.Combine(_env.WebRootPath, _configuration.GetSection("Paths").GetSection("images_album").Value);

            uploads = Path.Combine(uploads, albumCode);
            uploads = Path.Combine(uploads, imageCode);
            System.IO.File.Delete(uploads);

            return(Json(new { result = "success", imageCode = imageCode }));
        }
Exemple #6
0
        public IActionResult UploadAlbumVideo(ICollection <IFormFile> file, string albumCode)
        {
            var uploads = Path.Combine(_env.WebRootPath, _configuration.GetSection("Paths").GetSection("images_upload").Value);

            uploads = Path.Combine(uploads, albumCode);
            Directory.CreateDirectory(uploads);

            var fileName = ""; var fileExt = ""; var imageCode = "";

            foreach (var fi in file)
            {
                if (fi.Length > 0)
                {
                    fileName += Microsoft.Net.Http.Headers.ContentDispositionHeaderValue.Parse(fi.ContentDisposition).FileName.Trim('"');
                    fileExt   = Path.GetExtension(fileName);
                    fileName  = Path.GetFileNameWithoutExtension(fileName);
                    fileName  = fileName.Substring(0, (fileName.Length <= (50 - fileExt.Length) ? fileName.Length : (50 - fileExt.Length))) + fileExt;

                    imageCode = "A" + DateTime.Now.ToString("yyMMddhhmmssfffffff") + fileExt;
                    using (var SourceStream = fi.OpenReadStream())
                    {
                        using (var fileStream = new FileStream(Path.Combine(uploads, imageCode), FileMode.Create))
                        {
                            SourceStream.CopyTo(fileStream);

                            pic_image pic_image = new pic_image();
                            pic_image.image_code   = imageCode;
                            pic_image.x_status     = "N";
                            pic_image.image_name   = fileName;
                            pic_image.image_desc   = fileName;
                            pic_image.ref_doc_type = "album";
                            pic_image.ref_doc_code = albumCode;
                            _context.pic_image.Add(pic_image);
                            _context.SaveChanges();
                        }
                    }
                }
            }
            return(Json(new { result = "success", uploads = uploads, fileName = fileName }));
        }
        // GET: members/Edit/5
        public IActionResult Edit(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            member member = _context.member.Single(m => m.id == new Guid(id));

            if (member == null)
            {
                return(NotFound());
            }

            if (!String.IsNullOrEmpty(member.mem_photo))
            {
                pic_image m = _context.pic_image.Single(i => i.image_code == member.mem_photo);
                ViewBag.memPhoto = member.mem_photo + m.ref_doc_type;
            }

            if (!String.IsNullOrEmpty(member.cid_card_pic))
            {
                pic_image c = _context.pic_image.Single(i => i.image_code == member.cid_card_pic);
                ViewBag.cidCardPhoto = member.cid_card_pic + c.ref_doc_type;
            }

            ViewBag.memberId = id;

            //For dropdown province; we need to manually assign it, then prepare viewbag for javascript
            ViewBag.zipCode         = member.zip_code;
            ViewBag.subdistrictCode = member.subdistrict_code;
            ViewBag.districtCode    = member.district_code;
            //ViewBag.provinceCode = member.province_code;



            prepareViewBag();
            clearImageUpload();
            return(View(member));
        }
Exemple #8
0
        public IActionResult Create(string birthdate, string cid_card, string email, string fname, string lname, string mobile, string mem_photo, string cid_card_pic)
        {
            DateTime bd = Convert.ToDateTime(birthdate);

            //birthdate = (bd.Year).ToString() + bd.Month.ToString() + bd.Day.ToString();
            birthdate = (bd.Year).ToString() + bd.ToString("MMdd");
            string password = cid_card.Substring(cid_card.Length - 4);

            try
            {
                if ((!string.IsNullOrEmpty(mem_photo)) && (mem_photo.Substring(0, 1) != "M"))
                {
                    var       fileName = mem_photo.Substring(9);
                    var       fileExt  = Path.GetExtension(fileName);
                    pic_image m        = new pic_image();
                    m.image_code = "M" + DateTime.Now.ToString("yyMMddhhmmssfffffff") + fileExt;
                    m.x_status   = "Y";
                    m.image_name = fileName;

                    m.ref_doc_type = "member";
                    m.ref_doc_code = cid_card; //member_code;
                    fileName       = m.image_code;
                    _context.pic_image.Add(m);
                    _context.SaveChanges();

                    var s = Path.Combine(Path.Combine(_env.WebRootPath, _configuration.GetSection("Paths").GetSection("images_upload").Value), mem_photo);
                    var d = Path.Combine(Path.Combine(_env.WebRootPath, _configuration.GetSection("Paths").GetSection("images_member").Value), fileName);
                    System.IO.File.Copy(s, d, true);
                    System.IO.File.Delete(s);
                    //clearImageUpload();

                    mem_photo = m.image_code;
                }
                if ((!string.IsNullOrEmpty(cid_card_pic)) && (cid_card_pic.Substring(0, 1) != "C"))
                {
                    var       fileName  = cid_card_pic.Substring(9);
                    var       fileExt   = Path.GetExtension(fileName);
                    pic_image pic_image = new pic_image();
                    pic_image.image_code   = "C" + DateTime.Now.ToString("yyMMddhhmmssfffffff") + fileExt;
                    pic_image.x_status     = "Y";
                    pic_image.image_name   = fileName;
                    pic_image.ref_doc_type = "cidcard";
                    pic_image.ref_doc_code = cid_card; //member_code;
                    fileName = pic_image.image_code;
                    _context.pic_image.Add(pic_image);
                    _context.SaveChanges();

                    var s = Path.Combine(Path.Combine(_env.WebRootPath, _configuration.GetSection("Paths").GetSection("images_upload").Value), cid_card_pic);
                    var d = Path.Combine(Path.Combine(_env.WebRootPath, _configuration.GetSection("Paths").GetSection("images_member").Value), fileName);
                    System.IO.File.Copy(s, d, true);
                    System.IO.File.Delete(s);
                    //clearImageUpload();

                    cid_card_pic = pic_image.image_code;
                }
                _context.Database.ExecuteSqlCommand("INSERT INTO member (member_code,cid_card,birthdate,fname,lname,mobile,email,x_status,mem_password,mem_photo,cid_card_pic) VALUES ('" + cid_card + "','" + cid_card + "','" + birthdate + "',N'" + fname + "',N'" + lname + "','" + mobile + "','" + email + "','Y','" + password + "','" + mem_photo + "','" + cid_card_pic + "')");
                SendEmail(email, cid_card, password);
            }
            catch (SqlException ex)
            {
                var errno = ex.Number; var msg = "";
                if (errno == 2627) //Violation of primary key. Handle Exception
                {
                    msg = "duplicate";
                }
                return(Json(new { result = "fail", error_code = errno, error_message = msg }));
            }
            catch (Exception ex)
            {
                var errno = ex.HResult; var msg = "";
                if (ex.InnerException.Message.IndexOf("PRIMARY KEY") != -1)
                {
                    msg = "duplicate";
                }
                return(Json(new { result = "fail", error_code = errno, error_message = msg }));
            }

            return(Json(new { result = "success" }));
        }
        //public async Task<IActionResult> Create(string birthdate, string cid_card, string email, string fname, string lname, string mobile, string mem_photo, string cid_card_pic)
        public IActionResult RegisterMember(string birthdate, string cid_card, string email, string fname, string lname, string mobile, string mem_photo, string cid_card_pic)
        {
            DateTime bd = Convert.ToDateTime(birthdate);

            //birthdate = (bd.Year).ToString() + bd.Month.ToString() + bd.Day.ToString();
            birthdate = (bd.Year).ToString() + bd.ToString("MMdd");
            string password    = cid_card.Substring(cid_card.Length - 4);
            string passwordMD5 = Utils.EncodeMd5(password);

            try
            {
                if ((!string.IsNullOrEmpty(mem_photo)) && (mem_photo.Substring(0, 1) != "M"))
                {
                    var fileName = mem_photo.Substring(9);
                    var fileExt  = Path.GetExtension(fileName);

                    var s = Path.Combine(Path.Combine(_env.WebRootPath, _configuration.GetSection("Paths").GetSection("images_upload").Value), mem_photo);
                    //var d = Path.Combine(Path.Combine(_env.WebRootPath, _configuration.GetSection("Paths").GetSection("images_member").Value), fileName);
                    //System.IO.File.Copy(s, d, true);
                    //System.IO.File.Delete(s);

                    pic_image m = new pic_image();
                    m.image_code = "M" + DateTime.Now.ToString("yyMMddhhmmssfffffff") + fileExt;
                    m.x_status   = "Y";
                    m.image_name = fileName;
                    string base64String = "";
                    using (System.Drawing.Image image = System.Drawing.Image.FromFile(s))
                    {
                        using (MemoryStream mem = new MemoryStream())
                        {
                            image.Save(mem, image.RawFormat);
                            byte[] imageBytes = mem.ToArray();
                            base64String = Convert.ToBase64String(imageBytes);
                        }
                    }
                    m.image_file = base64String;

                    m.ref_doc_type = "member";
                    m.ref_doc_code = cid_card; //member_code;
                    fileName       = m.image_code;
                    _context.pic_image.Add(m);
                    _context.SaveChanges();

                    System.IO.File.Delete(s);
                    //clearImageUpload();

                    mem_photo = m.image_code;
                }
                if ((!string.IsNullOrEmpty(cid_card_pic)) && (cid_card_pic.Substring(0, 1) != "C"))
                {
                    var fileName = cid_card_pic.Substring(9);
                    var fileExt  = Path.GetExtension(fileName);

                    var s = Path.Combine(Path.Combine(_env.WebRootPath, _configuration.GetSection("Paths").GetSection("images_upload").Value), cid_card_pic);
                    //var d = Path.Combine(Path.Combine(_env.WebRootPath, _configuration.GetSection("Paths").GetSection("images_member").Value), fileName);
                    //System.IO.File.Copy(s, d, true);
                    //System.IO.File.Delete(s);

                    pic_image pic_image = new pic_image();
                    pic_image.image_code = "C" + DateTime.Now.ToString("yyMMddhhmmssfffffff") + fileExt;
                    pic_image.x_status   = "Y";
                    pic_image.image_name = fileName;
                    string base64String = "";
                    using (System.Drawing.Image image = System.Drawing.Image.FromFile(s))
                    {
                        using (MemoryStream mem = new MemoryStream())
                        {
                            image.Save(mem, image.RawFormat);
                            byte[] imageBytes = mem.ToArray();
                            base64String = Convert.ToBase64String(imageBytes);
                        }
                    }
                    pic_image.image_file   = base64String;
                    pic_image.ref_doc_type = "cidcard";
                    pic_image.ref_doc_code = cid_card; //member_code;
                    fileName = pic_image.image_code;
                    _context.pic_image.Add(pic_image);
                    _context.SaveChanges();

                    System.IO.File.Delete(s);
                    //clearImageUpload();

                    cid_card_pic = pic_image.image_code;
                }
                _context.Database.ExecuteSqlCommand("INSERT INTO member (member_code,cid_card,birthdate,fname,lname,mobile,email,x_status,mem_username,mem_password,mem_role_id,mem_photo,cid_card_pic) VALUES ('" + cid_card + "','" + cid_card + "','" + birthdate + "',N'" + fname + "',N'" + lname + "','" + mobile + "','" + email + "','Y','" + cid_card + "','" + passwordMD5 + "','17822a90-1029-454a-b4c7-f631c9ca6c7d','" + mem_photo + "','" + cid_card_pic + "')");

                var mb = _context.member.SingleOrDefault(mm => mm.member_code == cid_card);
                SecurityMemberRoles smr = new SecurityMemberRoles();
                smr.MemberId    = mb.id;
                smr.CreatedDate = DateTime.Now;
                smr.CreatedBy   = mb.id;
                smr.EditedDate  = DateTime.Now;
                smr.EditedBy    = mb.id;
                smr.x_status    = "Y";
                _scontext.Add(smr);
                _scontext.SaveChanges();

                SendEmail(email, cid_card, password);
            }
            catch (SqlException ex)
            {
                var errno = ex.Number; var msg = "";
                if (errno == 2627) //Violation of primary key. Handle Exception
                {
                    msg = "duplicate";
                }
                return(Json(new { result = "fail", error_code = errno, error_message = msg }));
            }
            catch (Exception ex)
            {
                var errno = ex.HResult; var msg = "";
                if (ex.InnerException.Message.IndexOf("PRIMARY KEY") != -1)
                {
                    msg = "duplicate";
                }
                return(Json(new { result = "fail", error_code = errno, error_message = msg }));
            }

            return(Json(new { result = "success" }));
        }