public ActionResult <UserRole> Create(UserRole userRole) { try { var newUserRole = _userRoleServices.CreateUserRole(userRole); if ((bool)HttpContext.Items["isLoggedInOtherDevice"]) { return(Ok(new ResponseContext { code = (int)Common.ResponseCode.IS_LOGGED_IN_ORTHER_DEVICE, message = Common.Message.IS_LOGGED_IN_ORTHER_DEVICE, data = null })); } return(Ok(new ResponseContext { code = (int)Common.ResponseCode.SUCCESS, message = Common.Message.SUCCESS, data = newUserRole })); } catch (System.Exception ex) { _logger.LogError(ex, ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError, new ResponseMessage { status = "ERROR", message = ex.Message })); } }
public ActionResult _Add(UserRoleEditModel model) { switch (model.RoleId) { case 4: // Industry Director case 12: model.RegionId = null; model.CountryId = null; break; case 5: // Region Director case 13: model.IndustryId = null; model.CountryId = null; break; case 6: // Country Director case 14: model.IndustryId = null; model.RegionId = null; break; default: model.IndustryId = null; model.RegionId = null; model.CountryId = null; break; } if (!ModelState.IsValid) { return(Json(new { success = false, message = ModelState.GetErrors() })); } var userRole = Mapper.Map <UserRoleEditModel, UserRoleEntity>(model); var userId = model.UserEmail.Split('|')[0]; var userEmail = model.UserEmail.Split('|')[1]; userRole.UserId = Convert.ToInt32(userId); userRole.UserEmail = userEmail; var added = UserRoleServices.CreateUserRole(userRole); switch (added) { case -1: return(Json(new { success = false, title = "Error!", message = "User role could not added!" })); case 0: return(Json(new { success = false, title = "Already exists!", message = "User role could not added. It already exists." })); default: // 1: return(Json(new { success = true, message = "User role added!" })); } }