public async Task <IActionResult> PutxCourseDesc([FromRoute] Guid id, [FromBody] XCourseDesc varxCourseDesc)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != varxCourseDesc.XCourseDescId)
            {
                return(BadRequest());
            }

            _context.Entry(varxCourseDesc).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!xCourseDescExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PostxCourseDesc([FromBody] XCourseDesc varxCourseDesc)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.XCourseDesc.Add(varxCourseDesc);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetxCourseDesc", new { id = varxCourseDesc.XCourseDescId }, varxCourseDesc));
        }
        public async Task <IActionResult> Upload()
        {
            Guid id;

            try
            {
                id = new Guid(Request.Form["rowid"]);
            }
            catch
            {
                return(NoContent());
            }
            XCourseDesc xi = _context.XCourseDesc.FirstOrDefault(x => x.XCourseDescId == id);

            if (xi != null)
            {
                if (Request.Form.Files.Count > 0)
                {
                    IFormFile file = Request.Form.Files[0];

                    if (file == null || file.Length == 0)
                    {
                        return(NoContent());
                    }


                    // try to delete old file
                    if (xi.imageUrl != null && xi.imageUrl.Length > 20)  // guid-name
                    {
                        if (System.IO.File.Exists(FilePath + xi.imageUrl))
                        {
                            try
                            {
                                System.IO.File.Delete(FilePath + xi.imageUrl);
                            }
                            catch
                            {
                            }
                        }
                    }

                    // handle file here
                    var      stream = file.OpenReadStream();
                    FileInfo fi;
                    string   realFileName;
                    fi = new FileInfo(file.FileName);
                    Guid rowid = Guid.NewGuid();
                    realFileName = rowid.ToString().Replace("{", "").Replace("}", "").Replace("-", "") + fi.Extension;
                    string targetFilePath = FilePath + realFileName;

                    using (var targetStream = System.IO.File.Create(targetFilePath))
                    {
                        await stream.CopyToAsync(targetStream);

                        stream.Close();
                        targetStream.Close();
                    }

                    xi.imageUrl = "/" + _configuration["fileStoragePath"] + "/" + realFileName;
                    await _context.SaveChangesAsync();

                    return(Ok(xi.imageUrl));
                }
            }
            return(NoContent());
        }