Exemple #1
0
        public ActionResult Create(UploadPhotos upload)
        {
            var data = db.Citizens.Find(upload.Photo_citizen_id);

            if (ModelState.IsValid)
            {
                string filename     = data.citizen_national_id + "_" + data.citizen_first_name + Path.GetExtension(upload.f1.FileName);
                string filePath     = Server.MapPath("~/CitizenPhotos/");
                string filePathName = Path.Combine(filePath, filename);
                upload.f1.SaveAs(filePathName);

                var old = db.Photos.Where(a => a.Photo_citizen_id == upload.Photo_citizen_id).ToList();
                if (old != null)
                {
                    foreach (var item in old)
                    {
                        item.Photo_isCurrent = false;
                        db.SaveChanges();
                    }
                }

                Photo p = new Photo();
                p.Photo_Url        = filename;
                p.Photo_citizen_id = upload.Photo_citizen_id;
                p.Photo_isCurrent  = true;
                db.Photos.Add(p);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Photo_citizen_id = new SelectList(db.Citizens, "citizen_id", "citizen_national_id", upload.Photo_citizen_id);
            return(View(upload));
        }
        public IActionResult UploadPhotos(List <IFormFile> files)
        {
            var           uploadObj = new UploadPhotos(_environment);
            List <string> filesPath = uploadObj.Upload(files);

            return(Ok(filesPath));
        }
Exemple #3
0
        public ActionResult Edit(EducationalOut educationalOut, UploadPhotos f1)
        {
            var data = db.Citizens.Find(educationalOut.CitizenId);

            if (ModelState.IsValid)
            {
                var va = db.EducationalOuts.Where(a => a.Is_Deleted != true && a.Id != educationalOut.Id);

                foreach (var item in va)
                {
                    if (item.CitizenId == educationalOut.CitizenId)
                    {
                        ViewBag.errmessage = Servicely.Languages.Language.NameAlreadyExist;
                        ViewBag.CitizenId  = new SelectList(db.Citizens.Where(a => a.citizen_isDeleted != true), "citizen_id", "citizen_national_id", educationalOut.CitizenId);
                        return(View(educationalOut));
                    }
                }

                string filename     = data.citizen_national_id + "_" + data.citizen_first_name + Path.GetExtension(f1.f1.FileName);
                string filePath     = Server.MapPath("~/EducatedOut/");
                string filePathName = Path.Combine(filePath, filename);
                f1.f1.SaveAs(filePathName);
                educationalOut.Date         = DateTime.Now;
                educationalOut.DocumentName = filename;

                var old = db.EducationalOuts.Find(educationalOut.Id);
                old.CitizenId    = educationalOut.CitizenId;
                old.DocumentName = educationalOut.DocumentName;

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CitizenId = new SelectList(db.Citizens, "citizen_id", "citizen_national_id", educationalOut.CitizenId);
            return(View(educationalOut));
        }
        public ActionResult Create(University university, UploadPhotos upload)
        {
            if (ModelState.IsValid)
            {
                var data = db.Universities.Where(a => a.Is_Deleted != true && a.UniversityName == university.UniversityName).SingleOrDefault();

                if (data != null)
                {
                    ViewBag.universtyErr = Languages.Language.universtyErr;
                    ViewBag.State        = new SelectList(db.States.Where(a => a.state_isDeleted != true), "state_id", "state_name");

                    ViewBag.UniversitryTypeId = new SelectList(db.UniversityTypes.Where(a => a.Is_Deleted != true), "Id", "UniversityTypeName");
                    if (Session["lang"] != null)
                    {
                        if (Session["lang"].ToString().Equals("ar-EG"))
                        {
                            ViewBag.UniversitryTypeId = new SelectList(db.UniversityTypes.Where(a => a.Is_Deleted != true), "Id", "UniversityTypeNameArabic");

                            ViewBag.State = new SelectList(db.States.Where(a => a.state_isDeleted != true), "state_id", "state_arabic_name");
                        }
                    }
                    return(View(university));
                }

                string filename     = university.UniversityName + Path.GetExtension(upload.f1.FileName);
                string filePath     = Server.MapPath("~/UniversityLogo/");
                string filePathName = Path.Combine(filePath, filename);
                upload.f1.SaveAs(filePathName);
                university.UniversityLogo = filename;
                db.Universities.Add(university);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UniversitryTypeId = new SelectList(db.UniversityTypes, "Id", "UniversityTypeName", university.UniversitryTypeId);
            return(View(university));
        }