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

            if (id != varXInstructorInfo.XInstructorInfoId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PostXInstructorInfo([FromBody] XInstructorInfo varXInstructorInfo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.XInstructorInfo.Add(varXInstructorInfo);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetXInstructorInfo", new { id = varXInstructorInfo.XInstructorInfoId }, varXInstructorInfo));
        }
        public async Task <IActionResult> Upload()
        {
            Guid id;

            try
            {
                id = new Guid(Request.Form["rowid"]);
            }
            catch
            {
                return(NoContent());
            }
            XInstructorInfo xi = _context.XInstructorInfo.FirstOrDefault(x => x.XInstructorInfoId == 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.photoUrl != null && xi.photoUrl.Length > 20)   // guid-name
                    {
                        if (System.IO.File.Exists(FilePath + xi.photoUrl))
                        {
                            try
                            {
                                System.IO.File.Delete(FilePath + xi.photoUrl);
                            }
                            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.photoUrl = "/" + _configuration["fileStoragePath"] + "/" + realFileName;
                    await _context.SaveChangesAsync();

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