public async Task <IActionResult> CreateItem(ItemViewModel model) { if (ModelState.IsValid) { try { //get user id from access token i.e authorized user string Id = User.Claims.First(c => c.Type == "UserID").Value; //if customer created by sub-admin then customer linked to parent admin (i.e bussiness) string parentUserId = Id; var user = await _userManager.FindByIdAsync(Id); if (User.IsInRole(Constants.isSubAdmin)) { parentUserId = user.ParentUserId; } var userstatus = user.UserStatus; var items = new Items() { Name = model.Name, Description = model.Description, Quantity = model.Quantity, Price = model.Price, Tax = model.Tax, UserId = parentUserId, CreatedBy = Id, CreatedDate = DateTime.Now }; var retId = await _managementService.AddItem(items); if (retId > 0) { return(Ok(new { status = StatusCodes.Status200OK, success = true, message = "item" + ResponseMessages.msgCreationSuccess, userstatus })); } else { return(Ok(new { status = StatusCodes.Status404NotFound, success = false, message = ResponseMessages.msgDbConnectionError, userstatus = false })); } } catch (Exception ex) { return(Ok(new { status = StatusCodes.Status500InternalServerError, success = false, message = ResponseMessages.msgSomethingWentWrong + ex.Message, userstatus = false })); } } return(Ok(new { status = StatusCodes.Status406NotAcceptable, success = false, message = ResponseMessages.msgParametersNotCorrect, userstatus = false })); }