예제 #1
0
        public ActionResult Create([Bind(Include = "Id,Name,Image,Degree,Fees,SpecialistId")] Doctor doctor, HttpPostedFileBase Image)
        {
            if (ModelState.IsValid)
            {
                if (Image != null && Image.ContentLength > 0)
                {
                    try
                    {
                        string fileName  = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(Image.FileName);
                        string uploadUrl = Server.MapPath("~/Picture");
                        Image.SaveAs(Path.Combine(uploadUrl, fileName));
                        doctor.Image = "Picture/" + fileName;
                    }
                    catch (Exception ex)
                    {
                        ViewBag.Message = "ERROR:" + ex.Message.ToString();
                    }
                }
                doctor.Name         = doctor.Name;
                doctor.SpecialistId = doctor.SpecialistId;
                doctor.Degree       = doctor.Degree;
                doctor.Fees         = doctor.Fees;
                db.Doctors.Add(doctor);
                db.SaveChanges();
            }

            return(RedirectToAction("Create", new { message = "Doctor added Successfully" }));
        }
        public ActionResult Create([Bind(Include = "Id,HouseNo,Image,Information,Price")] House house, HttpPostedFileBase Image)
        {
            if (ModelState.IsValid)
            {
                if (Image != null && Image.ContentLength > 0)
                {
                    try
                    {
                        string fileName  = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(Image.FileName);
                        string uploadUrl = Server.MapPath("~/Picture");
                        Image.SaveAs(Path.Combine(uploadUrl, fileName));
                        house.Image = "Picture/" + fileName;
                    }
                    catch (Exception ex)
                    {
                        ViewBag.Message = "ERROR:" + ex.Message.ToString();
                    }
                }
                house.HouseNo     = house.HouseNo;
                house.Information = house.Information;
                house.Price       = house.Price;
                db.Houses.Add(house);
                db.SaveChanges();
            }

            return(RedirectToAction("Create", new { message = "House added Successfully" }));
        }
 public ActionResult Registration(SocietyRegistration register, HttpPostedFileBase Image)
 {
     using (var db = new SocietyContext())
     {
         if (Image != null && Image.ContentLength > 0)
         {
             try
             {
                 string fileName  = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(Image.FileName);
                 string uploadUrl = Server.MapPath("~/Picture");
                 Image.SaveAs(Path.Combine(uploadUrl, fileName));
                 register.Image = "Picture/" + fileName;
             }
             catch (Exception ex)
             {
                 ViewBag.Error = "ERROR:" + ex.Message.ToString();
             }
         }
         register.Email = register.Email;
         var e = db.SocietyRegistrations.Where(c => c.Email == register.Email).ToList().Count;
         if (e == 0)
         {
             register.Password = register.Password;
             register.Name     = register.Name;
             register.Address  = register.Address;
             register.Mobile   = register.Mobile;
             db.SocietyRegistrations.Add(register);
             db.SaveChanges();
         }
         else
         {
             ViewBag.Error = "Already Registered";
         }
     }
     ViewBag.Message = '1';
     return(View());
 }