コード例 #1
0
        public IActionResult EditPersonalDetail(PersonalDetail personDetail)
        {
            if (ModelState.IsValid)
            {
                if (Request.Form.Files["profile-image"] != null)
                {
                    //saving
                    if (Request.Form.Files["profile-image"].Length > 10 * 1024 * 1024)
                    {
                        personDetail.ErrorMsg = "File is not within size limit of 10MB.";
                        return(View(personDetail));
                    }
                    string pathToFolder = Path.Combine(_env.WebRootPath, "UploadedFiles", Request.Form.Files["profile-image"].FileName);
                    var    fileStream   = new FileStream(pathToFolder, FileMode.Create);
                    Request.Form.Files["profile-image"].CopyTo(fileStream);
                    personDetail.ImageLocation = "UploadedFiles" + Request.Form.Files["profile-image"].FileName;
                }

                var personInList = PersonMemory.GetPersons().Where(x => x.PersonalDetailId == personDetail.PersonalDetailId).FirstOrDefault();

                personInList.FirstName     = personDetail.FirstName;
                personInList.Occupation    = personDetail.Occupation;
                personInList.Age           = personDetail.Age;
                personInList.Address       = personDetail.Address;
                personInList.ImageLocation = personDetail.ImageLocation;

                return(RedirectToAction("Persons"));
            }
            else
            {
                return(View(personDetail));
            }
        }
コード例 #2
0
        public IActionResult PersonalDetailsEdit(int personDetailsID)
        {
            PersonalDetails pdetail = new PersonalDetails();

            pdetail = PersonMemory.GetPersons().Where(x => x.PersonalDetailsID == personDetailsID).FirstOrDefault();
            return(View(pdetail));
        }
コード例 #3
0
        public IActionResult PersonalDetailDelete(int personDetailId)
        {
            var person = PersonMemory.GetPersons().Where(x => x.PersonalDetailId == personDetailId).FirstOrDefault();

            PersonMemory.GetPersons().Remove(person);
            return(RedirectToAction("Persons"));
        }
コード例 #4
0
        public IActionResult CreatePerson(PersonalDetail person)
        {
            if (ModelState.IsValid)
            {
                if (Request.Form.Files["profile-image"] != null)
                {
                    //saving
                    if (Request.Form.Files["profile-image"].Length > 10 * 1024 * 1024)
                    {
                        person.ErrorMsg = "File is not within size limit of 10MB.";
                        return(View(person));
                    }
                    string pathToFolder = Path.Combine(_env.WebRootPath, "UploadedFiles", Request.Form.Files["profile-image"].FileName);
                    var    fileStream   = new FileStream(pathToFolder, FileMode.Create);
                    Request.Form.Files["profile-image"].CopyTo(fileStream);
                    person.ImageLocation = pathToFolder;
                    /*person.ImageLocation = "UploadedFiles" + Request.Form.Files["profile-image"].FileName;*/
                }
                var personDetailList = PersonMemory.GetPersons();
                int personsCount     = personDetailList.Count;
                person.PersonalDetailId = ++personsCount;

                personDetailList.Add(person);
                return(RedirectToAction("Persons"));
            }

            else
            {
                return(View(person));
            }
        }
コード例 #5
0
        public ViewResult PersonalDetailEdit(int personDetailId)
        {
            PersonalDetail pdetail = new PersonalDetail();

            pdetail = PersonMemory.GetPersons().Where(x => x.PersonalDetailId == personDetailId).FirstOrDefault();
            return(View(pdetail));
        }
コード例 #6
0
        public ActionResult CretePersonDetail(PersonalDetail pd)
        {
            if (Request.Form.Files["profile-image"] != null)
            {
                //saving
                if (Request.Form.Files["profile-image"].Length > 10 * 1024 * 1024)
                {
                    pd.ErrorMsg = "File Size not valid !!";
                    return(View(pd));
                }
                string pathToFolder = Path.Combine(_env.WebRootPath, "uploadedfiles", Request.Form.Files["profile-image"].FileName);

                using (var fileStreams = new FileStream(pathToFolder, FileMode.Create))
                {
                    Request.Form.Files["profile-image"].CopyTo(fileStreams);
                    pd.ImageLocation = pathToFolder;
                    fileStreams.Flush();
                }
            }
            var persondetailList   = PersonMemory.GetPersons();
            int currentPersonCount = persondetailList.Count;

            currentPersonCount  = currentPersonCount + 1;
            pd.PersonalDetailId = currentPersonCount;
            persondetailList.Add(pd);
            return(RedirectToAction("Persons"));
        }
コード例 #7
0
        public IActionResult PersonalDetail(int personDetailId)
        {
            PersonalDetail pdetail = new PersonalDetail();

            pdetail = PersonMemory.GetPersons().Where(x => x.PersonalDetailId == personDetailId).FirstOrDefault();
            return(View(pdetail));
            //return new ObjectResult(pdetail);
        }
コード例 #8
0
        public IActionResult CreatePersonDetail(PersonalDetails pd)
        {
            var personDetailList   = PersonMemory.GetPersons();
            int currentPersonCount = personDetailList.Count;

            pd.PersonalDetailsID = ++currentPersonCount;
            personDetailList.Add(pd);
            return(RedirectToAction("PDEditor"));
        }
コード例 #9
0
        //public IActionResult DownloadFile(int personId)
        //{
        //    string downlloadPath = PersonMemory.GetPersons().Where(x => x.PersonalDetailId == personId).FirstOrDefault().ImageLocation;
        //return File()

        //}

        public FileResult DownloadFile(int personId)
        {
            string downlloadPath = PersonMemory.GetPersons().Where(x => x.PersonalDetailId == personId).FirstOrDefault().ImageLocation;
            //string[] extension = downlloadPath.Split('/');
            //string filename = extension[2].ToString();
            string pathToFolder = Path.Combine(_env.WebRootPath, downlloadPath);
            var    fileStream   = new FileStream(pathToFolder, FileMode.Open);

            return(File(fileStream, "image/jpeg", "downloadedfile.jpg"));
        }
コード例 #10
0
        public ActionResult CretePersonDetail(PersonalDetail pd)
        {
            var persondetailList   = PersonMemory.GetPersons();
            int currentPersonCount = persondetailList.Count;

            currentPersonCount  = currentPersonCount + 1;
            pd.PersonalDetailId = currentPersonCount;
            persondetailList.Add(pd);
            return(RedirectToAction("Persons"));
        }
コード例 #11
0
        public IActionResult CreatePerson(PersonalDetail person)
        {
            var personDetailList = PersonMemory.GetPersons();
            int personsCount     = personDetailList.Count;

            person.PersonalDetailId = ++personsCount;

            personDetailList.Add(person);

            return(RedirectToAction("Persons"));
        }
コード例 #12
0
        public IActionResult PersonalDetailsEdit(PersonalDetails pd)
        {
            var personInList = PersonMemory.GetPersons().Where(x => x.PersonalDetailsID == pd.PersonalDetailsID).FirstOrDefault();

            personInList.FirstName  = pd.FirstName;
            personInList.Address    = pd.Address;
            personInList.Age        = pd.Age;
            personInList.Occupation = pd.Occupation;

            return(RedirectToAction("PDEditor"));
        }
コード例 #13
0
 public ActionResult PersonalDetailEdit(PersonalDetail pd)
 {
     if (ModelState.IsValid)
     {
         //reference type variable
         var personInList = PersonMemory.GetPersons().Where(x => x.PersonalDetailId == pd.PersonalDetailId).FirstOrDefault();
         personInList.FirstName  = pd.FirstName;
         personInList.Occupation = pd.Occupation;
         personInList.Age        = pd.Age;
         personInList.Address    = pd.Address;
         return(RedirectToAction("Persons"));
     }
     else
     {
         return(View(pd));
     }
 }
コード例 #14
0
        public IActionResult EditPersonalDetail(PersonalDetail personDetail)
        {
            if (ModelState.IsValid)
            {
                var personInList = PersonMemory.GetPersons().Where(x => x.PersonalDetailId == personDetail.PersonalDetailId).FirstOrDefault();

                personInList.FirstName  = personDetail.FirstName;
                personInList.Occupation = personDetail.Occupation;
                personInList.Age        = personDetail.Age;
                personInList.Address    = personDetail.Address;

                return(RedirectToAction("Persons"));
            }
            else
            {
                return(View(personDetail));
            }
        }
コード例 #15
0
        public async Task <ActionResult> PersonalDetailEdit(PersonalDetail pd)
        {
            if (ModelState.IsValid)
            {
                if (Request.Form.Files["profile-image"] != null)
                {
                    //saving
                    if (Request.Form.Files["profile-image"].Length > 10 * 1024 * 1024)
                    {
                        pd.ErrorMsg = "File Size not valid !!";
                        return(View(pd));
                    }
                    string pathToFolder = Path.Combine(_env.WebRootPath, "uploadedfiles", Request.Form.Files["profile-image"].FileName);

                    var fileStream = new FileStream(pathToFolder, FileMode.Create);

                    //await Task.Run(() >{
                    await Request.Form.Files["profile-image"].CopyToAsync(fileStream);
                    //});

                    pd.ImageLocation = "uploadedfiles/" + Request.Form.Files["profile-image"].FileName;
                }
                //reference type variable
                var personInList = PersonMemory.GetPersons().Where(x => x.PersonalDetailId == pd.PersonalDetailId).FirstOrDefault();
                personInList.FirstName     = pd.FirstName;
                personInList.Occupation    = pd.Occupation;
                personInList.Age           = pd.Age;
                personInList.Address       = pd.Address;
                personInList.ImageLocation = pd.ImageLocation;
                return(RedirectToAction("Persons"));
            }
            else
            {
                return(View(pd));
            }
        }
コード例 #16
0
 public IActionResult Persons()
 {
     return(View(PersonMemory.GetPersons()));
 }