public ActionResult Create([Bind(Include = "Id,UserName,Company,Contact,Password,ConfirmPassword")] Register register)
        {
            if (ModelState.IsValid)
            {
                db.Registers.Add(register);
                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }

            return(View(register));
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "Id,Searchname")] Search search)
        {
            if (ModelState.IsValid)
            {
                db.Searches.Add(search);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(search));
        }
Exemplo n.º 3
0
 public ActionResult Delete(int?id) //It will take the id as input and remove the product
 {
     using (UserEntities1 db = new UserEntities1())
     {
         Product p = db.Products.Find(id);
         db.Products.Remove(p);
         string currentImage  = Request.MapPath(p.SmallImage);
         string currentImage1 = Request.MapPath(p.LargeImage);
         Session["Delete"] = "Deleted";
         db.SaveChanges();
         //It will Remove the image from folder
         if (System.IO.File.Exists(currentImage))
         {
             System.IO.File.Delete(currentImage);
         }
         if (System.IO.File.Exists(currentImage1))
         {
             System.IO.File.Delete(currentImage1);
         }
         HttpCookie cookie = new HttpCookie("CookieDelete");
         cookie.Value = "Delete";
         Response.Cookies.Add(cookie);
         cookie.Expires = DateTime.Now.AddSeconds(10);
         return(RedirectToAction("Display"));
     }
 }
Exemplo n.º 4
0
        public ActionResult Add(Product p)//Add Product(Post Method)
        {
            if (p != null)
            {
                if (p.ImageFile1 != null)//Optional Image
                {
                    String filename1  = Path.GetFileNameWithoutExtension(p.ImageFile1.FileName);
                    String extension1 = Path.GetExtension(p.ImageFile1.FileName);
                    filename1    = filename1 + DateTime.Now.ToString("yymmssfff") + extension1;
                    p.LargeImage = "~/Images/Large/" + filename1;
                    filename1    = Path.Combine(Server.MapPath("~/Images/Large/"), filename1);
                    p.ImageFile1.SaveAs(filename1);
                }
                else
                {
                    p.LargeImage = "NA";
                }
                String filename  = Path.GetFileNameWithoutExtension(p.ImageFile.FileName);
                String extension = Path.GetExtension(p.ImageFile.FileName);
                filename     = filename + DateTime.Now.ToString("yymmssfff") + extension;
                p.SmallImage = "~/Images/Small/" + filename;
                filename     = Path.Combine(Server.MapPath("~/Images/Small/"), filename);
                p.ImageFile.SaveAs(filename);
                if (p.LongDescription == null)//Optional Description
                {
                    p.LongDescription = "NA";
                }
                using (UserEntities1 db = new UserEntities1())
                {
                    db.Products.Add(p);//Add all the details
                    db.SaveChanges();
                }

                ModelState.Clear();
                //Toster Message For Add Prouct
                HttpCookie cookie = new HttpCookie("CookieAdd");
                cookie.Value = "Add";
                Response.Cookies.Add(cookie);
                cookie.Expires = DateTime.Now.AddSeconds(10);
                return(RedirectToAction("Add", "Myproduct"));
            }
            else
            {
                return(View());
            }
        }
Exemplo n.º 5
0
        public ActionResult Climber_In([Bind(Include = "userID,timeStamp,stampRecord")] userLog userLog)
        {
            if (db.userdatas.Where(x => x.userID == userLog.userID).Any())
            {
                //creats a time stamp for the user when they sign in
                DateTime localDate = DateTime.Now;
                //converts time stamp to string to store in database
                string TimeStamp = localDate.ToString("MM/dd/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture);
                userLog.timeStamp = TimeStamp;


                int convert;
                var Temp_Record = db1.userLogs.Max(x => x.stampRecord);

                if (Temp_Record == null)
                {
                    Temp_Record         = "1";
                    userLog.stampRecord = Temp_Record;
                }
                else
                {
                    //convert int to string
                    convert = Int32.Parse(Temp_Record);
                    convert = convert + 1;
                    var NewStamp = convert.ToString();
                    userLog.stampRecord = NewStamp;
                }

                if (ModelState.IsValid)
                {
                    db1.userLogs.Add(userLog);
                    db1.SaveChanges();
                    Response.Write(@"<script language='javascript'>alert('Message: \n" + "Welcome!" + "');</script>");
                }

                return(View(userLog));
            }
            else
            {
                Response.Write(@"<script language='javascript'>alert('Message: \n" + "Your ID was Incorrect, Please Try again" + "');</script>");
                return(View());
            }
        }
Exemplo n.º 6
0
 public ActionResult Deleteall(string[] id)//Multiple Delete
 {
     int[] getid = null;
     if (id != null)
     {
         getid = new int[id.Length];
         int j = 0;
         foreach (string i in id)
         {
             int.TryParse(i, out getid[j++]);//Fetch all id
         }
         List <Product> pids = new List <Product>();
         UserEntities1  db   = new UserEntities1();
         pids = db.Products.Where(x => getid.Contains(x.ProductId)).ToList();
         foreach (var s in pids)
         {
             db.Products.Remove(s);//Remove product one by one using product id
         }
         db.SaveChanges();
         return(RedirectToAction("Display"));
     }
     return(RedirectToAction("Display"));
 }
Exemplo n.º 7
0
 public ActionResult Edit(int id, Product p)//Edit Product(Post Method)
 {
     try
     {
         string oldpath1 = Session["imgpath1"].ToString();
         string oldpath2 = Session["imgpath2"].ToString();
         //If conditions for optional image as well as compulsory image.
         if (p.SmallImage != null && p.LargeImage != null)
         {
             String filename  = Path.GetFileNameWithoutExtension(p.ImageFile.FileName);
             String extension = Path.GetExtension(p.ImageFile.FileName);
             filename     = filename + DateTime.Now.ToString("yymmssfff") + extension;
             p.SmallImage = "~/Images/Small/" + filename;
             filename     = Path.Combine(Server.MapPath("~/Images/Small/"), filename);
             p.ImageFile.SaveAs(filename);
             if (p.SmallImage != oldpath1)
             {
                 string p1 = Request.MapPath(oldpath1);
                 if (System.IO.File.Exists(p1))
                 {
                     System.IO.File.Delete(p1);
                 }
             }
             String filename1  = Path.GetFileNameWithoutExtension(p.ImageFile1.FileName);
             String extension1 = Path.GetExtension(p.ImageFile1.FileName);
             filename1    = filename1 + DateTime.Now.ToString("yymmssfff") + extension1;
             p.LargeImage = "~/Images/Large/" + filename1;
             filename1    = Path.Combine(Server.MapPath("~/Images/Large/"), filename1);
             p.ImageFile1.SaveAs(filename1);
             if (p.LargeImage != oldpath2)
             {
                 string p2 = Request.MapPath(oldpath2);
                 if (System.IO.File.Exists(p2))
                 {
                     System.IO.File.Delete(p2);
                 }
             }
         }
         if (p.ImageFile != null)
         {
             String filename  = Path.GetFileNameWithoutExtension(p.ImageFile.FileName);
             String extension = Path.GetExtension(p.ImageFile.FileName);
             filename     = filename + DateTime.Now.ToString("yymmssfff") + extension;
             p.SmallImage = "~/Images/Small/" + filename;
             filename     = Path.Combine(Server.MapPath("~/Images/Small/"), filename);
             p.ImageFile.SaveAs(filename);
             if (p.LargeImage == null)
             {
                 p.LargeImage = oldpath2;
             }
             if (p.SmallImage != oldpath1)
             {
                 string p1 = Request.MapPath(oldpath1);
                 if (System.IO.File.Exists(p1))
                 {
                     System.IO.File.Delete(p1);
                 }
             }
         }
         if (p.ImageFile1 != null)
         {
             String filename1  = Path.GetFileNameWithoutExtension(p.ImageFile1.FileName);
             String extension1 = Path.GetExtension(p.ImageFile1.FileName);
             filename1    = filename1 + DateTime.Now.ToString("yymmssfff") + extension1;
             p.LargeImage = "~/Images/Large/" + filename1;
             filename1    = Path.Combine(Server.MapPath("~/Images/Large/"), filename1);
             p.ImageFile1.SaveAs(filename1);
             if (p.SmallImage == null)
             {
                 p.SmallImage = oldpath1;
             }
             if (p.LargeImage != oldpath2)
             {
                 string p2 = Request.MapPath(oldpath2);
                 if (System.IO.File.Exists(p2))
                 {
                     System.IO.File.Delete(p2);
                 }
             }
         }
         if (p.SmallImage == null && p.LargeImage == null)
         {
             p.SmallImage = oldpath1;
             p.LargeImage = oldpath2;
         }
         if (p.LongDescription == null)
         {
             p.LongDescription = "NA";
         }
         UserEntities1 db = new UserEntities1();
         db.Entry(p).State = EntityState.Modified;//Modify The Data
         db.SaveChanges();
         //Toster Message For Edit Product.
         HttpCookie cookie2 = new HttpCookie("CookieEdit");
         cookie2.Value = "Edit";
         Response.Cookies.Add(cookie2);
         cookie2.Expires = DateTime.Now.AddSeconds(5);
         return(RedirectToAction("Display"));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
     return(View());
 }