Exemple #1
0
        public async Task <ActionResult> Create(HomePageSetUp homePageSetUp)
        {
            if (ModelState.IsValid)
            {
                string _FileName = String.Empty;
                try
                {
                    if (homePageSetUp.File?.ContentLength > 0)
                    {
                        _FileName = Path.GetFileName(homePageSetUp.File.FileName);
                        string _path     = HostingEnvironment.MapPath("~/Content/Images/") + _FileName;
                        var    directory = new DirectoryInfo(HostingEnvironment.MapPath("~/Content/Images/"));
                        if (directory.Exists == false)
                        {
                            directory.Create();
                        }
                        homePageSetUp.File.SaveAs(_path);
                    }
                }
                catch
                {
                    ViewBag.Message  = "File upload failed!!";
                    ViewBag.CourseId = new SelectList(Db.HomePageSetUps, "CourseId", "CourseCode");
                    return(View(homePageSetUp));
                }
                homePageSetUp.FileLocation = _FileName;
                Db.HomePageSetUps.Add(homePageSetUp);
                await Db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(homePageSetUp));
        }
Exemple #2
0
        public async Task <ActionResult> DeleteConfirmed(string id)
        {
            HomePageSetUp homePageSetUp = await Db.HomePageSetUps.FindAsync(id);

            Db.HomePageSetUps.Remove(homePageSetUp);
            await Db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemple #3
0
        public async Task <ActionResult> Edit([Bind(Include = "HomePagesetUpId,Title,DescriptiveText,FileLocation")] HomePageSetUp homePageSetUp)
        {
            if (ModelState.IsValid)
            {
                Db.Entry(homePageSetUp).State = EntityState.Modified;
                await Db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(homePageSetUp));
        }
Exemple #4
0
        // GET: HomePageSetUps/Edit/5
        public async Task <ActionResult> Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HomePageSetUp homePageSetUp = await Db.HomePageSetUps.FindAsync(id);

            if (homePageSetUp == null)
            {
                return(HttpNotFound());
            }
            return(View(homePageSetUp));
        }