Пример #1
0
        // GET: Admin/Saugats/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Saugat saugat = db.Saugats.Find(id);
            //Below Lines added for Community
            var userid  = User.Identity.GetUserId();
            var saugata = from item in db.Saugats where (item.SaugatId == id) select item;

            saugata = saugata.Include(a => a.CreatedBy);
            saugata = saugata.Where(a => a.CreatedBy == userid);
            if (saugata.Count() == 0)
            {
                saugat = null;
            }



            if (saugat == null)
            {
                return(HttpNotFound());
            }
            return(View(saugat));
        }
Пример #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            Saugat saugat = db.Saugats.Find(id);

            db.Saugats.Remove(saugat);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #3
0
        public ActionResult Create([Bind(Include = "SaugatId,Title,Description,LinkUrl,ImageUrl,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,DelFlg")] Saugat saugat, HttpPostedFileBase ImageUrl, HttpPostedFileBase LinkUrl)

        {
            if (ModelState.IsValid)
            {
                db.Entry(saugat).State = EntityState.Added;
                saugat.CreatedBy       = User.Identity.GetUserId();
                saugat.CreatedDate     = DateTime.Now;

                if (ImageUrl != null)
                {
                    string pathToCreate = "~/Images/saugat";
                    if (!Directory.Exists(Server.MapPath(pathToCreate)))
                    {
                        //Now you know it is ok, create it
                        Directory.CreateDirectory(Server.MapPath(pathToCreate));
                    }
                    string extension = Path.GetExtension(ImageUrl.FileName);
                    string fileName  = Path.GetFileNameWithoutExtension(ImageUrl.FileName);
                    string id        = Guid.NewGuid().ToString();
                    string imageUrl  = "/Images/saugat/" + fileName + "" + /*main.MainId.ToString()*/ id + extension;

                    ImageUrl.SaveAs(Path.Combine(Server.MapPath(pathToCreate), fileName + "" + /*main.MainId.ToString()*/ id + extension));
                    string DestinationPath = Path.Combine(Server.MapPath(pathToCreate));
                    DestinationPath += "\\" + fileName + id;
                    ImageResizer.ImageJob i = new ImageResizer.ImageJob(DestinationPath + extension, DestinationPath + "_thumb.jpg", new ImageResizer.ResizeSettings(
                                                                            "width=200;height=200;format=jpg;mode=max"));
                    i.Build();

                    saugat.ImageUrl = imageUrl;

                    db.Saugats.Add(saugat);
                }


                if (LinkUrl != null)
                {
                    string pathToCreate = "~/Documents/Saugat";
                    if (!Directory.Exists(Server.MapPath(pathToCreate)))
                    {
                        //Now you know it is ok, create it
                        Directory.CreateDirectory(Server.MapPath(pathToCreate));
                    }
                    string extension     = Path.GetExtension(LinkUrl.FileName);
                    string fileName      = Path.GetFileNameWithoutExtension(LinkUrl.FileName);
                    string id            = Guid.NewGuid().ToString();
                    string LinkUrlToSave = "/Documents/Saugat/" + fileName + "" + /*main.MainId.ToString()*/ id + extension;
                    LinkUrl.SaveAs(Path.Combine(Server.MapPath(pathToCreate), fileName + "" + /*main.MainId.ToString()*/ id + extension));
                    saugat.LinkUrl = LinkUrlToSave;
                }

                db.Saugats.Add(saugat);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(saugat));
        }
Пример #4
0
        public ActionResult Create([Bind(Include = "SaugatId,Title,Description,LinkUrl,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,DelFlg")] Saugat saugat, HttpPostedFileBase LinkUrl)

        {
            if (ModelState.IsValid)
            {
                db.Entry(saugat).State = EntityState.Added;
                saugat.CreatedBy       = User.Identity.GetUserId();
                saugat.CreatedDate     = DateTime.Now;
                if (LinkUrl != null && LinkUrl.ContentLength > 0)
                {
                    string pathToCreate = "~/UploadedDocuments/Saugat";
                    if (!Directory.Exists(Server.MapPath(pathToCreate)))
                    {
                        //Now you know it is ok, create it
                        Directory.CreateDirectory(Server.MapPath(pathToCreate));
                    }
                    string extension = Path.GetExtension(LinkUrl.FileName);
                    string fileName  = Path.GetFileNameWithoutExtension(LinkUrl.FileName);
                    string id        = Guid.NewGuid().ToString();
                    string linkurl   = "/UploadedDocuments/Saugat/" + fileName + "" + /*main.MainId.ToString()*/ id + extension;
                    LinkUrl.SaveAs(Path.Combine(Server.MapPath(pathToCreate), fileName + "" + /*main.MainId.ToString()*/ id + extension));
                    // extract only the filename
                    string DestinationPath = Path.Combine(Server.MapPath(pathToCreate));
                    DestinationPath += "\\" + fileName + id;
                    // store the file inside ~/App_Data/uploads folder
                    saugat.LinkUrl = linkurl;

                    db.Saugats.Add(saugat);
                }
                db.Saugats.Add(saugat);

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(saugat));
        }