Пример #1
0
        public async Task <IActionResult> Edit(IFormFile fileobj, [Bind("Clinic_ID,Clinic_Name,Clinic_Address,Clinic_Pincode,Clinic_Contact,Clinic_IsActive,Clinic_Profile,State_ID,City_ID,Doctor_ID")] DocClinic clinic, string fname, int id)
        {
            if (clinic.State_ID == 0)
            {
                ModelState.AddModelError("", "---Select State---");
            }
            else if (clinic.City_ID == 0)
            {
                ModelState.AddModelError("", "---Select City---");
            }


            // ------- Getting selected Value ------- //
            var SubCategoryID = HttpContext.Request.Form["City_ID"].ToString();


            // ------- Setting Data back to ViewBag after Posting Form ------- //
            List <State> statelist = new List <State>();

            statelist = (from state in _context.STATETB
                         select state).ToList();
            //statelist.Insert(0, new State { State_ID = 0, State_Name = "---Select State---" });
            //-------Assigning categorylist to ViewBag.ListofCategory------//
            ViewBag.ListofCategory = statelist;



            var getimg = await _context.CLINICTB.FindAsync(id);

            _context.CLINICTB.Remove(getimg);
            fname = Path.Combine("../Medical/wwwroot", "Clinic_Images", getimg.Clinic_Profile);
            FileInfo fi = new FileInfo(fname);

            if (fi.Exists)
            {
                System.IO.File.Delete(fname);
                fi.Delete();
            }
            var imgext = Path.GetExtension(fileobj.FileName);

            if (imgext == ".jpg" || imgext == ".png")
            {
                var uploadimg = Path.Combine("../Medical/wwwroot", "Clinic_Images", fileobj.FileName);
                var stream    = new FileStream(uploadimg, FileMode.Create);

                await fileobj.CopyToAsync(stream);

                stream.Close();

                var d = HttpContext.Session.GetInt32("SessionID");

                //mi.Medicine_ID = 1;
                clinic.Clinic_Profile  = fileobj.FileName;
                clinic.Clinic_IsActive = false;
                clinic.Doctor_ID       = (int)d;

                _context.Update(clinic);
                await _context.SaveChangesAsync();
            }


            ViewBag.DoctorName = TempData["SessionName"];
            TempData.Keep("SessionName");
            ViewBag.DoctorImg = TempData["SessionImg"];
            TempData.Keep("SessionImg");
            ViewBag.SID = TempData["Sessionid"];
            TempData.Keep("Sessionid");
            return(RedirectToAction("Index"));
        }
Пример #2
0
        public async Task <IActionResult> Create(IFormFile fileobj, [Bind("Clinic_ID,Clinic_Name,Clinic_Address,Clinic_Pincode,Clinic_Contact,Clinic_IsActive,Clinic_Profile,State_ID,City_ID,Doctor_ID")] DocClinic clinic)
        {
            if (clinic.State_ID == 0)
            {
                ModelState.AddModelError("", "---Select State---");
            }
            else if (clinic.City_ID == 0)
            {
                ModelState.AddModelError("", "---Select City---");
            }


            // ------- Getting selected Value ------- //
            var SubCategoryID = HttpContext.Request.Form["City_ID"].ToString();


            // ------- Setting Data back to ViewBag after Posting Form ------- //
            List <State> statelist = new List <State>();

            statelist = (from state in _context.STATETB
                         select state).ToList();
            //statelist.Insert(0, new State { State_ID = 0, State_Name = "---Select State---" });
            //-------Assigning categorylist to ViewBag.ListofCategory------//
            ViewBag.ListofCategory = statelist;
            //return View(doctorReg);

            var imgext = Path.GetExtension(fileobj.FileName);

            if (imgext == ".jpg" || imgext == ".png")
            {
                var uploadimg = Path.Combine("../Medical/wwwroot", "Clinic_Images", fileobj.FileName);
                var stream    = new FileStream(uploadimg, FileMode.Create);

                await fileobj.CopyToAsync(stream);

                stream.Close();
                var d = HttpContext.Session.GetInt32("SessionID");
                clinic.Clinic_Profile  = fileobj.FileName;
                clinic.Clinic_IsActive = false;
                clinic.Doctor_ID       = (int)d;
                await _context.CLINICTB.AddAsync(clinic);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            //if (ModelState.IsValid)
            //{
            //    _context.Add(clinic);
            //    await _context.SaveChangesAsync();
            //    return RedirectToAction(nameof(Index));
            //}


            ViewBag.DoctorName = TempData["SessionName"];
            TempData.Keep("SessionName");
            ViewBag.DoctorImg = TempData["SessionImg"];
            TempData.Keep("SessionImg");
            ViewBag.SID = TempData["Sessionid"];
            TempData.Keep("Sessionid");
            return(View(clinic));
        }