Example #1
0
        public ActionResult SetRatings(int id, double rate)
        {
            Mydbcontext db = new Mydbcontext();
            Ratings     r  = new Ratings();

            r.Rate       = rate;
            r.Businessid = id;
            r.Username   = Session["Username"].ToString();
            db.Ratings.Add(r);
            db.SaveChanges();
            int    i       = 0;
            double ratings = 0;
            var    bd      = from t in db.Ratings where t.Businessid == id select t;

            foreach (var t in bd)
            {
                ratings += t.Rate;
                i++;
            }
            ratings /= i;
            ratings  = Math.Truncate(ratings * 100) / 100;
            var details = new BusinessDetails()
            {
                Id      = id,
                Overall = ratings
            };

            db.BusinessDetails.Attach(details);
            db.Entry(details).Property(x => x.Overall).IsModified = true;
            db.Configuration.ValidateOnSaveEnabled = false;
            db.SaveChanges();

            return(RedirectToAction("Details", "Advertise", new { id = id }));
        }
Example #2
0
 public ActionResult AddEmployee(EmployeeModel model)
 {
     db.Employees.Add(model);
     db.SaveChanges();//will update database
     ViewBag.msg = "Employee Added:" + model.employeeid;
     return(View());
 }
 public ActionResult AddBusiness(BusinessDetails details, FormCollection mydetails, string Cat)
 {
     if (Session["Username"] != null)
     {
         string fileName  = Path.GetFileNameWithoutExtension(details.Imagefile.FileName);
         string extension = Path.GetExtension(details.Imagefile.FileName);
         fileName         += DateTime.Now.ToString("yymmssfff") + extension;
         details.Imagepath = "~/Image/" + fileName;
         fileName          = Path.Combine(Server.MapPath("~/Image/"), fileName);
         details.Imagefile.SaveAs(fileName);
         Mydbcontext     db  = new Mydbcontext();
         BusinessDetails cat = new BusinessDetails()
         {
             Businessname = Convert.ToString(mydetails["Businessname"]),
             Ownername    = Convert.ToString(mydetails["Ownername"]),
             //Category = Convert.ToString(mydetails["Category"]),
             Category    = Cat,
             Description = Convert.ToString(mydetails["Description"]),
             Address     = Convert.ToString(mydetails["Address"]),
             Mobile      = Convert.ToString(mydetails["Mobile"]),
             Imagepath   = details.Imagepath,
         };
         db.BusinessDetails.Add(cat);
         db.SaveChanges();
         ViewBag.MyCategory = from t in db.Categories select t.Categoryname;
         ModelState.Clear();
         ViewBag.Msg = "Your Business is Successfully added :)";
         return(View());
     }
     else
     {
         return(RedirectToAction("Error", "Home"));
     }
 }
Example #4
0
 public ActionResult AddLeave(EmployeeLeaves model)
 {
     db.EmployeeLeaves.Add(model);
     db.SaveChanges();
     ViewBag.msg = "Leave Added:" + model.employeeid;
     return(View());
 }
 public ActionResult DeleteCategory(string Cat)
 {
     if (Session["Username"].ToString() == "dishank")
     {
         Mydbcontext db  = new Mydbcontext();
         Categories  cat = db.Categories.FirstOrDefault(u => u.Categoryname.Equals(Cat));
         db.Categories.Remove(cat);
         db.SaveChanges();
         return(RedirectToAction("MyCategories", "Admin"));
     }
     else
     {
         return(RedirectToAction("Error", "Home"));
     }
 }
 public ActionResult Delete(string Username)
 {
     if (Session["Username"].ToString() == "dishank")
     {
         Mydbcontext db   = new Mydbcontext();
         UserDetails user = db.UserDetails.FirstOrDefault(u => u.Username.Equals(Username));
         db.UserDetails.Remove(user);
         db.SaveChanges();
         return(RedirectToAction("Users", "Admin"));
     }
     else
     {
         return(RedirectToAction("Error", "Home"));
     }
 }
 public ActionResult Edit(UserDetails details)
 {
     if (Session["Username"] != null)
     {
         string      name = Session["Username"].ToString();
         Mydbcontext db   = new Mydbcontext();
         UserDetails user = db.UserDetails.FirstOrDefault(u => u.Username.Equals(name));
         user.Firstname       = details.Firstname;
         user.Lastname        = details.Lastname;
         user.Email           = details.Email;
         user.Password        = details.Password;
         user.ConfirmPassword = details.ConfirmPassword;
         db.Entry(user).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
     return(RedirectToAction("Index", "Home"));
 }
        public ActionResult CreateCategory(Categories cat)
        {
            string fileName  = Path.GetFileNameWithoutExtension(cat.Imagefile.FileName);
            string extension = Path.GetExtension(cat.Imagefile.FileName);

            fileName        += DateTime.Now.ToString("yymmssfff") + extension;
            cat.CategoryPath = "~/Categories/" + fileName;
            fileName         = Path.Combine(Server.MapPath("~/Categories/"), fileName);
            cat.Imagefile.SaveAs(fileName);
            Mydbcontext db = new Mydbcontext();

            db.Categories.Add(cat);
            db.SaveChanges();
            ModelState.Clear();
            ViewBag.Msg = "Category is Successfully added :)";
            return(View());
        }
 public ActionResult Register(UserDetails account)
 {
     if (ModelState.IsValid)
     {
         using (Mydbcontext db = new Mydbcontext())
         {
             if (db.UserDetails.Where(u => u.Username == account.Username).FirstOrDefault() != null)
             {
                 ViewBag.error = "Username already exist";
                 return(View());
             }
             db.UserDetails.Add(account);
             db.SaveChanges();
         }
         ModelState.Clear();
         ViewBag.Message = account.Firstname + " " + account.Lastname + " successfully registered.";
     }
     return(View());
 }
Example #10
0
 public bool AddStudent(Student newStudent)
 {
     _mydbcontext.Students.Add(newStudent);
     _mydbcontext.SaveChanges();
     return(true);
 }