Example #1
0
        public ActionResult EditProfile(int id, TblCoach model, string city, HttpPostedFileBase postedFile)
        {
            List <TblCountry> countries = db.Country_tbl.ToList();

            ViewBag.CountryList = new SelectList(countries, "CountryId", "Country");
            if (postedFile != null)
            {
                using (BinaryReader br = new BinaryReader(postedFile.InputStream))
                {
                    bytes = br.ReadBytes(postedFile.ContentLength);
                }
            }
            var EditCoachList = db.Coach_tbl.Where(x => x.CoachId == id && x.Status == 1).FirstOrDefault();

            if (EditCoachList != null)
            {
                EditCoachList.Coach  = model.Coach;
                EditCoachList.DOB    = model.DOB;
                EditCoachList.Length = model.Length;
                EditCoachList.Weight = model.Weight;
                EditCoachList.Mobile = model.Mobile;
                if (bytes != null)
                {
                    EditCoachList.Photo = bytes;
                }
                db.SaveChanges();
            }
            //db.Entry(model).State = System.Data.Entity.EntityState.Modified;
            //db.SaveChanges();

            return(Content("<script>alert('Updated Successfully');location.href='CoachView';</script>"));
        }
Example #2
0
        public ActionResult CoachRegistration(TblCoach model, string city, HttpPostedFileBase postedFile)
        {
            var userid = Session["UserId"].ToString();

            List <TblCountry> countries = db.Country_tbl.ToList();

            ViewBag.CountryList = new SelectList(countries, "CountryId", "Country");

            List <TblUser> user = db.User_tbl.ToList();

            ViewBag.UserList = new SelectList(user, "UserId", "UserId");

            if (ModelState.IsValid)
            {
                byte[] bytes;
                using (BinaryReader br = new BinaryReader(postedFile.InputStream))
                {
                    bytes = br.ReadBytes(postedFile.ContentLength);
                }
                //TblPlayer tblPlayer = new TblPlayer();



                db.Coach_tbl.Add(new TblCoach
                {
                    CoachReferenceNumber = "1",
                    //PlayerId = model.PlayerId,
                    Coach  = model.Coach,
                    DOB    = model.DOB,
                    CityId = Convert.ToInt32(city),
                    Length = model.Length,
                    Weight = model.Weight,


                    //if(file!=null)
                    //{
                    //  string path = Path.Combine(Server.MapPath("~/UserImages"), Path.GetFileName(file.FileName));
                    //file.SaveAs(path);
                    //}


                    Photo     = bytes,
                    Confirmed = 1,

                    RegistrationDate = DateTime.Now,
                    ExpirationDate   = DateTime.Now,

                    SponsorId    = 1,
                    Mobile       = model.Mobile,
                    UserId       = Convert.ToInt32(userid),
                    Status       = 1,
                    CreatedId    = 1,
                    CreatedDate  = DateTime.Now,
                    ModifiedId   = 0,
                    ModifiedDate = DateTime.Now
                });


                db.SaveChanges();



                return(RedirectToAction("Coach"));
            }
            return(View());
        }