public async Task <IActionResult> PutXUserInfo([FromRoute] Guid id, [FromBody] XUserInfo varXUserInfo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != varXUserInfo.XUserInfoId) { return(BadRequest()); } _context.Entry(varXUserInfo).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!XUserInfoExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
/// <summary> /// Initializes a new instance of the <see cref="GetUserProfileResponse"/> class. /// </summary> /// <param name="user">The user<see cref="XUserInfo"/></param> public GetUserProfileResponse(XUserInfo user) { Id = user.XUserInfoId; FirstName = user.name; MiddleName = user.middleName; LastName = user.family; Phone = user.phone; LoginId = new Guid(user.login); }
public async Task <IActionResult> PostXUserInfo([FromBody] XUserInfo varXUserInfo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.XUserInfo.Add(varXUserInfo); await _context.SaveChangesAsync(); return(CreatedAtAction("GetXUserInfo", new { id = varXUserInfo.XUserInfoId }, varXUserInfo)); }
public async Task <IActionResult> Upload() { Guid id; try { id = new Guid(Request.Form["rowid"]); } catch { return(NoContent()); } XUserInfo xi = _context.XUserInfo.FirstOrDefault(x => x.XUserInfoId == 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()); }