public async Task <Object> Register([FromForm] PublisherModel model) { var claimsIdentity = this.User.Identity as ClaimsIdentity; var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; var oldData = _publisherService.GetById(int.Parse(userId)); if (oldData != null) { try { oldData.publisherName = model.publisherName; oldData.streetAddress = model.streetAddress; oldData.city = model.city; oldData.state = model.state; oldData.postal = model.postal; oldData.country = model.country; if (_imageService.IdentityCheck(userId)) { string path = _imageService.GetIdentityPath(userId); _imageService.DeleteImage(path); _imageService.RemoveIdentityFromDB(userId); } string IdentityCardFileName = $"IDC_{userId}_{DateTime.Now.Ticks.ToString()}.png"; string subPath = "IdentityCard"; await _imageService.UploadImageAsync(model.Image, subPath, IdentityCardFileName); IdentityCard idcIMG = new IdentityCard(); idcIMG.imgName = IdentityCardFileName; idcIMG.userId = int.Parse(userId); _imageService.AddIdentityToDB(idcIMG); await _publisherService.UpdateAsync(oldData); } catch (Exception ex) { throw ex; } } else { try { Publisher newModel = new Publisher(); newModel.verify = false; newModel.verifyBy = 0; newModel.userId = int.Parse(userId); newModel.publisherName = model.publisherName; newModel.streetAddress = model.streetAddress; newModel.city = model.city; newModel.state = model.state; newModel.postal = model.postal; newModel.country = model.country; string IdentityCardFileName = $"IDC_{userId}_{DateTime.Now.Ticks.ToString()}.png"; string subPath = "IdentityCard"; await _imageService.UploadImageAsync(model.Image, subPath, IdentityCardFileName); IdentityCard idcIMG = new IdentityCard(); idcIMG.imgName = IdentityCardFileName; idcIMG.userId = int.Parse(userId); _imageService.AddIdentityToDB(idcIMG); await _publisherService.AddToDb(newModel); } catch (Exception ex) { throw ex; } } return(Ok()); }