Esempio n. 1
0
        //public async Task<IActionResult> Edit(int id, [Bind("ID,Title,Note,Video,Header,Tag,ProjectId,CreatedAt,UpdatedAt")] Education.Models.Task task)
        public async Task <IActionResult> Edit(int id, [Bind("ID,Title,Note,Video,Header,Tag,ProjectId,CreatedAt")] Education.Models.Task task)
        {
            if (id != task.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(task);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TaskExists(task.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProjectId"] = new SelectList(_context.Project, "ID", "ID", task.ProjectId);
            return(View(task));
        }
Esempio n. 2
0
        //public async Task<IActionResult> Edit(int id, [Bind("ID,Name,Content,Price,CreatedAt,UpdatedAt")] Project project)
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Content,Price,Image,CreatedAt")] ProjectCreate projectCreate)
        {
            if (id != projectCreate.ID)
            {
                return(NotFound());
            }

            Project projectModel = null;

            if (ModelState.IsValid)
            {
                try
                {
                    string uniqueFileName = UploadedFile(projectCreate);
                    string fileLocation   = HttpContext.Request.Scheme + "://" + this.Request.Host + "/images/" + uniqueFileName;

                    projectModel = new Project
                    {
                        ID      = projectCreate.ID,
                        Name    = projectCreate.Name,
                        Content = projectCreate.Content,
                        Price   = projectCreate.Price,
                        //Picture = uniqueFileName,
                        Picture = fileLocation,
                    };

                    _context.Update(projectModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProjectExists(projectModel.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(projectModel));
        }